[PATCH 2/3] gfs2: plug the log writes of a flush

From: Tal Zussman

Date: Tue Nov 17 2026 - 02:46:45 EST


__gfs2_log_flush() submits the log blocks of a transaction as several
bios. lops_before_commit() starts a new bio whenever the next block is
not contiguous with the last one or has a different completion handler,
so each descriptor block is a bio of its own. Most of these bios are
contiguous on disk, but the flush does not plug, so without an I/O
scheduler each of them reaches the device as a separate write.

Plug around lops_before_commit() and the submission of the last bio, so
that the block layer can merge the contiguous bios into fewer requests.
The log header is still written after the plug is finished.

With fio 4K write+fsync and no I/O scheduler, this takes the write
requests for 32k fsyncs from 229.5k back to 196.7k, and the p99.9 fsync
latency on null_blk from 51 us back to 41 us.

Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/gfs2/log.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 238f6655e15f..9b05db20921a 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -1088,6 +1088,7 @@ static void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
bool frozen = test_bit(SDF_FROZEN, &sdp->sd_flags);
unsigned int first_log_head;
unsigned int reserved_revokes = 0;
+ struct blk_plug plug;

trace_gfs2_log_flush(sdp, 1, flags);

@@ -1148,11 +1149,13 @@ static void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
gfs2_ordered_write(sdp);
if (gfs2_withdrawn(sdp))
goto out_withdraw;
+
+ /* Plug so that the contiguous log bios merge into fewer requests. */
+ blk_start_plug(&plug);
lops_before_commit(sdp, tr);
- if (gfs2_withdrawn(sdp))
- goto out_withdraw;
- if (sdp->sd_jdesc)
+ if (!gfs2_withdrawn(sdp) && sdp->sd_jdesc)
gfs2_log_submit_write(&sdp->sd_jdesc->jd_log_bio);
+ blk_finish_plug(&plug);
if (gfs2_withdrawn(sdp))
goto out_withdraw;


--
2.39.5