[PATCH v2 1/4] gfs2: make the log page pool per superblock
From: Tal Zussman
Date: Tue Nov 24 2026 - 16:04:38 EST
The log headers, descriptors, revoke blocks, and escaped block copies
come from gfs2_page_pool, a single mempool shared by every mounted
filesystem. Give each superblock a pool of its own, sd_log_buf_pool. A
per-superblock pool can hold buffers of the filesystem's block size,
which a global one cannot.
The pool is set up in gfs2_fill_super() once the superblock has been
read and is destroyed in free_sbd(). Its elements are still pages, so
each mount now reserves 64 pages of its own.
Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/gfs2/incore.h | 2 ++
fs/gfs2/log.c | 2 +-
fs/gfs2/lops.c | 10 +++++-----
fs/gfs2/main.c | 8 --------
fs/gfs2/ops_fstype.c | 5 +++++
fs/gfs2/util.c | 1 -
fs/gfs2/util.h | 3 ---
7 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 1ff19f87d3bd..60748b99d39a 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -21,6 +21,7 @@
#include <linux/lockref.h>
#include <linux/rhashtable.h>
#include <linux/mutex.h>
+#include <linux/mempool.h>
#define DIO_WAIT 0x00000010
#define DIO_METADATA 0x00000020
@@ -846,6 +847,7 @@ struct gfs2_sbd {
struct rw_semaphore sd_log_flush_lock;
atomic_t sd_log_in_flight;
wait_queue_head_t sd_log_flush_wait;
+ mempool_t sd_log_buf_pool;
int sd_log_error; /* First log error */
unsigned int sd_log_tail;
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 1baaaf30c4fa..e7076db3ba46 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -850,7 +850,7 @@ 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);
+ page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
lh = page_address(page);
clear_page(lh);
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 657edd406dd1..7a2c29652fec 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -229,7 +229,7 @@ static void gfs2_end_log_write(struct bio *bio)
gfs2_end_log_write_bh(sdp, folio, bvec->bv_offset,
bvec->bv_len, bio->bi_status);
else
- mempool_free(page, gfs2_page_pool);
+ mempool_free(page, &sdp->sd_log_buf_pool);
}
bio_put(bio);
@@ -377,7 +377,7 @@ static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
* @page: The struct page
*
* 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
+ * that the page must have been allocated from the sd_log_buf_pool mempool
* and that after this has been called, ownership has been transferred and
* the page may be freed at any time.
*/
@@ -607,7 +607,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
static struct page *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 page *page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
struct gfs2_log_descriptor *ld = page_address(page);
clear_page(ld);
ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
@@ -696,7 +696,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);
+ page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
p = page_address(page);
memcpy_from_folio(p, bd2->bd_bh->b_folio,
bh_offset(bd2->bd_bh),
@@ -872,7 +872,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
if (offset + sizeof(u64) > sdp->sd_sb.sb_bsize) {
gfs2_log_write_page(sdp, page);
- page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
+ page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
mh = page_address(page);
clear_page(mh);
mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index a607e98eb45f..8a45b2e9b618 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -16,7 +16,6 @@
#include <linux/rcupdate.h>
#include <linux/rculist_bl.h>
#include <linux/atomic.h>
-#include <linux/mempool.h>
#include "gfs2.h"
#include "incore.h"
@@ -166,10 +165,6 @@ 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)
- goto fail_mempool;
-
gfs2_register_debugfs();
error = register_filesystem(&gfs2_fs_type);
if (error)
@@ -187,8 +182,6 @@ static int __init init_gfs2_fs(void)
fail_fs2:
unregister_filesystem(&gfs2_fs_type);
fail_fs1:
- mempool_destroy(gfs2_page_pool);
-fail_mempool:
destroy_workqueue(gfs2_freeze_wq);
fail_wq3:
destroy_workqueue(gfs2_control_wq);
@@ -240,7 +233,6 @@ static void __exit exit_gfs2_fs(void)
rcu_barrier();
- mempool_destroy(gfs2_page_pool);
kmem_cache_destroy(gfs2_trans_cachep);
kmem_cache_destroy(gfs2_qadata_cachep);
kmem_cache_destroy(gfs2_quotad_cachep);
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 6ec47376aecf..f62a893ce5a2 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -67,6 +67,7 @@ void free_sbd(struct gfs2_sbd *sdp)
{
struct super_block *sb = sdp->sd_vfs;
+ mempool_exit(&sdp->sd_log_buf_pool);
free_percpu(sdp->sd_lkstats);
sb->s_fs_info = NULL;
kfree(sdp);
@@ -1218,6 +1219,10 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
if (error)
goto fail_locking;
+ error = mempool_init_page_pool(&sdp->sd_log_buf_pool, 64, 0);
+ if (error)
+ goto fail_sb;
+
/* Turn rgrplvb on by default if fs format is recent enough */
if (!sdp->sd_args.ar_got_rgrplvb && sdp->sd_sb.sb_fs_format > 1801)
sdp->sd_args.ar_rgrplvb = 1;
diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
index 529c3ec37a18..d42db8a9f5aa 100644
--- a/fs/gfs2/util.c
+++ b/fs/gfs2/util.c
@@ -34,7 +34,6 @@ 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;
void gfs2_assert_i(struct gfs2_sbd *sdp)
{
diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h
index ffcc47d6b0b4..0179ddcd4c22 100644
--- a/fs/gfs2/util.h
+++ b/fs/gfs2/util.h
@@ -12,8 +12,6 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#endif
-#include <linux/mempool.h>
-
#include "incore.h"
#define fs_emerg(fs, fmt, ...) \
@@ -165,7 +163,6 @@ 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 struct workqueue_struct *gfs2_control_wq;
static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
--
2.39.5