From nobody Tue May 21 18:16:47 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VkN1X2Gfvz5Lxd7; Tue, 21 May 2024 18:16:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VkN1W6G5vz4vwt; Tue, 21 May 2024 18:16:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716315407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AUwto1QTfsO7yUOZKRNcaN8x7Tq/szRkWCAcFJCVcI0=; b=pc74PIPaekZ0gLVAho2WN8KBMIOswr4ye5MWYmRDHvLCdWzJBPPy0Zpc94dVMkUKkHtWud M2QOd+QT4sUDFzohbuof584iTTac8Si8rd3TnheNUVB4VTSpJR11YH+20txEUJ24qZEAGb yfhEIG72+hXbVlmVJ16CqUKPYQXztsT1GC5qEMtHH9KQ4sfvkML/OFMq7rAyuOcHXXGWad jwYnyNXHNHSQztGxGsIe7ryuotkJU6j2jxrEN+59EHU6mPPIwIzN1FSPIH65bF7+zLiLGa yU3kYOw9nR9JBoUIorGTHZSQnqEkcYuBzBCqWBMDdIIxfCkcE/bXK7ROidLsTw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716315407; a=rsa-sha256; cv=none; b=raiBRR4BpQuF7WYl7p3FMpoTgyqWQ1C8RxOAA2s2cqnW55SJkEX4NEL4+SmN6G9HBQtc8v 0yaPBfv2RBpZuS66E7oDddCZM6aH0l3wEmu6dN1zWthwhi/74vkTusKjZWNnc2IuiSsWw7 iAQVpboy01DqAjWKAw03EiI+9yhmlMwrXYYaMNN0bUn8pLQMK+vfkYrA2I8ZKNnoNpDTBH 2Smjomv2gRXwAWlAHxlXHsfAY9I574GbsCqPVIAko1qsnXII4AUSyb8sUQBOmCBB01DE7a +u3erVtUjYdLslWlzIR5qjOhWcG6ZAW0nl+mLW6bMnvOhcALJ7FvrcDPv0waxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716315407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AUwto1QTfsO7yUOZKRNcaN8x7Tq/szRkWCAcFJCVcI0=; b=PLOBJo6bwUwYLCMr8wpoaNakVQOLvnibogSQeM2bDA912J5NfoZ9vM/Xnzpymnz0YxrMjy UGOwbstzdZl/Crjg0MWq0k1kEMG4kq1MumNfyv5+WzBRORhiOuANzNfgjF+1DyLxv2dBKH ehTK6SpcVr7ZoMb3UPedsy7yH3sh2M/nefKsM+7JT88AHddtIP7UT/nqh+USWeKb54W4Rl lT8rtzAz887uLCUkn7Q+djUk8M8WQrAIqkEgDyPw7l5JHfntF9PKTwx3fTGxKpxoDZczbV BT/ICuDpOMLezhomd57MuK5GlUYoiNqVsjKOTkPq2SDDl0GLN8DTEPnFhNT3BQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VkN1W5szxzXtv; Tue, 21 May 2024 18:16:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44LIGlaZ056242; Tue, 21 May 2024 18:16:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44LIGlT6056239; Tue, 21 May 2024 18:16:47 GMT (envelope-from git) Date: Tue, 21 May 2024 18:16:47 GMT Message-Id: <202405211816.44LIGlT6056239@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ryan Libby Subject: git: a332ba32d4a2 - main - getblk: fail faster with GB_LOCK_NOWAIT List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rlibby X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a332ba32d4a26e20c959db14afa11ccfa25cf76c Auto-Submitted: auto-generated The branch main has been updated by rlibby: URL: https://cgit.FreeBSD.org/src/commit/?id=a332ba32d4a26e20c959db14afa11ccfa25cf76c commit a332ba32d4a26e20c959db14afa11ccfa25cf76c Author: Ryan Libby AuthorDate: 2024-05-21 17:21:50 +0000 Commit: Ryan Libby CommitDate: 2024-05-21 17:21:50 +0000 getblk: fail faster with GB_LOCK_NOWAIT If we asked not to wait on a lock, and then we failed to get a buf lock because we would have had to wait, then just return the error. This avoids taking the bufobj lock and a second trip to lockmgr. Reviewed by: mckusick, kib, markj Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D45245 --- sys/kern/vfs_bio.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index b5466fb2cd53..01057072d991 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -4010,8 +4010,23 @@ getblkx(struct vnode *vp, daddr_t blkno, daddr_t dblkno, int size, int slpflag, error = BUF_TIMELOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL, "getblku", 0, 0); - if (error != 0) + if (error != 0) { + KASSERT(error == EBUSY, + ("getblk: unexpected error %d from buf try-lock", error)); + /* + * We failed a buf try-lock. + * + * With GB_LOCK_NOWAIT, just return, rather than taking the + * bufobj interlock and trying again, since we would probably + * fail again anyway. This is okay even if the buf's identity + * changed and we contended on the wrong lock, as changing + * identity itself requires the buf lock, and we could have + * contended on the right lock. + */ + if ((flags & GB_LOCK_NOWAIT) != 0) + return (error); goto loop; + } /* Verify buf identify has not changed since lookup. */ if (bp->b_bufobj == bo && bp->b_lblkno == blkno) @@ -4020,6 +4035,10 @@ getblkx(struct vnode *vp, daddr_t blkno, daddr_t dblkno, int size, int slpflag, /* It changed, fallback to locked lookup. */ BUF_UNLOCK_RAW(bp); + /* As above, with GB_LOCK_NOWAIT, just return. */ + if ((flags & GB_LOCK_NOWAIT) != 0) + return (EBUSY); + loop: BO_RLOCK(bo); bp = gbincore(bo, blkno);