All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Carlos Maiolino <cem@kernel.org>,
	Dave Chinner <dchinner@redhat.com>,
	linux-xfs@vger.kernel.org, "Darrick J. Wong" <djwong@kernel.org>
Subject: Re: [PATCH 4/4] xfs: don't decrement the buffer LRU count for in-use buffers
Date: Mon, 23 Mar 2026 08:27:33 -0400	[thread overview]
Message-ID: <acExtTJynRQQ30dJ@bfoster> (raw)
In-Reply-To: <20260323075102.2952705-5-hch@lst.de>

On Mon, Mar 23, 2026 at 08:50:54AM +0100, Christoph Hellwig wrote:
> XFS buffers are added to the LRU when they are unused, but are only
> removed from the LRU lazily when the LRU list scan finds a used buffer.
> So far this only happen when the LRU counter hits 0, which is suboptimal
> as buffers that were added to the LRU, but are in use again still consume
> LRU scanning resources and are aged while actually in use.
> 
> Fix this by checking for in-use buffers and removing the from the LRU
> before decrementing the LRU counter.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/xfs_buf.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
> index e4b65d0c9ef0..ee8c3944015a 100644
> --- a/fs/xfs/xfs_buf.c
> +++ b/fs/xfs/xfs_buf.c
> @@ -1524,23 +1524,25 @@ xfs_buftarg_isolate(
>  		return LRU_SKIP;
>  
>  	/*
> -	 * Decrement the b_lru_ref count unless the value is already
> -	 * zero. If the value is already zero, we need to reclaim the
> -	 * buffer, otherwise it gets another trip through the LRU.
> +	 * If the buffer is in use, remove it from the LRU for now.  We can't
> +	 * free it while someone is using it, and we should also not count
> +	 * eviction passed for it, just as if it hadn't been added to the LRU
> +	 * yet.
>  	 */
> -	if (atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
> +	if (bp->b_lockref.count > 0) {
> +		list_lru_isolate(lru, &bp->b_lru);
>  		spin_unlock(&bp->b_lockref.lock);
> -		return LRU_ROTATE;
> +		return LRU_REMOVED;
>  	}
>  
>  	/*
> -	 * If the buffer is in use, remove it from the LRU for now as we can't
> -	 * free it.  It will be freed when the last reference drops.
> +	 * Decrement the b_lru_ref count unless the value is already
> +	 * zero. If the value is already zero, we need to reclaim the
> +	 * buffer, otherwise it gets another trip through the LRU.
>  	 */
> -	if (bp->b_lockref.count > 0) {
> -		list_lru_isolate(lru, &bp->b_lru);
> +	if (atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
>  		spin_unlock(&bp->b_lockref.lock);
> -		return LRU_REMOVED;
> +		return LRU_ROTATE;
>  	}
>  
>  	lockref_mark_dead(&bp->b_lockref);
> -- 
> 2.47.3
> 
> 


  reply	other threads:[~2026-03-23 12:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23  7:50 buffer cache simplification v6 Christoph Hellwig
2026-03-23  7:50 ` [PATCH 1/4] xfs: don't keep a reference for buffers on the LRU Christoph Hellwig
2026-03-23  7:50 ` [PATCH 2/4] xfs: use a lockref for the buffer reference count Christoph Hellwig
2026-03-23  7:50 ` [PATCH 3/4] xfs: switch (back) to a per-buftarg buffer hash Christoph Hellwig
2026-03-23 12:27   ` Brian Foster
2026-03-23  7:50 ` [PATCH 4/4] xfs: don't decrement the buffer LRU count for in-use buffers Christoph Hellwig
2026-03-23 12:27   ` Brian Foster [this message]
2026-03-30 15:10 ` buffer cache simplification v6 Carlos Maiolino
  -- strict thread matches above, loose matches on Subject: below --
2026-03-17 13:40 buffer cache simplification v5 Christoph Hellwig
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

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=acExtTJynRQQ30dJ@bfoster \
    --to=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.