[PATCH 2/3] jfs: allocate the log buffers with kmalloc()

From: Tal Zussman

Date: Tue Nov 17 2026 - 01:57:11 EST


The log buffers aren't in the page cache, so they don't need a struct
page. lbmLogInit() currently allocates whole pages, splits each one into
LOGPSIZE lbufs and takes a page reference for each.

Allocate each lbuf's buffer with kzalloc() instead and add it to the bio
with bio_add_virt_nofail(). LOGPSIZE is a power of two, so the buffer is
naturally aligned. This removes l_page and l_offset from struct lbuf.

Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/jfs/jfs_logmgr.c | 45 ++++++++++++++++-----------------------------
fs/jfs/jfs_logmgr.h | 2 --
2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 306165e61438..ad77fdf56149 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1795,7 +1795,7 @@ static int lbmLogInit(struct jfs_log * log)
log->wqueue = NULL;

/*
- * Each log has its own buffer pages allocated to it. These are
+ * Each log has its own buffers allocated to it. These are
* not managed by the page cache. This ensures that a transaction
* writing to the log does not block trying to allocate a page from
* the page cache (for the log). This would be bad, since page
@@ -1807,33 +1807,20 @@ static int lbmLogInit(struct jfs_log * log)

log->lbuf_free = NULL;

- for (i = 0; i < LOGPAGES;) {
- char *buffer;
- uint offset;
- struct page *page = alloc_page(GFP_KERNEL | __GFP_ZERO);
-
- if (!page)
+ for (i = 0; i < LOGPAGES; i++) {
+ lbuf = kmalloc_obj(struct lbuf);
+ if (lbuf == NULL)
+ goto error;
+ lbuf->l_ldata = kzalloc(LOGPSIZE, GFP_KERNEL);
+ if (lbuf->l_ldata == NULL) {
+ kfree(lbuf);
goto error;
- buffer = page_address(page);
- for (offset = 0; offset < PAGE_SIZE; offset += LOGPSIZE) {
- lbuf = kmalloc_obj(struct lbuf);
- if (lbuf == NULL) {
- if (offset == 0)
- __free_page(page);
- goto error;
- }
- if (offset) /* we already have one reference */
- get_page(page);
- lbuf->l_offset = offset;
- lbuf->l_ldata = buffer + offset;
- lbuf->l_page = page;
- lbuf->l_log = log;
- init_waitqueue_head(&lbuf->l_ioevent);
-
- lbuf->l_freelist = log->lbuf_free;
- log->lbuf_free = lbuf;
- i++;
}
+ lbuf->l_log = log;
+ init_waitqueue_head(&lbuf->l_ioevent);
+
+ lbuf->l_freelist = log->lbuf_free;
+ log->lbuf_free = lbuf;
}

return (0);
@@ -1858,7 +1845,7 @@ static void lbmLogShutdown(struct jfs_log * log)
lbuf = log->lbuf_free;
while (lbuf) {
struct lbuf *next = lbuf->l_freelist;
- __free_page(lbuf->l_page);
+ kfree(lbuf->l_ldata);
kfree(lbuf);
lbuf = next;
}
@@ -1971,7 +1958,7 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp)

bio = bio_alloc(file_bdev(log->bdev_file), 1, REQ_OP_READ, GFP_NOFS);
bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
- __bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
+ bio_add_virt_nofail(bio, bp->l_ldata, LOGPSIZE);
BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);

bio->bi_end_io = lbmIODone;
@@ -2117,7 +2104,7 @@ static void lbmStartIO(struct lbuf * bp)
bio = bio_alloc(bdev, 1, REQ_OP_WRITE | REQ_SYNC,
GFP_NOFS);
bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
- __bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
+ bio_add_virt_nofail(bio, bp->l_ldata, LOGPSIZE);
BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);

bio->bi_end_io = lbmIODone;
diff --git a/fs/jfs/jfs_logmgr.h b/fs/jfs/jfs_logmgr.h
index 09e0ef6aecce..e8f43c25deb6 100644
--- a/fs/jfs/jfs_logmgr.h
+++ b/fs/jfs/jfs_logmgr.h
@@ -455,8 +455,6 @@ struct lbuf {

s64 l_blkno; /* 8: log page block number */
caddr_t l_ldata; /* 4: data page */
- struct page *l_page; /* The page itself */
- uint l_offset; /* Offset of l_ldata within the page */

wait_queue_head_t l_ioevent; /* 4: i/o done event */
};

--
2.39.5