From owner-svn-src-all@freebsd.org Sat Oct 17 13:04:25 2020 Return-Path: Delivered-To: svn-src-all@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 E0CCD4377D0; Sat, 17 Oct 2020 13:04:25 +0000 (UTC) (envelope-from mjg@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CD3Bd5bBVz46kc; Sat, 17 Oct 2020 13:04:25 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A415921B7F; Sat, 17 Oct 2020 13:04:25 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09HD4PqU023482; Sat, 17 Oct 2020 13:04:25 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09HD4PO6023481; Sat, 17 Oct 2020 13:04:25 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202010171304.09HD4PO6023481@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sat, 17 Oct 2020 13:04:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366791 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 366791 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Oct 2020 13:04:25 -0000 Author: mjg Date: Sat Oct 17 13:04:25 2020 New Revision: 366791 URL: https://svnweb.freebsd.org/changeset/base/366791 Log: cache: avoid smr in cache_neg_evict in favoro of the already held bucket lock Modified: head/sys/kern/vfs_cache.c Modified: head/sys/kern/vfs_cache.c ============================================================================== --- head/sys/kern/vfs_cache.c Sat Oct 17 09:51:17 2020 (r366790) +++ head/sys/kern/vfs_cache.c Sat Oct 17 13:04:25 2020 (r366791) @@ -803,6 +803,11 @@ SYSCTL_COUNTER_U64(_vfs_cache_neg, OID_AUTO, evict_ski &neg_evict_skipped_empty, "Number of times evicting failed due to lack of entries"); +static COUNTER_U64_DEFINE_EARLY(neg_evict_skipped_missed); +SYSCTL_COUNTER_U64(_vfs_cache_neg, OID_AUTO, evict_skipped_missed, CTLFLAG_RD, + &neg_evict_skipped_missed, + "Number of times evicting failed due to target entry disappearing"); + static COUNTER_U64_DEFINE_EARLY(neg_evict_skipped_contended); SYSCTL_COUNTER_U64(_vfs_cache_neg, OID_AUTO, evict_skipped_contended, CTLFLAG_RD, &neg_evict_skipped_contended, @@ -1008,8 +1013,11 @@ cache_neg_evict(void) struct namecache *ncp, *ncp2; struct neglist *nl; struct negstate *ns; + struct vnode *dvp; struct mtx *dvlp; struct mtx *blp; + uint32_t hash; + u_char nlen; nl = cache_neg_evict_select(); if (nl == NULL) { @@ -1033,25 +1041,30 @@ cache_neg_evict(void) return; } ns = NCP2NEGSTATE(ncp); - dvlp = VP2VNODELOCK(ncp->nc_dvp); - blp = NCP2BUCKETLOCK(ncp); + nlen = ncp->nc_nlen; + dvp = ncp->nc_dvp; + hash = cache_get_hash(ncp->nc_name, nlen, dvp); + dvlp = VP2VNODELOCK(dvp); + blp = HASH2BUCKETLOCK(hash); mtx_unlock(&nl->nl_lock); mtx_unlock(&nl->nl_evict_lock); mtx_lock(dvlp); mtx_lock(blp); /* - * Enter SMR to safely check the negative list. - * Even if the found pointer matches, the entry may now be reallocated - * and used by a different vnode. + * Note that since all locks were dropped above, the entry may be + * gone or reallocated to be something else. */ - vfs_smr_enter(); - ncp2 = TAILQ_FIRST(&nl->nl_list); - if (ncp != ncp2 || dvlp != VP2VNODELOCK(ncp2->nc_dvp) || - blp != NCP2BUCKETLOCK(ncp2)) { - vfs_smr_exit(); + CK_SLIST_FOREACH(ncp2, (NCHHASH(hash)), nc_hash) { + if (ncp2 == ncp && ncp2->nc_dvp == dvp && + ncp2->nc_nlen == nlen && (ncp2->nc_flag & NCF_NEGATIVE) != 0) + break; + } + if (ncp2 == NULL) { + counter_u64_add(neg_evict_skipped_missed, 1); ncp = NULL; } else { - vfs_smr_exit(); + MPASS(dvlp == VP2VNODELOCK(ncp->nc_dvp)); + MPASS(blp == NCP2BUCKETLOCK(ncp)); SDT_PROBE2(vfs, namecache, evict_negative, done, ncp->nc_dvp, ncp->nc_name); cache_zap_locked(ncp);