Skip to content

Commit 098b790

Browse files
laramielcopybara-github
authored andcommitted
ocdbt only align large writes (>4mb) to block boundaries.
PiperOrigin-RevId: 788635730 Change-Id: If094edd295a40596572554821b1c0ad796bb10d0
1 parent 7907fa6 commit 098b790

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tensorstore/kvstore/ocdbt/io/indirect_data_writer.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ auto& indirect_data_writer_histogram =
5151

5252
ABSL_CONST_INIT internal_log::VerboseFlag ocdbt_logging("ocdbt");
5353

54+
// Direct IO is only useful on larger files.
55+
// These are the values where block padding will be applied.
56+
constexpr size_t kMinPaddingSize = 1024 * 1024 * 4;
57+
constexpr size_t kDefaultPaddingAlignment = 4096;
58+
5459
} // namespace
5560

5661
class IndirectDataWriter
@@ -123,8 +128,9 @@ void MaybeFlush(IndirectDataWriter& self, UniqueWriterLock<absl::Mutex> lock) {
123128
DataFileId data_file_id = self.data_file_id_;
124129
lock.unlock();
125130

126-
// zero-pad up to the block boundary to allow for potential direct io reads.
127-
if (self.write_alignment_ > 1 &&
131+
// zero-pad up to the block boundary to allow for potential direct io reads
132+
// on larger files.
133+
if (self.write_alignment_ > 1 && buffer.size() > kMinPaddingSize &&
128134
(buffer.size() % self.write_alignment_) > 0) {
129135
size_t pad_size =
130136
self.write_alignment_ - (buffer.size() % self.write_alignment_);
@@ -211,7 +217,7 @@ IndirectDataWriterPtr MakeIndirectDataWriter(kvstore::KvStore kvstore,
211217
// Align output up to 4k to allow for potential direct io reads.
212218
return internal::MakeIntrusivePtr<IndirectDataWriter>(
213219
std::move(kvstore), std::move(prefix), target_size,
214-
/*write_alignment=*/4096);
220+
/*write_alignment=*/kDefaultPaddingAlignment);
215221
}
216222

217223
} // namespace internal_ocdbt

0 commit comments

Comments
 (0)