bufmgr: Return early in ScheduleBufferTagForWriteback() if fsync=off
authorAndres Freund <[email protected]>
Tue, 8 Oct 2024 15:37:45 +0000 (11:37 -0400)
committerAndres Freund <[email protected]>
Tue, 8 Oct 2024 15:37:45 +0000 (11:37 -0400)
As pg_flush_data() doesn't do anything with fsync disabled, there's no point
in tracking the buffer for writeback. Arguably the better fix would be to
change pg_flush_data() to flush data even with fsync off, but that's a
behavioral change, whereas this is just a small optimization.

Reviewed-by: Heikki Linnakangas <[email protected]>
Reviewed-by: Noah Misch <[email protected]>
Discussion: https://postgr.es/m/1f6b50a7-38ef-4d87-8246-786d39f46ab9@iki.fi

src/backend/storage/buffer/bufmgr.c

index 485204430017eb3c3a4e0ea1333fe449e1a489f4..b8680cc8fd4686cf01c6bad0c4f7c28bb45e1754 100644 (file)
@@ -5899,7 +5899,12 @@ ScheduleBufferTagForWriteback(WritebackContext *wb_context, IOContext io_context
 {
        PendingWriteback *pending;
 
-       if (io_direct_flags & IO_DIRECT_DATA)
+       /*
+        * As pg_flush_data() doesn't do anything with fsync disabled, there's no
+        * point in tracking in that case.
+        */
+       if (io_direct_flags & IO_DIRECT_DATA ||
+               !enableFsync)
                return;
 
        /*