From nobody Mon Oct 14 17:12:21 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 4XS3gn4QTzz5Ys6k; Mon, 14 Oct 2024 17:12:21 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XS3gn3v7Zz4c5r; Mon, 14 Oct 2024 17:12:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728925941; 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=Vsat7//Eu0EOsx/DKRx7WYYFpcFXrhoZ+kRorlIFnpc=; b=cHj5lBlmd3E5txNHRLQd8RWRx62n1kIsTYkSDBTmUexYVqSmBS9MYhNjLkMu6IwLa0OJPi cYBvop+Y2QOXCmyX1oZiQdCfz1CNiHsC5LU1+8mVeXeeDSU/RnpZduVsPZPChV6TF22WSK ASM6FBpH73fkQCHGwY2iYkCgL5opP5c9F0HhLpj3rfGl1zzG4hX5haQ6U1LWDwNtzUlqNZ qWZ1sQA1/aoheDi/n4adUGoA9+b12cxFMP3iVG0bRjJ/qnrEYkLnCKbCRIb9EhdM1eO6Cq a7RfM70mOC+cFX6XkHu0vpJEzKqx917xrJsRF4KbPTVmZiEPRJ6DDSiZ/OIyIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728925941; 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=Vsat7//Eu0EOsx/DKRx7WYYFpcFXrhoZ+kRorlIFnpc=; b=sjKV4JDIG3OCFmwAW2W9CSD3OzmmVHsWktHaTR7lLUoI9VCi5S9JrX5wEWqd8gDtfeeRwG 4SDj6HV0gokEhTQn7FmKL8zWIuy8uVrZBP6cJFq3WV4O2aVmLDRahOk6kyxCr2b6jYRe5H B2YMGh1jBXAGw3kvEtvShwBapvr+hPEJhH7FB49tG1gYf96qZNzLSEPRp01FXYUrKw/azi Oy1iXL1sRNJHQlAEZD4JwQIFOICsZciZ58jgkZz0mpHq9sOLBy6jaPxRi3PemowOujT2xW YDEJ8bhU93pXHLWeCailL4dNqH5WesDsFlgr+cjOWEjqMpGn/PO9HqLgCXNrfA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728925941; a=rsa-sha256; cv=none; b=h3PVgFIvwXKLyXK4bLhP3EbKJPXZ4r9AAACdRSb4PsvZ+lG5dSQKYHOlETAlanzcHGFcxO ezvrVcAhDVl8Hesp5aTJyVKbXjZ2HNMJCFgkzDAwD4i8xKv2si4xsIQZa9guwDhXqyLdve ovvNFrBaZN9krtpEVVuO8NfCevOU1vrd1LKuAYmTY+bhSRUxNA7sSfDWrK+SAVfVSnjCVC dZmZ3swV7iw85F8xSn2Nf9q/jMw7YLLwj7iH8QkdBsh1g8iU1ECdsw9CZ1Dky8MvBUcCu8 285GpGFrsx+qmD4nU866hDYla1g2N24s7f2wZXFUw6fhr9uBEQgOFaNg7YRq6w== 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 4XS3gn3VcgzmN9; Mon, 14 Oct 2024 17:12:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49EHCL63064274; Mon, 14 Oct 2024 17:12:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49EHCL6e064271; Mon, 14 Oct 2024 17:12:21 GMT (envelope-from git) Date: Mon, 14 Oct 2024 17:12:21 GMT Message-Id: <202410141712.49EHCL6e064271@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: 2c8caa4b3925 - main - vfs_subr: optimize inval_buf_range 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: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2c8caa4b3925aa73350d687cd13876c275f35889 Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=2c8caa4b3925aa73350d687cd13876c275f35889 commit 2c8caa4b3925aa73350d687cd13876c275f35889 Author: Doug Moore AuthorDate: 2024-10-14 17:07:59 +0000 Commit: Doug Moore CommitDate: 2024-10-14 17:07:59 +0000 vfs_subr: optimize inval_buf_range Use a pctrie_lookup to avoid walking over low out-of-range buf list entries, and an early break to avoid the high out-of-range entries. Avoid writing almost identical loops for the dirty and clean lists. Because pctries are built for unsigned keys, and these are signed values, handle the wraparound problem the same way that bnoreuselist() does. Reviewed by: kib Tested by: pho Differential Revision: https://reviews.freebsd.org/D46963 --- sys/kern/vfs_subr.c | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index f192c6798858..ff18c50546dd 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -2616,17 +2616,25 @@ static int v_inval_buf_range_locked(struct vnode *vp, struct bufobj *bo, daddr_t startlbn, daddr_t endlbn) { + struct bufv *bv; struct buf *bp, *nbp; - bool anyfreed; + uint8_t anyfreed; + bool clean; ASSERT_VOP_LOCKED(vp, "v_inval_buf_range_locked"); ASSERT_BO_LOCKED(bo); + anyfreed = 1; + clean = true; do { - anyfreed = false; - TAILQ_FOREACH_SAFE(bp, &bo->bo_clean.bv_hd, b_bobufs, nbp) { - if (bp->b_lblkno < startlbn || bp->b_lblkno >= endlbn) - continue; + bv = clean ? &bo->bo_clean : &bo->bo_dirty; + bp = BUF_PCTRIE_LOOKUP_GE(&bv->bv_root, startlbn); + if (bp == NULL || bp->b_lblkno >= endlbn || + bp->b_lblkno < startlbn) + continue; + TAILQ_FOREACH_FROM_SAFE(bp, &bv->bv_hd, b_bobufs, nbp) { + if (bp->b_lblkno >= endlbn) + break; if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK, BO_LOCKPTR(bo)) == ENOLCK) { @@ -2638,39 +2646,17 @@ v_inval_buf_range_locked(struct vnode *vp, struct bufobj *bo, bp->b_flags |= B_INVAL | B_RELBUF; bp->b_flags &= ~B_ASYNC; brelse(bp); - anyfreed = true; + anyfreed = 2; BO_LOCK(bo); if (nbp != NULL && - (((nbp->b_xflags & BX_VNCLEAN) == 0) || + (((nbp->b_xflags & + (clean ? BX_VNCLEAN : BX_VNDIRTY)) == 0) || nbp->b_vp != vp || - (nbp->b_flags & B_DELWRI) != 0)) - return (EAGAIN); - } - - TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) { - if (bp->b_lblkno < startlbn || bp->b_lblkno >= endlbn) - continue; - if (BUF_LOCK(bp, - LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK, - BO_LOCKPTR(bo)) == ENOLCK) { - BO_LOCK(bo); - return (EAGAIN); - } - bremfree(bp); - bp->b_flags |= B_INVAL | B_RELBUF; - bp->b_flags &= ~B_ASYNC; - brelse(bp); - anyfreed = true; - - BO_LOCK(bo); - if (nbp != NULL && - (((nbp->b_xflags & BX_VNDIRTY) == 0) || - (nbp->b_vp != vp) || - (nbp->b_flags & B_DELWRI) == 0)) + (nbp->b_flags & B_DELWRI) == (clean? B_DELWRI: 0))) return (EAGAIN); } - } while (anyfreed); + } while (clean = !clean, anyfreed-- > 0); return (0); }