From: Christoph Hellwig <hch@lst.de>
To: Carlos Maiolino <cem@kernel.org>
Cc: "Darrick J. Wong" <djwong@kernel.org>, linux-xfs@vger.kernel.org
Subject: [PATCH 01/12] xfs: don't get a pag reference in xfs_buf_get_map
Date: Wed, 15 Jul 2026 16:50:54 +0200 [thread overview]
Message-ID: <20260715145147.95654-2-hch@lst.de> (raw)
In-Reply-To: <20260715145147.95654-1-hch@lst.de>
As of commit 497560b9ef42 ("xfs: switch (back) to a per-buftarg buffer
hash"), buffer lookups don't require the perag structure. Stop looking
it up in xfs_buf_get_map, and instead only find it when allocating a new
buffer.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/xfs/xfs_buf.c | 44 ++++++++++----------------------------------
1 file changed, 10 insertions(+), 34 deletions(-)
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index e1465e950acc..54e091315d56 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -469,7 +469,6 @@ xfs_buf_lookup(
static int
xfs_buf_find_insert(
struct xfs_buftarg *btp,
- struct xfs_perag *pag,
struct xfs_buf_map *cmap,
struct xfs_buf_map *map,
int nmaps,
@@ -482,10 +481,13 @@ xfs_buf_find_insert(
error = xfs_buf_alloc(btp, map, nmaps, flags, &new_bp);
if (error)
- goto out_drop_pag;
+ return error;
/* The new buffer keeps the perag reference until it is freed. */
- new_bp->b_pag = pag;
+ if (!xfs_buftarg_is_mem(btp)) {
+ new_bp->b_pag = xfs_perag_get(btp->bt_mount,
+ xfs_daddr_to_agno(btp->bt_mount, cmap->bm_bn));
+ }
retry:
rcu_read_lock();
@@ -520,25 +522,12 @@ xfs_buf_find_insert(
return 0;
out_free_buf:
+ if (new_bp->b_pag)
+ xfs_perag_put(new_bp->b_pag);
xfs_buf_free(new_bp);
-out_drop_pag:
- if (pag)
- xfs_perag_put(pag);
return error;
}
-static inline struct xfs_perag *
-xfs_buftarg_get_pag(
- struct xfs_buftarg *btp,
- const struct xfs_buf_map *map)
-{
- struct xfs_mount *mp = btp->bt_mount;
-
- if (xfs_buftarg_is_mem(btp))
- return NULL;
- return xfs_perag_get(mp, xfs_daddr_to_agno(mp, map->bm_bn));
-}
-
/*
* Assembles a buffer covering the specified range. The code is optimised for
* cache hits, as metadata intensive workloads will see 3 orders of magnitude
@@ -552,7 +541,6 @@ xfs_buf_get_map(
xfs_buf_flags_t flags,
struct xfs_buf **bpp)
{
- struct xfs_perag *pag;
struct xfs_buf *bp = NULL;
struct xfs_buf_map cmap = { .bm_bn = map[0].bm_bn };
int error;
@@ -567,28 +555,21 @@ xfs_buf_get_map(
if (error)
return error;
- pag = xfs_buftarg_get_pag(btp, &cmap);
-
error = xfs_buf_lookup(btp, &cmap, flags, &bp);
if (error && error != -ENOENT)
- goto out_put_perag;
+ return error;
/* cache hits always outnumber misses by at least 10:1 */
if (unlikely(!bp)) {
XFS_STATS_INC(btp->bt_mount, xb_miss_locked);
if (flags & XBF_INCORE)
- goto out_put_perag;
-
- /* xfs_buf_find_insert() consumes the perag reference. */
- error = xfs_buf_find_insert(btp, pag, &cmap, map, nmaps,
- flags, &bp);
+ return 0;
+ error = xfs_buf_find_insert(btp, &cmap, map, nmaps, flags, &bp);
if (error)
return error;
} else {
XFS_STATS_INC(btp->bt_mount, xb_get_locked);
- if (pag)
- xfs_perag_put(pag);
}
/*
@@ -602,11 +583,6 @@ xfs_buf_get_map(
trace_xfs_buf_get(bp, flags, _RET_IP_);
*bpp = bp;
return 0;
-
-out_put_perag:
- if (pag)
- xfs_perag_put(pag);
- return error;
}
int
--
2.53.0
next prev parent reply other threads:[~2026-07-15 14:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 14:50 misc buffer cache improvements Christoph Hellwig
2026-07-15 14:50 ` Christoph Hellwig [this message]
2026-07-15 14:50 ` [PATCH 02/12] xfs: consolidate buffer locking in xfs_buf_get_map Christoph Hellwig
2026-07-15 14:50 ` [PATCH 03/12] xfs: split out a lower-level xfs_buf_get_map helper from xfs_find_get_buf Christoph Hellwig
2026-07-15 14:50 ` [PATCH 04/12] xfs: remove spurious XBF_DONE clearing on readahead validation failure Christoph Hellwig
2026-07-15 14:50 ` [PATCH 05/12] xfs: remove _XBF_LOGRECOVERY Christoph Hellwig
2026-07-15 14:50 ` [PATCH 06/12] xfs: hide b_flags manipulation from code outside of xfs_buf.c Christoph Hellwig
2026-07-15 14:51 ` [PATCH 07/12] xfs: use WRITE_ONCE to update b_flags Christoph Hellwig
2026-07-15 14:51 ` [PATCH 08/12] xfs: don't reverify buffers in xfs_buf_readahead_map Christoph Hellwig
2026-07-15 14:51 ` [PATCH 09/12] xfs: use goto based error unwinding in xfs_buf_read_map Christoph Hellwig
2026-07-15 14:51 ` [PATCH 10/12] xfs: merge xfs_buf_reverify into xfs_buf_read_map Christoph Hellwig
2026-07-15 14:51 ` [PATCH 11/12] xfs: move buffer locking out of xfs_find_get_buf Christoph Hellwig
2026-07-15 14:51 ` [PATCH 12/12] xfs: add lockless xfs_buf_readahead_map fast path Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260715145147.95654-2-hch@lst.de \
--to=hch@lst.de \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox