From: Dave Chinner <dgc@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Carlos Maiolino <cem@kernel.org>,
Dave Chinner <dchinner@redhat.com>,
Brian Foster <bfoster@redhat.com>,
linux-xfs@vger.kernel.org, "Darrick J. Wong" <djwong@kernel.org>
Subject: Re: [PATCH 2/4] xfs: use a lockref for the buffer reference count
Date: Wed, 18 Mar 2026 08:53:13 +1100 [thread overview]
Message-ID: <abnNSZy-N8ITNKul@dread> (raw)
In-Reply-To: <20260317134110.1691097-3-hch@lst.de>
On Tue, Mar 17, 2026 at 02:40:53PM +0100, Christoph Hellwig wrote:
> The lockref structure allows incrementing/decrementing counters like
> an atomic_t for the fast path, while still allowing complex slow path
> operations as if the counter was protected by a lock. The only slow
> path operations that actually need to take the lock are the final
> put, LRU evictions and marking a buffer stale.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Seems straight forward enough, even if it is more verbose...
> @@ -853,16 +837,14 @@ xfs_buf_hold(
> {
> trace_xfs_buf_hold(bp, _RET_IP_);
>
> - spin_lock(&bp->b_lock);
> - bp->b_hold++;
> - spin_unlock(&bp->b_lock);
> + lockref_get(&bp->b_lockref);
> }
Can we make xfs_buf_hold a static inline in xfs_buf.h now? It is
called quite frequently and it's now just a one line wrapper
around the lockref code...
> @@ -1564,10 +1547,10 @@ xfs_buftarg_isolate(
> struct list_head *dispose = arg;
>
> /*
> - * We are inverting the lru lock vs bp->b_lock order here, so use a
> - * trylock. If we fail to get the lock, just skip the buffer.
> + * We are inverting the lru lock vs bp->b_lockref.lock order here, so
> + * use a trylock. If we fail to get the lock, just skip the buffer.
> */
> - if (!spin_trylock(&bp->b_lock))
> + if (!spin_trylock(&bp->b_lockref.lock))
> return LRU_SKIP;
>
> /*
You modify this comment and whitespace in the previous patch without
any code change, and then do it again in this patch with a code
change. Can you collapse that just into a single change in this
patch with the code change?
> diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h
> index e7324d58bd96..3a1d066e1c13 100644
> --- a/fs/xfs/xfs_buf.h
> +++ b/fs/xfs/xfs_buf.h
> @@ -14,6 +14,7 @@
> #include <linux/dax.h>
> #include <linux/uio.h>
> #include <linux/list_lru.h>
> +#include <linux/lockref.h>
>
> extern struct kmem_cache *xfs_buf_cache;
>
> @@ -154,7 +155,7 @@ struct xfs_buf {
>
> xfs_daddr_t b_rhash_key; /* buffer cache index */
> int b_length; /* size of buffer in BBs */
> - int b_hold; /* reference count */
> + struct lockref b_lockref; /* refcount + lock */
> atomic_t b_lru_ref; /* lru reclaim ref count */
IIUC, this adds a 4 byte hole to the structure - b_lockref is an aligned
u64...
> xfs_buf_flags_t b_flags; /* status flags */
And we end up with another 4 byte hole here because...
> struct semaphore b_sema; /* semaphore for lockables */
the struct semaphore also ends up being u64 aligned...
The first cacheline of the xfs_buf is explicitly packed
packed with the fields that a hash lookup needs to
minimise cacheline misses during lookup, so we really don't want to
screw that up by wasting space in the first cacheline.
Indeed, seeing as we've simplified the structure of the cache index
over time and are moving back to a global cache index, we probably
need to take another look at exactly where the cacheline boundary
sits and exactly what the lockless lookup fast path accesses. i.e.
make sure that lookups only access the first cacheline, and there is
nothing on that first cacheline that any other concurrent buffer
access might contend on (e.g. lru list scanning, wait queues, pure
read-only accesses, etc.)
Otherwise, the code change looks ok.
-Dave.
--
Dave Chinner
dgc@kernel.org
next prev parent reply other threads:[~2026-03-17 21:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 13:40 buffer cache simplification v5 Christoph Hellwig
2026-03-17 13:40 ` [PATCH 1/4] xfs: don't keep a reference for buffers on the LRU Christoph Hellwig
2026-03-17 21:33 ` Dave Chinner
2026-03-18 14:38 ` Christoph Hellwig
2026-03-18 11:44 ` Brian Foster
2026-03-17 13:40 ` [PATCH 2/4] xfs: use a lockref for the buffer reference count Christoph Hellwig
2026-03-17 21:53 ` Dave Chinner [this message]
2026-03-18 14:49 ` Christoph Hellwig
2026-03-17 13:40 ` [PATCH 3/4] xfs: switch (back) to a per-buftarg buffer hash Christoph Hellwig
2026-03-17 22:00 ` Dave Chinner
2026-03-18 12:14 ` Brian Foster
2026-03-17 13:40 ` [PATCH 4/4] xfs: don't decrement the buffer LRU count for in-use buffers Christoph Hellwig
2026-03-17 22:06 ` Dave Chinner
2026-03-18 11:47 ` Brian Foster
2026-03-18 11:45 ` Brian Foster
-- strict thread matches above, loose matches on Subject: below --
2026-03-23 7:50 buffer cache simplification v6 Christoph Hellwig
2026-03-23 7:50 ` [PATCH 2/4] xfs: use a lockref for the buffer reference count 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=abnNSZy-N8ITNKul@dread \
--to=dgc@kernel.org \
--cc=bfoster@redhat.com \
--cc=cem@kernel.org \
--cc=dchinner@redhat.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--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