mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] gfs2: stop using struct page in the log code
@ 2026-11-17  7:46 Tal Zussman
  2026-11-17  7:46 ` [PATCH 1/3] gfs2: stop using pages for log buffers Tal Zussman
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Tal Zussman @ 2026-11-17  7:46 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle), Tal Zussman

This series gets rid of the remaining struct page usage in the gfs2 log
code.

The log headers, descriptors, revoke blocks, and escaped block copies
are allocated as pages from a mempool, and they end up in the same bios
as the page cache buffers being journaled. The completion handler then
calls page_folio() on every segment to figure out which kind it is
looking at. That won't work once memdescs land and those pool pages are
no longer folios.

Patch 1 moves these blocks over to a kmalloc mempool, with their own
bios and completion handler. As a result each descriptor block is now
submitted as its own bio, so patch 2 adds a plug around the log flush to
let the block layer merge them back together. Patch 3 cleans up the
leftover page references in the log code.

Tested with fio 4K write+fsync on gfs2 over virtio-blk and null_blk.
Without an I/O scheduler, patch 1 adds one write request per log flush
(196.7k to 229.5k for 32k fsyncs) and ~10 us to the p99.9 fsync latency
on null_blk (41 us to 51 us); the plug in patch 2 merges them and
restores both performance numbers to the baseline. With mq-deadline
nothing changes.

---
Tal Zussman (3):
      gfs2: stop using pages for log buffers
      gfs2: plug the log writes of a flush
      gfs2: remove the remaining page references in the log code

 fs/gfs2/bmap.h |   1 -
 fs/gfs2/log.c  |  19 ++---
 fs/gfs2/lops.c | 221 +++++++++++++++++++++++++++++++++++----------------------
 fs/gfs2/lops.h |   6 +-
 fs/gfs2/main.c |   8 +--
 fs/gfs2/util.c |   2 +-
 fs/gfs2/util.h |   2 +-
 7 files changed, 154 insertions(+), 105 deletions(-)
---
base-commit: e3280ea8b73964efb447f396fb09401a31373136
change-id: 20261014-gfs2-log-folio-274b84f5cc07

Best regards,
--  
Tal Zussman <tz2294@columbia.edu>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] gfs2: stop using pages for log buffers
  2026-11-17  7:46 [PATCH 0/3] gfs2: stop using struct page in the log code Tal Zussman
@ 2026-11-17  7:46 ` Tal Zussman
  2026-11-20  0:08   ` Andreas Gruenbacher
  2026-11-17  7:46 ` [PATCH 2/3] gfs2: plug the log writes of a flush Tal Zussman
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Tal Zussman @ 2026-11-17  7:46 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle), Tal Zussman

The log headers, descriptors, revoke blocks, and escaped block copies
come from a mempool of pages and share a bio with the buffer heads being
journaled. The completion handler tells the two apart by checking each
segment for buffers, which treats a pool page as a folio. That won't
work once memdescs give these pages a type of their own.

Allocate them from a kmalloc mempool instead and add them to the bio
with bio_add_virt_nofail(). Give the pool blocks their own completion
handler, and start a new bio whenever the handler changes so that a bio
only holds one kind of segment. gfs2_log_write() now takes a folio, so
the log write path no longer uses struct page.

Each descriptor and each escaped block copy is now a bio of its own.
They are contiguous and merge under an I/O scheduler, but the flush
path doesn't plug, so without a scheduler they reach the device as
separate writes.

Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
 fs/gfs2/log.c  |  10 ++-
 fs/gfs2/lops.c | 203 +++++++++++++++++++++++++++++++++++----------------------
 fs/gfs2/lops.h |   6 +-
 fs/gfs2/main.c |   8 +--
 fs/gfs2/util.c |   2 +-
 fs/gfs2/util.h |   2 +-
 6 files changed, 139 insertions(+), 92 deletions(-)

diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 1baaaf30c4fa..238f6655e15f 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -841,7 +841,6 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 {
 	struct gfs2_log_header *lh;
 	u32 hash, crc;
-	struct page *page;
 	struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
 	struct timespec64 tv;
 	struct super_block *sb = sdp->sd_vfs;
@@ -850,9 +849,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 	if (gfs2_withdrawn(sdp))
 		return;
 
-	page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
-	lh = page_address(page);
-	clear_page(lh);
+	lh = mempool_alloc(gfs2_log_buf_pool, GFP_NOIO);
+	memset(lh, 0, sb->s_blocksize);
 
 	lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
 	lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
@@ -905,8 +903,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 		     sb->s_blocksize - LH_V1_SIZE - 4);
 	lh->lh_crc = cpu_to_be32(crc);
 
-	gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock,
-		       REQ_OP_WRITE | op_flags);
+	gfs2_log_write_buf(sdp, jd, lh, sb->s_blocksize, dblock,
+			   REQ_OP_WRITE | op_flags);
 	gfs2_log_submit_write(&jd->jd_log_bio);
 }
 
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 657edd406dd1..c86f92f2e508 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -196,45 +196,69 @@ static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, struct folio *folio,
 	} while (bh && size);
 }
 
+static void gfs2_log_write_error(struct bio *bio)
+{
+	struct gfs2_sbd *sdp = bio->bi_private;
+	int err = blk_status_to_errno(bio->bi_status);
+
+	if (!cmpxchg(&sdp->sd_log_error, 0, err))
+		fs_err(sdp, "Error %d writing to journal, jid=%u\n",
+		       err, sdp->sd_jdesc->jd_jid);
+	gfs2_withdraw(sdp);
+}
+
+static void gfs2_log_write_done(struct bio *bio)
+{
+	struct gfs2_sbd *sdp = bio->bi_private;
+
+	bio_put(bio);
+	if (atomic_dec_and_test(&sdp->sd_log_in_flight))
+		wake_up(&sdp->sd_log_flush_wait);
+}
+
 /**
- * gfs2_end_log_write - end of i/o to the log
+ * gfs2_end_log_write - end of I/O to the log for buffers
  * @bio: The bio
  *
- * Each bio_vec contains either data from the pagecache or data
- * relating to the log itself. Here we iterate over the bio_vec
- * array, processing both kinds of data.
- *
+ * Every folio in the bio comes from the page cache. Unlock the buffers
+ * that were written.
  */
 
 static void gfs2_end_log_write(struct bio *bio)
 {
 	struct gfs2_sbd *sdp = bio->bi_private;
-	struct bio_vec *bvec;
-	struct bvec_iter_all iter_all;
+	struct folio_iter fi;
 
-	if (bio->bi_status) {
-		int err = blk_status_to_errno(bio->bi_status);
+	if (bio->bi_status)
+		gfs2_log_write_error(bio);
 
-		if (!cmpxchg(&sdp->sd_log_error, 0, err))
-			fs_err(sdp, "Error %d writing to journal, jid=%u\n",
-			       err, sdp->sd_jdesc->jd_jid);
-		gfs2_withdraw(sdp);
-	}
+	bio_for_each_folio_all(fi, bio)
+		gfs2_end_log_write_bh(sdp, fi.folio, fi.offset, fi.length,
+				      bio->bi_status);
 
-	bio_for_each_segment_all(bvec, bio, iter_all) {
-		struct page *page = bvec->bv_page;
-		struct folio *folio = page_folio(page);
+	gfs2_log_write_done(bio);
+}
 
-		if (folio && folio_buffers(folio))
-			gfs2_end_log_write_bh(sdp, folio, bvec->bv_offset,
-					bvec->bv_len, bio->bi_status);
-		else
-			mempool_free(page, gfs2_page_pool);
-	}
+/**
+ * gfs2_end_log_write_buf - end of I/O to the log for log blocks
+ * @bio: The bio
+ *
+ * Every segment in the bio is a block from the log buffer mempool.
+ * Return them to the pool.
+ */
 
-	bio_put(bio);
-	if (atomic_dec_and_test(&sdp->sd_log_in_flight))
-		wake_up(&sdp->sd_log_flush_wait);
+static void gfs2_end_log_write_buf(struct bio *bio)
+{
+	struct bio_vec *bvec;
+	struct bvec_iter_all iter_all;
+
+	if (bio->bi_status)
+		gfs2_log_write_error(bio);
+
+	bio_for_each_segment_all(bvec, bio, iter_all)
+		mempool_free(bvec_virt(bvec), gfs2_log_buf_pool);
+
+	gfs2_log_write_done(bio);
 }
 
 /**
@@ -291,9 +315,9 @@ static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno,
  * @flush: Always flush the current bio and allocate a new one?
  *
  * If there is a cached bio, then if the next block number is sequential
- * with the previous one, return it, otherwise flush the bio to the
- * device. If there is no cached bio, or we just flushed it, then
- * allocate a new one.
+ * with the previous one and the bio has the same completion handler,
+ * return it, otherwise flush the bio to the device. If there is no
+ * cached bio, or we just flushed it, then allocate a new one.
  *
  * Returns: The bio to use for log writes
  */
@@ -309,7 +333,7 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
 
 		nblk = bio_end_sector(bio);
 		nblk >>= sdp->sd_fsb2bb_shift;
-		if (blkno == nblk && !flush)
+		if (blkno == nblk && bio->bi_end_io == end_io && !flush)
 			return bio;
 		gfs2_log_submit_write(biop);
 	}
@@ -319,38 +343,63 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
 }
 
 /**
- * gfs2_log_write - write to log
+ * gfs2_log_write - write a folio segment to the log
  * @sdp: the filesystem
  * @jd: The journal descriptor
- * @page: the page to write
+ * @folio: the folio to write
  * @size: the size of the data to write
- * @offset: the offset within the page 
+ * @offset: the offset within the folio
  * @blkno: block number of the log entry
  * @opf: REQ_OP | op_flags
  *
- * Try and add the page segment to the current bio. If that fails,
+ * Try and add the folio segment to the current bio. If that fails,
  * submit the current bio to the device and create a new one, and
- * then add the page segment to that.
+ * then add the folio segment to that.
  */
 
-void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
-		    struct page *page, unsigned size, unsigned offset,
-		    u64 blkno, blk_opf_t opf)
+static void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
+			   struct folio *folio, unsigned int size,
+			   unsigned int offset, u64 blkno, blk_opf_t opf)
 {
 	struct bio *bio;
-	int ret;
 
 	bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio, opf,
 			       gfs2_end_log_write, false);
-	ret = bio_add_page(bio, page, size, offset);
-	if (ret == 0) {
+	if (!bio_add_folio(bio, folio, size, offset)) {
 		bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio,
 				       opf, gfs2_end_log_write, true);
-		ret = bio_add_page(bio, page, size, offset);
-		WARN_ON(ret == 0);
+		WARN_ON(!bio_add_folio(bio, folio, size, offset));
 	}
 }
 
+/**
+ * gfs2_log_write_buf - write a log buffer to the log
+ * @sdp: the filesystem
+ * @jd: The journal descriptor
+ * @buf: the buffer to write, from the log buffer mempool
+ * @size: the size of the data to write
+ * @blkno: block number of the log entry
+ * @opf: REQ_OP | op_flags
+ *
+ * Like gfs2_log_write(), for a block allocated from gfs2_log_buf_pool.
+ * Ownership of the buffer passes to the bio, which returns it to the
+ * pool on completion.
+ */
+
+void gfs2_log_write_buf(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
+			void *buf, unsigned int size, u64 blkno,
+			blk_opf_t opf)
+{
+	struct bio *bio;
+
+	bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio, opf,
+			       gfs2_end_log_write_buf, false);
+	if (bio->bi_vcnt >= bio->bi_max_vecs)
+		bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio,
+				       opf, gfs2_end_log_write_buf, true);
+	bio_add_virt_nofail(bio, buf, size);
+}
+
 /**
  * gfs2_log_write_bh - write a buffer's content to the log
  * @sdp: The super block
@@ -367,30 +416,30 @@ static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
 
 	dblock = gfs2_log_bmap(sdp->sd_jdesc, sdp->sd_log_flush_head);
 	gfs2_log_incr_head(sdp);
-	gfs2_log_write(sdp, sdp->sd_jdesc, folio_page(bh->b_folio, 0),
-			bh->b_size, bh_offset(bh), dblock, REQ_OP_WRITE);
+	gfs2_log_write(sdp, sdp->sd_jdesc, bh->b_folio, bh->b_size,
+		       bh_offset(bh), dblock, REQ_OP_WRITE);
 }
 
 /**
- * gfs2_log_write_page - write one block stored in a page, into the log
+ * gfs2_log_write_block - write one block stored in a log buffer, into the log
  * @sdp: The superblock
- * @page: The struct page
+ * @buf: The buffer
  *
- * This writes the first block-sized part of the page into the log. Note
- * that the page must have been allocated from the gfs2_page_pool mempool
- * and that after this has been called, ownership has been transferred and
- * the page may be freed at any time.
+ * This writes the first block-sized part of the buffer into the log. Note
+ * that the buffer must have been allocated from the gfs2_log_buf_pool
+ * mempool and that after this has been called, ownership has been
+ * transferred and the buffer may be freed at any time.
  */
 
