@@ -51,6 +51,11 @@ auto& indirect_data_writer_histogram =
51
51
52
52
ABSL_CONST_INIT internal_log::VerboseFlag ocdbt_logging (" ocdbt" );
53
53
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
+
54
59
} // namespace
55
60
56
61
class IndirectDataWriter
@@ -123,8 +128,9 @@ void MaybeFlush(IndirectDataWriter& self, UniqueWriterLock<absl::Mutex> lock) {
123
128
DataFileId data_file_id = self.data_file_id_ ;
124
129
lock.unlock ();
125
130
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 &&
128
134
(buffer.size () % self.write_alignment_ ) > 0 ) {
129
135
size_t pad_size =
130
136
self.write_alignment_ - (buffer.size () % self.write_alignment_ );
@@ -211,7 +217,7 @@ IndirectDataWriterPtr MakeIndirectDataWriter(kvstore::KvStore kvstore,
211
217
// Align output up to 4k to allow for potential direct io reads.
212
218
return internal::MakeIntrusivePtr<IndirectDataWriter>(
213
219
std::move (kvstore), std::move (prefix), target_size,
214
- /* write_alignment=*/ 4096 );
220
+ /* write_alignment=*/ kDefaultPaddingAlignment );
215
221
}
216
222
217
223
} // namespace internal_ocdbt
0 commit comments