From 8166876aadef90744bb26addc9c5a16b1c8341b5 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Mon, 23 Mar 2026 08:50:54 +0100 Subject: [PATCH] xfs: don't decrement the buffer LRU count for in-use buffers 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 Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- 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 @@ -1523,6 +1523,18 @@ xfs_buftarg_isolate( if (!spin_trylock(&bp->b_lockref.lock)) return LRU_SKIP; + /* + * 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 (bp->b_lockref.count > 0) { + list_lru_isolate(lru, &bp->b_lru); + spin_unlock(&bp->b_lockref.lock); + return LRU_REMOVED; + } + /* * Decrement the b_lru_ref count unless the value is already * zero. If the value is already zero, we need to reclaim the @@ -1533,16 +1545,6 @@ xfs_buftarg_isolate( return LRU_ROTATE; } - /* - * 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. - */ - if (bp->b_lockref.count > 0) { - list_lru_isolate(lru, &bp->b_lru); - spin_unlock(&bp->b_lockref.lock); - return LRU_REMOVED; - } - lockref_mark_dead(&bp->b_lockref); list_lru_isolate_move(lru, item, dispose); spin_unlock(&bp->b_lockref.lock);