-static void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page)
+static void gfs2_log_write_block(struct gfs2_sbd *sdp, void *buf)
 {
 	struct super_block *sb = sdp->sd_vfs;
 	u64 dblock;
 
 	dblock = gfs2_log_bmap(sdp->sd_jdesc, sdp->sd_log_flush_head);
 	gfs2_log_incr_head(sdp);
-	gfs2_log_write(sdp, sdp->sd_jdesc, page, sb->s_blocksize, 0, dblock,
-		       REQ_OP_WRITE);
+	gfs2_log_write_buf(sdp, sdp->sd_jdesc, buf, sb->s_blocksize, dblock,
+			   REQ_OP_WRITE);
 }
 
 /**
@@ -604,12 +653,14 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
 	return ret;
 }
 
-static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
-				      u32 ld_length, u32 ld_data1)
+static struct gfs2_log_descriptor *gfs2_get_log_desc(struct gfs2_sbd *sdp,
+						     u32 ld_type, u32 ld_length,
+						     u32 ld_data1)
 {
-	struct page *page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
-	struct gfs2_log_descriptor *ld = page_address(page);
-	clear_page(ld);
+	struct gfs2_log_descriptor *ld;
+
+	ld = mempool_alloc(gfs2_log_buf_pool, GFP_NOIO);
+	memset(ld, 0, sdp->sd_sb.sb_bsize);
 	ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
 	ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD);
 	ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD);
@@ -617,7 +668,7 @@ static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
 	ld->ld_length = cpu_to_be32(ld_length);
 	ld->ld_data1 = cpu_to_be32(ld_data1);
 	ld->ld_data2 = 0;
-	return page;
+	return ld;
 }
 
 static void gfs2_check_magic(struct buffer_head *bh)
@@ -652,7 +703,6 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 {
 	struct gfs2_log_descriptor *ld;
 	struct gfs2_bufdata *bd1 = NULL, *bd2;
-	struct page *page;
 	unsigned int num;
 	unsigned n;
 	__be64 *ptr;
@@ -665,10 +715,9 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 		if (total > limit)
 			num = limit;
 		spin_unlock(&sdp->sd_log_lock);
-		page = gfs2_get_log_desc(sdp,
-					 is_databuf ? GFS2_LOG_DESC_JDATA :
-					 GFS2_LOG_DESC_METADATA, num + 1, num);
-		ld = page_address(page);
+		ld = gfs2_get_log_desc(sdp,
+				       is_databuf ? GFS2_LOG_DESC_JDATA :
+				       GFS2_LOG_DESC_METADATA, num + 1, num);
 		spin_lock(&sdp->sd_log_lock);
 		ptr = (__be64 *)(ld + 1);
 
@@ -684,7 +733,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 		}
 
 		spin_unlock(&sdp->sd_log_lock);
-		gfs2_log_write_page(sdp, page);
+		gfs2_log_write_block(sdp, ld);
 		spin_lock(&sdp->sd_log_lock);
 
 		n = 0;
@@ -696,8 +745,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 			if (buffer_escaped(bd2->bd_bh)) {
 				void *p;
 
-				page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
-				p = page_address(page);
+				p = mempool_alloc(gfs2_log_buf_pool, GFP_NOIO);
 				memcpy_from_folio(p, bd2->bd_bh->b_folio,
 						  bh_offset(bd2->bd_bh),
 						  bd2->bd_bh->b_size);
@@ -705,7 +753,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 				clear_buffer_escaped(bd2->bd_bh);
 				unlock_buffer(bd2->bd_bh);
 				brelse(bd2->bd_bh);
-				gfs2_log_write_page(sdp, page);
+				gfs2_log_write_block(sdp, p);
 			} else {
 				gfs2_log_write_bh(sdp, bd2->bd_bh);
 			}
@@ -856,7 +904,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
 	struct gfs2_meta_header *mh;
 	unsigned int offset;
 	struct gfs2_bufdata *bd;
-	struct page *page;
+	void *buf;
 	unsigned int length;
 
 	gfs2_flush_revokes(sdp);
@@ -864,29 +912,30 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
 		return;
 
 	length = gfs2_struct2blk(sdp, sdp->sd_log_num_revoke);
-	page = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_REVOKE, length, sdp->sd_log_num_revoke);
+	buf = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_REVOKE, length,
+				sdp->sd_log_num_revoke);
 	offset = sizeof(struct gfs2_log_descriptor);
 
 	list_for_each_entry(bd, &sdp->sd_log_revokes, bd_list) {
 		sdp->sd_log_num_revoke--;
 
 		if (offset + sizeof(u64) > sdp->sd_sb.sb_bsize) {
-			gfs2_log_write_page(sdp, page);
-			page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
-			mh = page_address(page);
-			clear_page(mh);
+			gfs2_log_write_block(sdp, buf);
+			buf = mempool_alloc(gfs2_log_buf_pool, GFP_NOIO);
+			mh = buf;
+			memset(mh, 0, sdp->sd_sb.sb_bsize);
 			mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
 			mh->mh_type = cpu_to_be32(GFS2_METATYPE_LB);
 			mh->mh_format = cpu_to_be32(GFS2_FORMAT_LB);
 			offset = sizeof(struct gfs2_meta_header);
 		}
 
-		*(__be64 *)(page_address(page) + offset) = cpu_to_be64(bd->bd_blkno);
+		*(__be64 *)(buf + offset) = cpu_to_be64(bd->bd_blkno);
 		offset += sizeof(u64);
 	}
 	gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
 
-	gfs2_log_write_page(sdp, page);
+	gfs2_log_write_block(sdp, buf);
 }
 
 void gfs2_drain_revokes(struct gfs2_sbd *sdp)
diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h
index 772557b63b48..c1d9e6fef7ac 100644
--- a/fs/gfs2/lops.h
+++ b/fs/gfs2/lops.h
@@ -14,9 +14,9 @@ extern const struct gfs2_log_operations *gfs2_log_ops[];
 
 void gfs2_log_incr_head(struct gfs2_sbd *sdp);
 u64 gfs2_log_bmap(struct gfs2_jdesc *jd, unsigned int lbn);
-void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
-		    struct page *page, unsigned size, unsigned offset,
-		    u64 blkno, blk_opf_t opf);
+void gfs2_log_write_buf(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
+			void *buf, unsigned int size, u64 blkno,
+			blk_opf_t opf);
 void gfs2_log_submit_write(struct bio **biop);
 void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
 int gfs2_find_jhead(struct gfs2_jdesc *jd,
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index a607e98eb45f..0da4cfbe54ea 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -166,8 +166,8 @@ static int __init init_gfs2_fs(void)
 	if (!gfs2_freeze_wq)
 		goto fail_wq3;
 
-	gfs2_page_pool = mempool_create_page_pool(64, 0);
-	if (!gfs2_page_pool)
+	gfs2_log_buf_pool = mempool_create_kmalloc_pool(64, PAGE_SIZE);
+	if (!gfs2_log_buf_pool)
 		goto fail_mempool;
 
 	gfs2_register_debugfs();
@@ -187,7 +187,7 @@ static int __init init_gfs2_fs(void)
 fail_fs2:
 	unregister_filesystem(&gfs2_fs_type);
 fail_fs1:
-	mempool_destroy(gfs2_page_pool);
+	mempool_destroy(gfs2_log_buf_pool);
 fail_mempool:
 	destroy_workqueue(gfs2_freeze_wq);
 fail_wq3:
@@ -240,7 +240,7 @@ static void __exit exit_gfs2_fs(void)
 
 	rcu_barrier();
 
-	mempool_destroy(gfs2_page_pool);
+	mempool_destroy(gfs2_log_buf_pool);
 	kmem_cache_destroy(gfs2_trans_cachep);
 	kmem_cache_destroy(gfs2_qadata_cachep);
 	kmem_cache_destroy(gfs2_quotad_cachep);
diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
index 529c3ec37a18..1fd5f817312b 100644
--- a/fs/gfs2/util.c
+++ b/fs/gfs2/util.c
@@ -34,7 +34,7 @@ struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
 struct kmem_cache *gfs2_quotad_cachep __read_mostly;
 struct kmem_cache *gfs2_qadata_cachep __read_mostly;
 struct kmem_cache *gfs2_trans_cachep __read_mostly;
-mempool_t *gfs2_page_pool __read_mostly;
+mempool_t *gfs2_log_buf_pool __read_mostly;
 
 void gfs2_assert_i(struct gfs2_sbd *sdp)
 {
diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h
index ffcc47d6b0b4..399c20004283 100644
--- a/fs/gfs2/util.h
+++ b/fs/gfs2/util.h
@@ -165,7 +165,7 @@ extern struct kmem_cache *gfs2_rgrpd_cachep;
 extern struct kmem_cache *gfs2_quotad_cachep;
 extern struct kmem_cache *gfs2_qadata_cachep;
 extern struct kmem_cache *gfs2_trans_cachep;
-extern mempool_t *gfs2_page_pool;
+extern mempool_t *gfs2_log_buf_pool;
 extern struct workqueue_struct *gfs2_control_wq;
 
 static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,

-- 
2.39.5


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/3] gfs2: plug the log writes of a flush
  2026-11-17  7:46 [PATCH 0/3] gfs2: stop using struct page in the log code Tal Zussman
  2026-11-17  7:46 ` [PATCH 1/3] gfs2: stop using pages for log buffers Tal Zussman
@ 2026-11-17  7:46 ` Tal Zussman
  2026-11-17  7:46 ` [PATCH 3/3] gfs2: remove the remaining page references in the log code Tal Zussman
  2026-11-19 23:47 ` [PATCH 0/3] gfs2: stop using struct page " Andreas Gruenbacher
  3 siblings, 0 replies; 8+ messages in thread
From: Tal Zussman @ 2026-11-17  7:46 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle), Tal Zussman

__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@columbia.edu>
---
 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/3] gfs2: remove the remaining page references in the log code
  2026-11-17  7:46 [PATCH 0/3] gfs2: stop using struct page in the log code Tal Zussman
  2026-11-17  7:46 ` [PATCH 1/3] gfs2: stop using pages for log buffers Tal Zussman
  2026-11-17  7:46 ` [PATCH 2/3] gfs2: plug the log writes of a flush Tal Zussman
@ 2026-11-17  7:46 ` Tal Zussman
  2026-11-19 23:47 ` [PATCH 0/3] gfs2: stop using struct page " Andreas Gruenbacher
  3 siblings, 0 replies; 8+ messages in thread
From: Tal Zussman @ 2026-11-17  7:46 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle), Tal Zussman

gfs2_jhead_process_page() takes a folio, and the comments around it and
gfs2_end_log_read() still describe folios as pages. Rename it to
gfs2_jhead_process_folio() and update the comments.

Drop the struct page forward declaration from bmap.h as well, which has
had no user since the unstuff path was converted.

Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
 fs/gfs2/bmap.h |  1 -
 fs/gfs2/lops.c | 18 +++++++++---------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h
index e3d6efdfd890..7b44cc9c742c 100644
--- a/fs/gfs2/bmap.h
+++ b/fs/gfs2/bmap.h
@@ -13,7 +13,6 @@
 
 struct inode;
 struct gfs2_inode;
-struct page;
 
 
 /**
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index c86f92f2e508..805466667e8a 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -446,7 +446,7 @@ static void gfs2_log_write_block(struct gfs2_sbd *sdp, void *buf)
  * gfs2_end_log_read - end I/O callback for reads from the log
  * @bio: The bio
  *
- * Simply unlock the pages in the bio. The main thread will wait on them and
+ * Simply unlock the folios in the bio. The main thread will wait on them and
  * process them in order as necessary.
  */
 static void gfs2_end_log_read(struct bio *bio)
