From owner-dev-commits-src-main@freebsd.org Mon Jan 25 22:42:48 2021 Return-Path: Delivered-To: dev-commits-src-main@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 C61934F48D8; Mon, 25 Jan 2021 22:42: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 4DPlHr3qrtz3kpS; Mon, 25 Jan 2021 22:42:48 +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 736D41EA83; Mon, 25 Jan 2021 22:42:44 +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 10PMgiJ8026436; Mon, 25 Jan 2021 22:42:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10PMgiIv026435; Mon, 25 Jan 2021 22:42:44 GMT (envelope-from git) Date: Mon, 25 Jan 2021 22:42:44 GMT Message-Id: <202101252242.10PMgiIv026435@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: e7cf562a40fc - main - cache: change ->v_cache_dd synchronisation rules MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e7cf562a40fc093df054bd7fa6f34746069a984a Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jan 2021 22:42:49 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=e7cf562a40fc093df054bd7fa6f34746069a984a commit e7cf562a40fc093df054bd7fa6f34746069a984a Author: Mateusz Guzik AuthorDate: 2021-01-25 20:49:09 +0000 Commit: Mateusz Guzik CommitDate: 2021-01-25 22:41:13 +0000 cache: change ->v_cache_dd synchronisation rules Instead of resorting to seqc modification take advantage of immutability of entries and check if the entry still matches after everything got prepared. --- sys/kern/vfs_cache.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index fad7ce91ef44..a73e4843b5f3 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -1440,9 +1440,7 @@ cache_zap_locked(struct namecache *ncp) SDT_PROBE3(vfs, namecache, zap, done, dvp, ncp->nc_name, vp); TAILQ_REMOVE(&vp->v_cache_dst, ncp, nc_dst); if (ncp == vp->v_cache_dd) { - vn_seqc_write_begin_unheld(vp); atomic_store_ptr(&vp->v_cache_dd, NULL); - vn_seqc_write_end(vp); } } else { SDT_PROBE2(vfs, namecache, zap_negative, done, dvp, ncp->nc_name); @@ -1450,9 +1448,7 @@ cache_zap_locked(struct namecache *ncp) } if (ncp->nc_flag & NCF_ISDOTDOT) { if (ncp == dvp->v_cache_dd) { - vn_seqc_write_begin_unheld(dvp); atomic_store_ptr(&dvp->v_cache_dd, NULL); - vn_seqc_write_end(dvp); } } else { LIST_REMOVE(ncp, nc_src); @@ -1627,9 +1623,7 @@ retry_dotdot: mtx_unlock(dvlp2); cache_free(ncp); } else { - vn_seqc_write_begin(dvp); atomic_store_ptr(&dvp->v_cache_dd, NULL); - vn_seqc_write_end(dvp); mtx_unlock(dvlp); if (dvlp2 != NULL) mtx_unlock(dvlp2); @@ -2246,7 +2240,6 @@ cache_enter_dotdot_prep(struct vnode *dvp, struct vnode *vp, cache_celockstate_init(&cel); hash = cache_get_hash(cnp->cn_nameptr, len, dvp); cache_enter_lock_dd(&cel, dvp, vp, hash); - vn_seqc_write_begin(dvp); ncp = dvp->v_cache_dd; if (ncp != NULL && (ncp->nc_flag & NCF_ISDOTDOT)) { KASSERT(ncp->nc_dvp == dvp, ("wrong isdotdot parent")); @@ -2255,7 +2248,6 @@ cache_enter_dotdot_prep(struct vnode *dvp, struct vnode *vp, ncp = NULL; } atomic_store_ptr(&dvp->v_cache_dd, NULL); - vn_seqc_write_end(dvp); cache_enter_unlock(&cel); if (ncp != NULL) cache_free(ncp); @@ -2392,9 +2384,8 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, goto out_unlock_free; KASSERT(vp == NULL || vp->v_type == VDIR, ("wrong vnode type %p", vp)); - vn_seqc_write_begin(dvp); + atomic_thread_fence_rel(); atomic_store_ptr(&dvp->v_cache_dd, ncp); - vn_seqc_write_end(dvp); } if (vp != NULL) { @@ -2404,20 +2395,17 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, * directory name in it and the name ".." for the * directory's parent. */ - vn_seqc_write_begin(vp); if ((ndd = vp->v_cache_dd) != NULL) { if ((ndd->nc_flag & NCF_ISDOTDOT) != 0) cache_zap_locked(ndd); else ndd = NULL; } + atomic_thread_fence_rel(); atomic_store_ptr(&vp->v_cache_dd, ncp); - vn_seqc_write_end(vp); } else if (vp->v_type != VDIR) { if (vp->v_cache_dd != NULL) { - vn_seqc_write_begin(vp); atomic_store_ptr(&vp->v_cache_dd, NULL); - vn_seqc_write_end(vp); } } } @@ -3301,10 +3289,6 @@ vn_fullpath_any_smr(struct vnode *vp, struct vnode *rdir, char *buf, cache_rev_failed(&reason); goto out_abort; } - if (!cache_ncp_canuse(ncp)) { - cache_rev_failed(&reason); - goto out_abort; - } if (ncp->nc_nlen >= *buflen) { cache_rev_failed(&reason); error = ENOMEM; @@ -3324,6 +3308,17 @@ vn_fullpath_any_smr(struct vnode *vp, struct vnode *rdir, char *buf, cache_rev_failed(&reason); goto out_abort; } + /* + * Acquire fence provided by vn_seqc_read_any above. + */ + if (__predict_false(atomic_load_ptr(&vp->v_cache_dd) != ncp)) { + cache_rev_failed(&reason); + goto out_abort; + } + if (!cache_ncp_canuse(ncp)) { + cache_rev_failed(&reason); + goto out_abort; + } vp = tvp; vp_seqc = tvp_seqc; if (vp == rdir || vp == rootvnode) @@ -4719,15 +4714,22 @@ cache_fplookup_dotdot(struct cache_fpl *fpl) fpl->tvp = ncp->nc_dvp; } - if (!cache_ncp_canuse(ncp)) { - return (cache_fpl_aborted(fpl)); - } - fpl->tvp_seqc = vn_seqc_read_any(fpl->tvp); if (seqc_in_modify(fpl->tvp_seqc)) { return (cache_fpl_partial(fpl)); } + /* + * Acquire fence provided by vn_seqc_read_any above. + */ + if (__predict_false(atomic_load_ptr(&dvp->v_cache_dd) != ncp)) { + return (cache_fpl_aborted(fpl)); + } + + if (!cache_ncp_canuse(ncp)) { + return (cache_fpl_aborted(fpl)); + } + counter_u64_add(dotdothits, 1); return (0); }