The patch titled direct-io-sync-and-invalidate-file-region-when-falling-back-to-buffered-write fix has been added to the -mm tree. Its filename is direct-io-sync-and-invalidate-file-region-when-falling-back-to-buffered-write-fix.patch See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: direct-io-sync-and-invalidate-file-region-when-falling-back-to-buffered-write fix From: Jeff Moyer <jmoyer@xxxxxxxxxx> akpm> /* akpm> * We need to ensure that the page cache pages are written to akpm> * disk and invalidated to preserve the expected O_DIRECT akpm> * semantics. akpm> */ akpm> endbyte = pos + written_buffered - 1; We probably want to handle the case where generic_file_buffered_write returns an error or nothing written. akpm> err = do_sync_file_range(file, pos, endbyte, akpm> SYNC_FILE_RANGE_WAIT_BEFORE| akpm> SYNC_FILE_RANGE_WRITE| akpm> SYNC_FILE_RANGE_WAIT_AFTER); akpm> if (err == 0) { akpm> written += written_buffered; akpm> invalidate_mapping_pages(mapping, akpm> pos >> PAGE_CACHE_SHIFT, akpm> endbyte >> PAGE_CACHE_SHIFT); generic_file_buffered_write takes written as an argument, and returns that amount plus whatever it managed to write. As such, you don't want to add written_buffered to written. Instead, you want written = written_buffered. The endbyte calculation has to be altered in kind. Incremental, locally tested patch attached. Comments are welcome as always. Once there is consensus, I'll send this off for testing with Oracle again. Cc: Jeff Moyer <jmoyer@xxxxxxxxxx> Cc: Zach Brown <zach.brown@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxx> --- mm/filemap.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff -puN mm/filemap.c~direct-io-sync-and-invalidate-file-region-when-falling-back-to-buffered-write-fix mm/filemap.c --- a/mm/filemap.c~direct-io-sync-and-invalidate-file-region-when-falling-back-to-buffered-write-fix +++ a/mm/filemap.c @@ -2291,19 +2291,21 @@ __generic_file_aio_write_nolock(struct k written_buffered = generic_file_buffered_write(iocb, iov, nr_segs, pos, ppos, count, written); + if (written_buffered < 0 || written_buffered == written) + goto out; /* * We need to ensure that the page cache pages are written to * disk and invalidated to preserve the expected O_DIRECT * semantics. */ - endbyte = pos + written_buffered - 1; + endbyte = pos + written_buffered - written - 1; err = do_sync_file_range(file, pos, endbyte, SYNC_FILE_RANGE_WAIT_BEFORE| SYNC_FILE_RANGE_WRITE| SYNC_FILE_RANGE_WAIT_AFTER); if (err == 0) { - written += written_buffered; + written = written_buffered; invalidate_mapping_pages(mapping, pos >> PAGE_CACHE_SHIFT, endbyte >> PAGE_CACHE_SHIFT); _ Patches currently in -mm which might be from jmoyer@xxxxxxxxxx are direct-io-sync-and-invalidate-file-region-when-falling-back-to-buffered-write.patch direct-io-sync-and-invalidate-file-region-when-falling-back-to-buffered-write-fix.patch dio-centralize-completion-in-dio_complete.patch dio-call-blk_run_address_space-once-per-op.patch dio-formalize-bio-counters-as-a-dio-reference-count.patch dio-remove-duplicate-bio-wait-code.patch dio-only-call-aio_complete-after-returning-eiocbqueued.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html