@@ -464,7 +464,7 @@ static void gfs2_end_log_read(struct bio *bio)
 }
 
 /**
- * gfs2_jhead_folio_search - Look for the journal head in a given page.
+ * gfs2_jhead_folio_search - Look for the journal head in a given folio.
  * @jd: The journal descriptor
  * @head: The journal head to start from
  * @folio: The folio to look in
@@ -498,9 +498,9 @@ static bool gfs2_jhead_folio_search(struct gfs2_jdesc *jd,
 }
 
 /**
- * gfs2_jhead_process_page - Search/cleanup a page
+ * gfs2_jhead_process_folio - Search/cleanup a folio
  * @jd: The journal descriptor
- * @index: Index of the page to look into
+ * @index: Index of the folio to look into
  * @head: The journal head to start from
  * @done: If set, perform only cleanup, else search and set if found.
  *
@@ -517,9 +517,9 @@ static bool gfs2_jhead_folio_search(struct gfs2_jdesc *jd,
  * our references to the folio.
  */
 
-static void gfs2_jhead_process_page(struct gfs2_jdesc *jd, unsigned long index,
-				    struct gfs2_log_header_host *head,
-				    bool *done)
+static void gfs2_jhead_process_folio(struct gfs2_jdesc *jd, unsigned long index,
+				     struct gfs2_log_header_host *head,
+				     bool *done)
 {
 	struct folio *folio;
 
@@ -630,7 +630,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
 				continue;
 			}
 
-			gfs2_jhead_process_page(jd, blocks_read >> shift, head, &done);
+			gfs2_jhead_process_folio(jd, blocks_read >> shift, head, &done);
 			blocks_read += PAGE_SIZE >> bsize_shift;
 			if (done)
 				goto out;  /* found */
@@ -641,7 +641,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
 	if (bio)
 		submit_bio(bio);
 	while (blocks_read < block) {
-		gfs2_jhead_process_page(jd, blocks_read >> shift, head, &done);
+		gfs2_jhead_process_folio(jd, blocks_read >> shift, head, &done);
 		blocks_read += PAGE_SIZE >> bsize_shift;
 	}
 

-- 
2.39.5


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] gfs2: stop using struct page in the log code
  2026-11-17  7:46 [PATCH 0/3] gfs2: stop using struct page in the log code Tal Zussman
                   ` (2 preceding siblings ...)
  2026-11-17  7:46 ` [PATCH 3/3] gfs2: remove the remaining page references in the log code Tal Zussman
@ 2026-11-19 23:47 ` Andreas Gruenbacher
  2026-11-20 18:11   ` Tal Zussman
  3 siblings, 1 reply; 8+ messages in thread
From: Andreas Gruenbacher @ 2026-11-19 23:47 UTC (permalink / raw)
  To: Tal Zussman; +Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle)

Tal,

On Tue, Nov 17, 2026 at 8:46 AM Tal Zussman <tz2294@columbia.edu> wrote:
> This series gets rid of the remaining struct page usage in the gfs2 log
> code.
>
> The log headers, descriptors, revoke blocks, and escaped block copies
> are allocated as pages from a mempool, and they end up in the same bios
> as the page cache buffers being journaled. The completion handler then
> calls page_folio() on every segment to figure out which kind it is
> looking at. That won't work once memdescs land and those pool pages are
> no longer folios.
>
> Patch 1 moves these blocks over to a kmalloc mempool, with their own
> bios and completion handler. As a result each descriptor block is now
> submitted as its own bio, so patch 2 adds a plug around the log flush to
> let the block layer merge them back together. Patch 3 cleans up the
> leftover page references in the log code.
>
> Tested with fio 4K write+fsync on gfs2 over virtio-blk and null_blk.
> Without an I/O scheduler, patch 1 adds one write request per log flush
> (196.7k to 229.5k for 32k fsyncs) and ~10 us to the p99.9 fsync latency
> on null_blk (41 us to 51 us); the plug in patch 2 merges them and
> restores both performance numbers to the baseline. With mq-deadline
> nothing changes.

thank you for these patches. Could you please rerun that test with a
block size smaller than the page size?

Thanks,
Andreas

