Fix redundant direct I/O tail rewrite in WritableFileWriter - #15083
Open
taimoor789 wants to merge 1 commit into
Open
Fix redundant direct I/O tail rewrite in WritableFileWriter#15083taimoor789 wants to merge 1 commit into
taimoor789 wants to merge 1 commit into
Conversation
Under O_DIRECT, WriteDirect() pads an unaligned tail with zeros, writes it, and parks the tail bytes in buf_ for a future Append() to glue onto. It never marked that tail as already written, so a later Flush(), Sync(), or Close() with no intervening Append() would re-issue the same write. Track when buf_ holds only such a clean tail and skip the redundant write. Fixes facebook#12168.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Under O_DIRECT,
WriteDirect()/WriteDirectWithChecksum()pad an unaligned tail with zeros, write it, and park the tail bytes at the front ofbuf_viaRefitTail()so a futureAppend()can glue more data onto them before the next write. Neither function marked that parked tail as already written, so a laterFlush(),Sync(), orClose()call with no interveningAppend()would re-issue aPositionedAppend()for the same already-written bytes -- not a correctness issue, since the same bytes just get rewritten at the same offset, but wasted I/O.This adds a
direct_io_buf_is_clean_tail_flag: set afterRefitTail()when the buffer holds only an already-written tail, cleared the momentAppend()adds new data.Flush()'s direct-I/O path now also checks this flag and skips the redundant write.Fixes #12168, following the fix direction @ajkr suggested on the issue: track whether the buffer is dirty or clean and skip the write when it's clean.
Test Plan
Added
WritableFileWriterTest.DirectIOSkipsRedundantTailRewrite(util/file_reader_writer_test.cc), which countsPositionedAppend()calls acrossFlush()/Sync()/Close()sequences with no interveningAppend()and asserts no redundant write occurs, plus that appending more data still glues onto the tail correctly and final file content is byte-correct. Fails on unfixed code, passes with the fix. Fullfile_reader_writer_testsuite (114 tests) andmake checkpass;make check-sourcesclean.