diff mbox series

[4/5] xfs: reduce the number of atomic when locking a buffer after lookup

Message ID 20220403120119.235457-5-hch@lst.de (mailing list archive)
State Superseded
Headers show
Series [1/5] xfs: add a flags argument to xfs_buf_get | expand

Commit Message

Christoph Hellwig April 3, 2022, 12:01 p.m. UTC
From: Dave Chinner <dchinner@redhat.com>

Avoid an extra atomic operation in the non-trylock case by only doing a
trylock if the XBF_TRYLOCK flag is set. This follows the pattern in the
IO path with NOWAIT semantics where the "trylock-fail-lock" path showed
5-10% reduced throughput compared to just using single lock call when not
under NOWAIT conditions. So make that same change here, too.

See commit 942491c9e6d6 ("xfs: fix AIM7 regression") for details.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
[hch: split from a larger patch]
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_buf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index ef645e15935369..dd68aee52118c2 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -636,12 +636,13 @@  xfs_buf_get_map(
 	}
 	xfs_perag_put(pag);
 
-	if (!xfs_buf_trylock(bp)) {
-		if (flags & XBF_TRYLOCK) {
+	if (flags & XBF_TRYLOCK) {
+		if (!xfs_buf_trylock(bp)) {
 			xfs_buf_rele(bp);
 			XFS_STATS_INC(mp, xb_busy_locked);
 			return -EAGAIN;
 		}
+	} else {
 		xfs_buf_lock(bp);
 		XFS_STATS_INC(mp, xb_get_locked_waited);
 	}