> ---
> Tal Zussman (3):
>       gfs2: stop using pages for log buffers
>       gfs2: plug the log writes of a flush
>       gfs2: remove the remaining page references in the log code
>
>  fs/gfs2/bmap.h |   1 -
>  fs/gfs2/log.c  |  19 ++---
>  fs/gfs2/lops.c | 221 +++++++++++++++++++++++++++++++++++----------------------
>  fs/gfs2/lops.h |   6 +-
>  fs/gfs2/main.c |   8 +--
>  fs/gfs2/util.c |   2 +-
>  fs/gfs2/util.h |   2 +-
>  7 files changed, 154 insertions(+), 105 deletions(-)
> ---
> base-commit: e3280ea8b73964efb447f396fb09401a31373136
> change-id: 20261014-gfs2-log-folio-274b84f5cc07
>
> Best regards,
> --
> Tal Zussman <tz2294@columbia.edu>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] gfs2: stop using pages for log buffers
  2026-11-17  7:46 ` [PATCH 1/3] gfs2: stop using pages for log buffers Tal Zussman
@ 2026-11-20  0:08   ` Andreas Gruenbacher
  2026-11-20 18:14     ` Tal Zussman
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Gruenbacher @ 2026-11-20  0:08 UTC (permalink / raw)
  To: Tal Zussman; +Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle)

On Tue, Nov 17, 2026 at 8:46 AM Tal Zussman <tz2294@columbia.edu> wrote:
>
> The log headers, descriptors, revoke blocks, and escaped block copies
> come from a mempool of pages and share a bio with the buffer heads being
> journaled. The completion handler tells the two apart by checking each
> segment for buffers, which treats a pool page as a folio. That won't
> work once memdescs give these pages a type of their own.
>
> Allocate them from a kmalloc mempool instead and add them to the bio
> with bio_add_virt_nofail(). Give the pool blocks their own completion
> handler, and start a new bio whenever the handler changes so that a bio
> only holds one kind of segment. gfs2_log_write() now takes a folio, so
> the log write path no longer uses struct page.
>
> Each descriptor and each escaped block copy is now a bio of its own.
> They are contiguous and merge under an I/O scheduler, but the flush
> path doesn't plug, so without a scheduler they reach the device as
> separate writes.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
>  fs/gfs2/log.c  |  10 ++-
>  fs/gfs2/lops.c | 203 +++++++++++++++++++++++++++++++++++----------------------
>  fs/gfs2/lops.h |   6 +-
>  fs/gfs2/main.c |   8 +--
>  fs/gfs2/util.c |   2 +-
>  fs/gfs2/util.h |   2 +-
>  6 files changed, 139 insertions(+), 92 deletions(-)
>
> diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
> index 1baaaf30c4fa..238f6655e15f 100644
> --- a/fs/gfs2/log.c
> +++ b/fs/gfs2/log.c
> @@ -841,7 +841,6 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
>  {
>         struct gfs2_log_header *lh;
>         u32 hash, crc;
> -       struct page *page;
>         struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
>         struct timespec64 tv;
>         struct super_block *sb = sdp->sd_vfs;
> @@ -850,9 +849,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
>         if (gfs2_withdrawn(sdp))
>                 return;
>
> -       page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
> -       lh = page_address(page);
> -       clear_page(lh);
> +       lh = mempool_alloc(gfs2_log_buf_pool, GFP_NOIO);
> +       memset(lh, 0, sb->s_blocksize);
>
>         lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
>         lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
> @@ -905,8 +903,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
>                      sb->s_blocksize - LH_V1_SIZE - 4);
>         lh->lh_crc = cpu_to_be32(crc);
>
> -       gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock,
> -                      REQ_OP_WRITE | op_flags);
> +       gfs2_log_write_buf(sdp, jd, lh, sb->s_blocksize, dblock,
> +                          REQ_OP_WRITE | op_flags);
>         gfs2_log_submit_write(&jd->jd_log_bio);
>  }
>
> diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
> index 657edd406dd1..c86f92f2e508 100644
> --- a/fs/gfs2/lops.c
> +++ b/fs/gfs2/lops.c
> @@ -196,45 +196,69 @@ static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, struct folio *folio,
>         } while (bh && size);
>  }
>
> +static void gfs2_log_write_error(struct bio *bio)
> +{
> +       struct gfs2_sbd *sdp = bio->bi_private;
> +       int err = blk_status_to_errno(bio->bi_status);
> +
> +       if (!cmpxchg(&sdp->sd_log_error, 0, err))
> +               fs_err(sdp, "Error %d writing to journal, jid=%u\n",
> +                      err, sdp->sd_jdesc->jd_jid);
> +       gfs2_withdraw(sdp);
> +}
> +
> +static void gfs2_log_write_done(struct bio *bio)
> +{
> +       struct gfs2_sbd *sdp = bio->bi_private;
> +
> +       bio_put(bio);
> +       if (atomic_dec_and_test(&sdp->sd_log_in_flight))
> +               wake_up(&sdp->sd_log_flush_wait);
> +}
> +
>  /**
> - * gfs2_end_log_write - end of i/o to the log
> + * gfs2_end_log_write - end of I/O to the log for buffers
>   * @bio: The bio
>   *
> - * Each bio_vec contains either data from the pagecache or data
> - * relating to the log itself. Here we iterate over the bio_vec
> - * array, processing both kinds of data.
> - *
> + * Every folio in the bio comes from the page cache. Unlock the buffers
> + * that were written.
>   */
>
>  static void gfs2_end_log_write(struct bio *bio)
>  {
>         struct gfs2_sbd *sdp = bio->bi_private;
> -       struct bio_vec *bvec;
> -       struct bvec_iter_all iter_all;
> +       struct folio_iter fi;
>
> -       if (bio->bi_status) {
> -               int err = blk_status_to_errno(bio->bi_status);
> +       if (bio->bi_status)
> +               gfs2_log_write_error(bio);
>
> -               if (!cmpxchg(&sdp->sd_log_error, 0, err))
> -                       fs_err(sdp, "Error %d writing to journal, jid=%u\n",
> -                              err, sdp->sd_jdesc->jd_jid);
> -               gfs2_withdraw(sdp);
> -       }
> +       bio_for_each_folio_all(fi, bio)
> +               gfs2_end_log_write_bh(sdp, fi.folio, fi.offset, fi.length,
> +                                     bio->bi_status);
>
> -       bio_for_each_segment_all(bvec, bio, iter_all) {
> -               struct page *page = bvec->bv_page;
> -               struct folio *folio = page_folio(page);
> +       gfs2_log_write_done(bio);
> +}
>
> -               if (folio && folio_buffers(folio))
> -                       gfs2_end_log_write_bh(sdp, folio, bvec->bv_offset,
> -                                       bvec->bv_len, bio->bi_status);
> -               else
> -                       mempool_free(page, gfs2_page_pool);
> -       }
> +/**
> + * gfs2_end_log_write_buf - end of I/O to the log for log blocks
> + * @bio: The bio
> + *
> + * Every segment in the bio is a block from the log buffer mempool.
> + * Return them to the pool.
> + */
>
> -       bio_put(bio);
> -       if (atomic_dec_and_test(&sdp->sd_log_in_flight))
> -               wake_up(&sdp->sd_log_flush_wait);
> +static void gfs2_end_log_write_buf(struct bio *bio)
> +{
> +       struct bio_vec *bvec;
> +       struct bvec_iter_all iter_all;
> +
> +       if (bio->bi_status)
> +               gfs2_log_write_error(bio);
> +
> +       bio_for_each_segment_all(bvec, bio, iter_all)
> +               mempool_free(bvec_virt(bvec), gfs2_log_buf_pool);
> +
> +       gfs2_log_write_done(bio);
>  }
>
>  /**
> @@ -291,9 +315,9 @@ static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno,
>   * @flush: Always flush the current bio and allocate a new one?
>   *
>   * If there is a cached bio, then if the next block number is sequential
> - * with the previous one, return it, otherwise flush the bio to the
> - * device. If there is no cached bio, or we just flushed it, then
> - * allocate a new one.
> + * with the previous one and the bio has the same completion handler,
> + * return it, otherwise flush the bio to the device. If there is no
> + * cached bio, or we just flushed it, then allocate a new one.
>   *
>   * Returns: The bio to use for log writes
>   */
> @@ -309,7 +333,7 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
>
>                 nblk = bio_end_sector(bio);
>                 nblk >>= sdp->sd_fsb2bb_shift;
> -               if (blkno == nblk && !flush)
> +               if (blkno == nblk && bio->bi_end_io == end_io && !flush)
>                         return bio;
>                 gfs2_log_submit_write(biop);
>         }
> @@ -319,38 +343,63 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
>  }
>
>  /**
> - * gfs2_log_write - write to log
> + * gfs2_log_write - write a folio segment to the log
>   * @sdp: the filesystem
>   * @jd: The journal descriptor
> - * @page: the page to write
> + * @folio: the folio to write
>   * @size: the size of the data to write
> - * @offset: the offset within the page
> + * @offset: the offset within the folio
>   * @blkno: block number of the log entry
>   * @opf: REQ_OP | op_flags
>   *
> - * Try and add the page segment to the current bio. If that fails,
> + * Try and add the folio segment to the current bio. If that fails,
>   * submit the current bio to the device and create a new one, and
> - * then add the page segment to that.
> + * then add the folio segment to that.
>   */
>
> -void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
> -                   struct page *page, unsigned size, unsigned offset,
> -                   u64 blkno, blk_opf_t opf)
> +static void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
> +                          struct folio *folio, unsigned int size,
> +                          unsigned int offset, u64 blkno, blk_opf_t opf)
>  {
>         struct bio *bio;
> -       int ret;
>
>         bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio, opf,
>                                gfs2_end_log_write, false);
> -       ret = bio_add_page(bio, page, size, offset);
> -       if (ret == 0) {
> +       if (!bio_add_folio(bio, folio, size, offset)) {
>                 bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio,
>                                        opf, gfs2_end_log_write, true);
> -               ret = bio_add_page(bio, page, size, offset);
> -               WARN_ON(ret == 0);
> +               WARN_ON(!bio_add_folio(bio, folio, size, offset));
>         }
>  }
>
> +/**
> + * gfs2_log_write_buf - write a log buffer to the log
> + * @sdp: the filesystem
> + * @jd: The journal descriptor
> + * @buf: the buffer to write, from the log buffer mempool
> + * @size: the size of the data to write
> + * @blkno: block number of the log entry
> + * @opf: REQ_OP | op_flags
> + *
> + * Like gfs2_log_write(), for a block allocated from gfs2_log_buf_pool.
> + * Ownership of the buffer passes to the bio, which returns it to the
> + * pool on completion.
> + */
> +
> +void gfs2_log_write_buf(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
> +                       void *buf, unsigned int size, u64 blkno,
> +                       blk_opf_t opf)
> +{
> +       struct bio *bio;
> +
> +       bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio, opf,
> +                              gfs2_end_log_write_buf, false);
> +       if (bio->bi_vcnt >= bio->bi_max_vecs)
> +               bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio,
> +                                      opf, gfs2_end_log_write_buf, true);
> +       bio_add_virt_nofail(bio, buf, size);
> +}
> +
>  /**
>   * gfs2_log_write_bh - write a buffer's content to the log
>   * @sdp: The super block
> @@ -367,30 +416,30 @@ static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
>
>         dblock = gfs2_log_bmap(sdp->sd_jdesc, sdp->sd_log_flush_head);
>         gfs2_log_incr_head(sdp);
> -       gfs2_log_write(sdp, sdp->sd_jdesc, folio_page(bh->b_folio, 0),
> -                       bh->b_size, bh_offset(bh), dblock, REQ_OP_WRITE);
> +       gfs2_log_write(sdp, sdp->sd_jdesc, bh->b_folio, bh->b_size,
> +                      bh_offset(bh), dblock, REQ_OP_WRITE);
>  }
>
>  /**
> - * gfs2_log_write_page - write one block stored in a page, into the log
> + * gfs2_log_write_block - write one block stored in a log buffer, into the log
>   * @sdp: The superblock
> - * @page: The struct page
> + * @buf: The buffer
>   *
> - * This writes the first block-sized part of the page into the log. Note
> - * that the page must have been allocated from the gfs2_page_pool mempool
> - * and that after this has been called, ownership has been transferred and
> - * the page may be freed at any time.
> + * This writes the first block-sized part of the buffer into the log. Note
> + * that the buffer must have been allocated from the gfs2_log_buf_pool
> + * mempool and that after this has been called, ownership has been
> + * transferred and the buffer may be freed at any time.
>   */
>
> -static void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page)
> +static void gfs2_log_write_block(struct gfs2_sbd *sdp, void *buf)
>  {
>         struct super_block *sb = sdp->sd_vfs;
>         u64 dblock;
>
>         dblock = gfs2_log_bmap(sdp->sd_jdesc, sdp->sd_log_flush_head);
>         gfs2_log_incr_head(sdp);
> -       gfs2_log_write(sdp, sdp->sd_jdesc, page, sb->s_blocksize, 0, dblock,
> -                      REQ_OP_WRITE);
> +       gfs2_log_write_buf(sdp, sdp->sd_jdesc, buf, sb->s_blocksize, dblock,
> +                          REQ_OP_WRITE);
>  }
>
>  /**
> @@ -604,12 +653,14 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
>         return ret;
>  }
>
> -static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
> -                                     u32 ld_length, u32 ld_data1)
> +static struct gfs2_log_descriptor *gfs2_get_log_desc(struct gfs2_sbd *sdp,
> +                                                    u32 ld_type, u32 ld_length,
> +                                                    u32 ld_data1)
>  {
> -       struct page *page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
> -       struct gfs2_log_descriptor *ld = page_address(page);
> -       clear_page(ld);
> +       struct gfs2_log_descriptor *ld;
> +
> +       ld = mempool_alloc(gfs2_log_buf_pool, GFP_NOIO);
> +       memset(ld, 0, sdp->sd_sb.sb_bsize);
>         ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
>         ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD);
>         ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD);
> @@ -617,7 +668,7 @@ static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
>         ld->ld_length = cpu_to_be32(ld_length);
>         ld->ld_data1 = cpu_to_be32(ld_data1);
>         ld->ld_data2 = 0;
> -       return page;
> +       return ld;
>  }
>
>  static void gfs2_check_magic(struct buffer_head *bh)
> @@ -652,7 +703,6 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
>  {
>         struct gfs2_log_descriptor *ld;
>         struct gfs2_bufdata *bd1 = NULL, *bd2;
> -       struct page *page;
>         unsigned int num;
>         unsigned n;
>         __be64 *ptr;
> @@ -665,10 +715,9 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
>                 if (total > limit)
>                         num = limit;
>                 spin_unlock(&sdp->sd_log_lock);
> -               page = gfs2_get_log_desc(sdp,
> -                                        is_databuf ? GFS2_LOG_DESC_JDATA :
> -                                        GFS2_LOG_DESC_METADATA, num + 1, num);
> -               ld = page_address(page);
> +               ld = gfs2_get_log_desc(sdp,
> +                                      is_databuf ? GFS2_LOG_DESC_JDATA :
> +                                      GFS2_LOG_DESC_METADATA, num + 1, num);
>                 spin_lock(&sdp->sd_log_lock);
>                 ptr = (__be64 *)(ld + 1);
>
> @@ -684,7 +733,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
>                 }
>
>                 spin_unlock(&sdp->sd_log_lock);
> -               gfs2_log_write_page(sdp, page);
> +               gfs2_log_write_block(sdp, ld);
>                 spin_lock(&sdp->sd_log_lock);
>
>                 n = 0;
> @@ -696,8 +745,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
>                         if (buffer_escaped(bd2->bd_bh)) {
>                                 void *p;
>
> -                               page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
> -                               p = page_address(page);
> +                               p = mempool_alloc(gfs2_log_buf_pool, GFP_NOIO);
>                                 memcpy_from_folio(p, bd2->bd_bh->b_folio,
>                                                   bh_offset(bd2->bd_bh),
>                                                   bd2->bd_bh->b_size);
> @@ -705,7 +753,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
>                                 clear_buffer_escaped(bd2->bd_bh);
>                                 unlock_buffer(bd2->bd_bh);
>                                 brelse(bd2->bd_bh);
> -                               gfs2_log_write_page(sdp, page);
> +                               gfs2_log_write_block(sdp, p);
>                         } else {
>                                 gfs2_log_write_bh(sdp, bd2->bd_bh);
>                         }
> @@ -856,7 +904,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
>         struct gfs2_meta_header *mh;
>         unsigned int offset;
>         struct gfs2_bufdata *bd;
> -       struct page *page;
> +       void *buf;
>         unsigned int length;
>
>         gfs2_flush_revokes(sdp);
> @@ -864,29 +912,30 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
>                 return;
>
>         length = gfs2_struct2blk(sdp, sdp->sd_log_num_revoke);
> -       page = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_REVOKE, length, sdp->sd_log_num_revoke);
> +       buf = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_REVOKE, length,
> +                               sdp->sd_log_num_revoke);
>         offset = sizeof(struct gfs2_log_descriptor);
>
>         list_for_each_entry(bd, &sdp->sd_log_revokes, bd_list) {
>                 sdp->sd_log_num_revoke--;
>
>                 if (offset + sizeof(u64) > sdp->sd_sb.sb_bsize) {
> -                       gfs2_log_write_page(sdp, page);
> -                       page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
> -                       mh = page_address(page);
> -                       clear_page(mh);
> +                       gfs2_log_write_block(sdp, buf);
> +                       buf = mempool_alloc(gfs2_log_buf_pool, GFP_NOIO);
> +                       mh = buf;
> +                       memset(mh, 0, sdp->sd_sb.sb_bsize);
>                         mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
>                         mh->mh_type = cpu_to_be32(GFS2_METATYPE_LB);
>                         mh->mh_format = cpu_to_be32(GFS2_FORMAT_LB);
>                         offset = sizeof(struct gfs2_meta_header);
>                 }
>
> -               *(__be64 *)(page_address(page) + offset) = cpu_to_be64(bd->bd_blkno);
> +               *(__be64 *)(buf + offset) = cpu_to_be64(bd->bd_blkno);
>                 offset += sizeof(u64);
>         }
>         gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
>
> -       gfs2_log_write_page(sdp, page);
> +       gfs2_log_write_block(sdp, buf);
>  }
>
>  void gfs2_drain_revokes(struct gfs2_sbd *sdp)
> diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h
> index 772557b63b48..c1d9e6fef7ac 100644
> --- a/fs/gfs2/lops.h
> +++ b/fs/gfs2/lops.h
> @@ -14,9 +14,9 @@ extern const struct gfs2_log_operations *gfs2_log_ops[];
>
>  void gfs2_log_incr_head(struct gfs2_sbd *sdp);
>  u64 gfs2_log_bmap(struct gfs2_jdesc *jd, unsigned int lbn);
> -void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
> -                   struct page *page, unsigned size, unsigned offset,
> -                   u64 blkno, blk_opf_t opf);
> +void gfs2_log_write_buf(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
> +                       void *buf, unsigned int size, u64 blkno,
> +                       blk_opf_t opf);
>  void gfs2_log_submit_write(struct bio **biop);
>  void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
>  int gfs2_find_jhead(struct gfs2_jdesc *jd,
> diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
> index a607e98eb45f..0da4cfbe54ea 100644
> --- a/fs/gfs2/main.c
> +++ b/fs/gfs2/main.c
> @@ -166,8 +166,8 @@ static int __init init_gfs2_fs(void)
>         if (!gfs2_freeze_wq)
>                 goto fail_wq3;
>
> -       gfs2_page_pool = mempool_create_page_pool(64, 0);
> -       if (!gfs2_page_pool)
> +       gfs2_log_buf_pool = mempool_create_kmalloc_pool(64, PAGE_SIZE);

We actually need s_blocksize size rather than PAGE_SIZE buffers here.
How about a per-sbd mempool instead of a global one?

> +       if (!gfs2_log_buf_pool)
>                 goto fail_mempool;
>
>         gfs2_register_debugfs();
> @@ -187,7 +187,7 @@ static int __init init_gfs2_fs(void)
>  fail_fs2:
>         unregister_filesystem(&gfs2_fs_type);
>  fail_fs1:
> -       mempool_destroy(gfs2_page_pool);
> +       mempool_destroy(gfs2_log_buf_pool);
>  fail_mempool:
>         destroy_workqueue(gfs2_freeze_wq);
>  fail_wq3:
> @@ -240,7 +240,7 @@ static void __exit exit_gfs2_fs(void)
>
>         rcu_barrier();
>
> -       mempool_destroy(gfs2_page_pool);
> +       mempool_destroy(gfs2_log_buf_pool);
>         kmem_cache_destroy(gfs2_trans_cachep);
>         kmem_cache_destroy(gfs2_qadata_cachep);
>         kmem_cache_destroy(gfs2_quotad_cachep);
> diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
> index 529c3ec37a18..1fd5f817312b 100644
> --- a/fs/gfs2/util.c
> +++ b/fs/gfs2/util.c
> @@ -34,7 +34,7 @@ struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
>  struct kmem_cache *gfs2_quotad_cachep __read_mostly;
>  struct kmem_cache *gfs2_qadata_cachep __read_mostly;
>  struct kmem_cache *gfs2_trans_cachep __read_mostly;
> -mempool_t *gfs2_page_pool __read_mostly;
> +mempool_t *gfs2_log_buf_pool __read_mostly;
>
>  void gfs2_assert_i(struct gfs2_sbd *sdp)
>  {
> diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h
> index ffcc47d6b0b4..399c20004283 100644
> --- a/fs/gfs2/util.h
> +++ b/fs/gfs2/util.h
> @@ -165,7 +165,7 @@ extern struct kmem_cache *gfs2_rgrpd_cachep;
>  extern struct kmem_cache *gfs2_quotad_cachep;
>  extern struct kmem_cache *gfs2_qadata_cachep;
>  extern struct kmem_cache *gfs2_trans_cachep;
> -extern mempool_t *gfs2_page_pool;
> +extern mempool_t *gfs2_log_buf_pool;
>  extern struct workqueue_struct *gfs2_control_wq;
>
>  static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
>
> --
> 2.39.5
>

Thanks,
Andreas


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] gfs2: stop using struct page in the log code
  2026-11-19 23:47 ` [PATCH 0/3] gfs2: stop using struct page " Andreas Gruenbacher
