Re: [PATCH 12/12] xfs: add lockless xfs_buf_readahead_map fast path
"Darrick J. Wong" <[email protected]>
| Newsgroups | org.kernel.vger.linux-xfs |
|---|---|
| Message-ID | <20260724170316.GZ2901224@frogsfrogsfrogs> |
On Wed, Jul 15, 2026 at 04:51:05PM +0200, Christoph Hellwig wrote: > Readahead currently always locks the buffer, which can cause contention > with actual users of the buffer. Add a fast path without taking any > locks if the buffer is uptodate and not stale. So we're trying to cut down on b_sema contention for detecting the case where the buffer is already uptodate? And I guess the idea here is that if you had per-fsblock filesystem metadata, you'd want to be able to readahead that metadata into memory during setup for file IO without so much locking? Sounds reasonable to me... Reviewed-by: "Darrick J. Wong" <[email protected]> --D > Signed-off-by: Christoph Hellwig <[email protected]> > --- > fs/xfs/xfs_buf.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c > index f5701f74061f..2e498e9e05e9 100644 > --- a/fs/xfs/xfs_buf.c > +++ b/fs/xfs/xfs_buf.c > @@ -756,13 +756,23 @@ xfs_buf_readahead_map( > > if (xfs_find_get_buf(target, map, nmaps, flags, &bp)) > return; > - if (xfs_buf_find_lock(bp, XBF_TRYLOCK)) > + > + /* > + * Do a lockless fast path check for a valid uptodate buffer and avoid > + * locking entirely in this case. > + */ > + if ((READ_ONCE(bp->b_flags) & (XBF_DONE | XBF_STALE)) == XBF_DONE) > goto out_rele; > > - trace_xfs_buf_readahead(bp, 0, _RET_IP_); > - if (bp->b_flags & XBF_DONE) > + /* Otherwise lock the buffer to stabilize the state */ > + if (!xfs_buf_trylock(bp)) > + goto out_rele; > + > + /* Let the actual reader deal with stale buffers. */ > + if (bp->b_flags & (XBF_STALE | XBF_DONE)) > goto out_unlock; > > + trace_xfs_buf_readahead(bp, 0, _RET_IP_); > XFS_STATS_INC(target->bt_mount, xb_get_read); > bp->b_ops = ops; > xfs_buf_clear_flags(bp, XBF_WRITE | XBF_DONE); > -- > 2.53.0 > >