]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
loop: only write back pagecache when starting to to use direct I/O
authorChristoph Hellwig <hch@lst.de>
Fri, 10 Jan 2025 07:37:34 +0000 (08:37 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 10 Jan 2025 14:31:50 +0000 (07:31 -0700)
There is no point in doing an fdatasync to write out pages when switching
away from direct I/O, as there won't be any.  The writeback is only
needed when switching to direct I/O, which would have to invalidate the
pagecache less efficiently from the I/O path.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250110073750.1582447-5-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/loop.c

index 55bea9c95b4596a3ea65a78a2c68d8aed8d280b7..cf80cdf5e440afe26cbd666ca45a1fc0c1798bdd 100644 (file)
@@ -203,8 +203,9 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
        if (lo->use_dio == use_dio)
                return;
 
-       /* flush dirty pages before changing direct IO */
-       vfs_fsync(lo->lo_backing_file, 0);
+       /* flush dirty pages before starting to use direct I/O */
+       if (use_dio)
+               vfs_fsync(lo->lo_backing_file, 0);
 
        /*
         * The flag of LO_FLAGS_DIRECT_IO is handled similarly with