From owner-dev-commits-src-branches@freebsd.org Thu Jan 21 12:47:21 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D83984F4490; Thu, 21 Jan 2021 12:47: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DM2Gd5qxcz3rgD; Thu, 21 Jan 2021 12:47:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B089B3E65; Thu, 21 Jan 2021 12:47:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10LClLTi040514; Thu, 21 Jan 2021 12:47:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10LClLNT040513; Thu, 21 Jan 2021 12:47:21 GMT (envelope-from git) Date: Thu, 21 Jan 2021 12:47:21 GMT Message-Id: <202101211247.10LClLNT040513@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: b3daf5db761e - stable/12 - tmpfs_reclaim: detach unlinked node on dereferencing. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: b3daf5db761e2e32b8e4384587c593fb6c645e2f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jan 2021 12:47:21 -0000 The branch stable/12 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=b3daf5db761e2e32b8e4384587c593fb6c645e2f commit b3daf5db761e2e32b8e4384587c593fb6c645e2f Author: Konstantin Belousov AuthorDate: 2021-01-12 16:10:07 +0000 Commit: Konstantin Belousov CommitDate: 2021-01-21 12:45:32 +0000 tmpfs_reclaim: detach unlinked node on dereferencing. (cherry picked from commit 2d1e4220ebd50b9220d3266754425f025c786108) --- sys/fs/tmpfs/tmpfs_vnops.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index 84134e48e83e..bfb84c508c78 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -1305,10 +1305,12 @@ tmpfs_reclaim(struct vop_reclaim_args *v) struct vnode *vp; struct tmpfs_mount *tmp; struct tmpfs_node *node; + bool unlock, tm_locked; vp = v->a_vp; node = VP_TO_TMPFS_NODE(vp); tmp = VFS_TO_TMPFS(vp->v_mount); + tm_locked = false; if (vp->v_type == VREG) tmpfs_destroy_vobject(vp, node->tn_reg.tn_aobj); @@ -1318,7 +1320,15 @@ tmpfs_reclaim(struct vop_reclaim_args *v) if (tmpfs_use_nc(vp)) cache_purge(vp); +relock: TMPFS_NODE_LOCK(node); + if (!tm_locked && node->tn_links == 0 && + (node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0) { + TMPFS_NODE_UNLOCK(node); + TMPFS_LOCK(tmp); + tm_locked = true; + goto relock; + } tmpfs_free_vp(vp); /* @@ -1328,11 +1338,18 @@ tmpfs_reclaim(struct vop_reclaim_args *v) */ if (node->tn_links == 0 && (node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0) { + MPASS(tm_locked); node->tn_vpstate = TMPFS_VNODE_DOOMED; + unlock = !tmpfs_free_node_locked(tmp, node, true); + } else { + unlock = true; + } + + if (unlock) { TMPFS_NODE_UNLOCK(node); - tmpfs_free_node(tmp, node); - } else - TMPFS_NODE_UNLOCK(node); + if (tm_locked) + TMPFS_UNLOCK(tmp); + } MPASS(vp->v_data == NULL); return (0); @@ -1543,6 +1560,7 @@ tmpfs_vptocnp(struct vop_vptocnp_args *ap) } restart: TMPFS_LOCK(tm); +restart_locked: LIST_FOREACH_SAFE(tnp, &tm->tm_nodes_used, tn_entries, tnp1) { if (tnp->tn_type != VDIR) continue; @@ -1580,8 +1598,13 @@ restart: } else { KASSERT(tnp->tn_refcount > 0, ("node %p refcount zero", tnp)); - tnp1 = LIST_NEXT(tnp, tn_entries); - TMPFS_NODE_UNLOCK(tnp); + if (tnp->tn_attached) { + tnp1 = LIST_NEXT(tnp, tn_entries); + TMPFS_NODE_UNLOCK(tnp); + } else { + TMPFS_NODE_UNLOCK(tnp); + goto restart_locked; + } } } TMPFS_UNLOCK(tm);