@ 2026-11-20 18:11   ` Tal Zussman
  0 siblings, 0 replies; 8+ messages in thread
From: Tal Zussman @ 2026-11-20 18:11 UTC (permalink / raw)
  To: Andreas Gruenbacher; +Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle)

On 11/19/26 6:47 PM, Andreas Gruenbacher wrote:
> Tal,
> 
> On Tue, Nov 17, 2026 at 8:46 AM Tal Zussman <tz2294@columbia.edu> wrote:
>> This series gets rid of the remaining struct page usage in the gfs2 log
>> code.
>>
>> The log headers, descriptors, revoke blocks, and escaped block copies
>> are allocated as pages from a mempool, and they end up in the same bios
>> as the page cache buffers being journaled. The completion handler then
>> calls page_folio() on every segment to figure out which kind it is
>> looking at. That won't work once memdescs land and those pool pages are
>> no longer folios.
>>
>> Patch 1 moves these blocks over to a kmalloc mempool, with their own
>> bios and completion handler. As a result each descriptor block is now
>> submitted as its own bio, so patch 2 adds a plug around the log flush to
>> let the block layer merge them back together. Patch 3 cleans up the
>> leftover page references in the log code.
>>
>> Tested with fio 4K write+fsync on gfs2 over virtio-blk and null_blk.
>> Without an I/O scheduler, patch 1 adds one write request per log flush
>> (196.7k to 229.5k for 32k fsyncs) and ~10 us to the p99.9 fsync latency
>> on null_blk (41 us to 51 us); the plug in patch 2 merges them and
>> restores both performance numbers to the baseline. With mq-deadline
>> nothing changes.
> 
> thank you for these patches. Could you please rerun that test with a
> block size smaller than the page size?
> 
> Thanks,
> Andreas
> 

I ran it with a 1k block size on 4k pages, and the result is the same:

job (fsyncs)      sched        base      p1        p2
----------------  -----------  --------  --------  --------
fsync4k (32768)   none         199519    232296    199514
fsync64k (2048)   none          15445     17503     15441
create (2000)     none          12228     14234     12226
fsync4k (32768)   mq-deadline  199509    200016    199505

p99.9 latency results are also the same.

Thanks,
Tal


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] gfs2: stop using pages for log buffers
  2026-11-20  0:08   ` Andreas Gruenbacher
@ 2026-11-20 18:14     ` Tal Zussman
  0 siblings, 0 replies; 8+ messages in thread
From: Tal Zussman @ 2026-11-20 18:14 UTC (permalink / raw)
  To: Andreas Gruenbacher; +Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle)

On 11/19/26 7:08 PM, Andreas Gruenbacher wrote:
> On Tue, Nov 17, 2026 at 8:46 AM Tal Zussman <tz2294@columbia.edu> wrote:
>>
>> The log headers, descriptors, revoke blocks, and escaped block copies
>> come from a mempool of pages and share a bio with the buffer heads being
>> journaled. The completion handler tells the two apart by checking each
>> segment for buffers, which treats a pool page as a folio. That won't
>> work once memdescs give these pages a type of their own.
>>
>> Allocate them from a kmalloc mempool instead and add them to the bio
>> with bio_add_virt_nofail(). Give the pool blocks their own completion
>> handler, and start a new bio whenever the handler changes so that a bio
>> only holds one kind of segment. gfs2_log_write() now takes a folio, so
>> the log write path no longer uses struct page.
>>
>> Each descriptor and each escaped block copy is now a bio of its own.
>> They are contiguous and merge under an I/O scheduler, but the flush
>> path doesn't plug, so without a scheduler they reach the device as
>> separate writes.
>>
>> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
>> ---

...

>> diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
>> index a607e98eb45f..0da4cfbe54ea 100644
>> --- a/fs/gfs2/main.c
>> +++ b/fs/gfs2/main.c
>> @@ -166,8 +166,8 @@ static int __init init_gfs2_fs(void)
>>         if (!gfs2_freeze_wq)
>>                 goto fail_wq3;
>>
>> -       gfs2_page_pool = mempool_create_page_pool(64, 0);
>> -       if (!gfs2_page_pool)
>> +       gfs2_log_buf_pool = mempool_create_kmalloc_pool(64, PAGE_SIZE);
> 
> We actually need s_blocksize size rather than PAGE_SIZE buffers here.
> How about a per-sbd mempool instead of a global one?
> 

Let me give that a shot for v2.

Thanks,
Tal

>> +       if (!gfs2_log_buf_pool)
>>                 goto fail_mempool;
>>
>>         gfs2_register_debugfs();
>> @@ -187,7 +187,7 @@ static int __init init_gfs2_fs(void)
>>  fail_fs2:
>>         unregister_filesystem(&gfs2_fs_type);
>>  fail_fs1:
>> -       mempool_destroy(gfs2_page_pool);
>> +       mempool_destroy(gfs2_log_buf_pool);
>>  fail_mempool:
>>         destroy_workqueue(gfs2_freeze_wq);
>>  fail_wq3:
>> @@ -240,7 +240,7 @@ static void __exit exit_gfs2_fs(void)
>>
>>         rcu_barrier();
>>
>> -       mempool_destroy(gfs2_page_pool);
>> +       mempool_destroy(gfs2_log_buf_pool);
>>         kmem_cache_destroy(gfs2_trans_cachep);
>>         kmem_cache_destroy(gfs2_qadata_cachep);
>>         kmem_cache_destroy(gfs2_quotad_cachep);
>> diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
>> index 529c3ec37a18..1fd5f817312b 100644
>> --- a/fs/gfs2/util.c
>> +++ b/fs/gfs2/util.c
>> @@ -34,7 +34,7 @@ struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
>>  struct kmem_cache *gfs2_quotad_cachep __read_mostly;
>>  struct kmem_cache *gfs2_qadata_cachep __read_mostly;
>>  struct kmem_cache *gfs2_trans_cachep __read_mostly;
>> -mempool_t *gfs2_page_pool __read_mostly;
>> +mempool_t *gfs2_log_buf_pool __read_mostly;
>>
>>  void gfs2_assert_i(struct gfs2_sbd *sdp)
>>  {
>> diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h
>> index ffcc47d6b0b4..399c20004283 100644
>> --- a/fs/gfs2/util.h
>> +++ b/fs/gfs2/util.h
>> @@ -165,7 +165,7 @@ extern struct kmem_cache *gfs2_rgrpd_cachep;
>>  extern struct kmem_cache *gfs2_quotad_cachep;
>>  extern struct kmem_cache *gfs2_qadata_cachep;
>>  extern struct kmem_cache *gfs2_trans_cachep;
>> -extern mempool_t *gfs2_page_pool;
>> +extern mempool_t *gfs2_log_buf_pool;
>>  extern struct workqueue_struct *gfs2_control_wq;
>>
>>  static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
>>
>> --
>> 2.39.5
>>
> 
> Thanks,
> Andreas
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-20 18:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  7:46 [PATCH 0/3] gfs2: stop using struct page in the log code Tal Zussman
2026-11-17  7:46 ` [PATCH 1/3] gfs2: stop using pages for log buffers Tal Zussman
2026-11-20  0:08   ` Andreas Gruenbacher
2026-11-20 18:14     ` Tal Zussman
2026-11-17  7:46 ` [PATCH 2/3] gfs2: plug the log writes of a flush Tal Zussman
2026-11-17  7:46 ` [PATCH 3/3] gfs2: remove the remaining page references in the log code Tal Zussman
2026-11-19 23:47 ` [PATCH 0/3] gfs2: stop using struct page " Andreas Gruenbacher
2026-11-20 18:11   ` Tal Zussman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®