From nobody Sat May 03 00:04:49 2025 X-Original-To: dev-commits-src-main@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 4Zq7MQ068Zz5vGy2; Sat, 03 May 2025 00:04:50 +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 4Zq7MP5ttSz40rv; Sat, 03 May 2025 00:04:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746230689; 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=M9aKqfFDPwsI2Y5GpkHpuxDbQkqGHrnEWAMTD6RzSIk=; b=AhyojcL1W6mqtqPr8ciza//8Pf+0f8ZFZSf5s/JhrlxaVfHHKhcT34nLEi3e0BAh3gEX/H aK9IAprMODW/KnfLG2ubHQq4Ky80NgkT3IiRzQXL7ZMo99tvyBUGSg7Cnk1QG5apRgfOvC /ho9rFTbbXUeEtfpUTgRZ4hIZ384MQi/vwLDO0gCKJVqdXJHo1FBXXGKsolP5H1bA6bWCC 9VUS1hRPr5ktsRDxqIzqOBh0pHmutledKL9lv3BI9suvDIeecp6CdyMKFQMgDecr3yGN/A tfK6CSZCRhJexKvSnrW0JJYNDSNMfA9/trYnRIOuvQQCiNwXdUTWRJK60ZN+1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746230689; 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=M9aKqfFDPwsI2Y5GpkHpuxDbQkqGHrnEWAMTD6RzSIk=; b=H1FmuXa1t1rNJEou71Wz1XYxanDCV80zb2V5HL7rpEoXL9iSGhK+gfQ0AdBNbJHe2r6FgD Cn03u5ceCoYF4LZmF6ZEM42hoNo9l4aCPApvxQbkYLXwjhlOltU6+XCdLpKBFdREhbrF3g EBcxRn0QY3lVmUsMux4JCLdVnqowbypUihhgry+dhK6AzHCVGN99iZw1zD8jY4rsVLJPRh +q44MVHU1/w0+ef86E//ymqmjERhkwFe/6aR0CQhi+XPFXEfsIeVxA9GBwY37WCHX7KJ3d b+ZwHA9YZfSnJz5MK/QRUdWVhBvfAj9PQRTPmnXGyyaV+3bJggzexqSKgBDGcw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746230689; a=rsa-sha256; cv=none; b=jqaf7mrI5Qib0CpoJi44uaockKzbJNn8HuvCgUkF7ssm1ZM9PGHEuEfUOyDkCIHFBm2oG/ BIPR1fScz+CWODAEjd0QQhEvfuLLxcNFdaRBLcLzuB9v5nBi7sx2oqbsgYTE0eNL81aAga uzsJbgPl8FUil7qCwHlW5wytsYbrR5DswXb6ciSFjf6NXG3Iy/RV0QhhPNgV2se0I/hTi8 a/vrWR9cPY392wYQ4jUdYN/i/vyAb9TIgGdG7XdaJKiMXW8YKc7cmhSbIO2OtHm123COLq firVKYF8Q4e+4Mz1U92676ZDBj4sCzIu0XonMfxNDnx07jSHyvmD0RFxKTp2Tg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4Zq7MP5K8kz3wC; Sat, 03 May 2025 00:04:49 +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 54304nCJ035257; Sat, 3 May 2025 00:04:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54304n2p035254; Sat, 3 May 2025 00:04:49 GMT (envelope-from git) Date: Sat, 3 May 2025 00:04:49 GMT Message-Id: <202505030004.54304n2p035254@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: cc25864d4568 - main - vfs cache: Move hash row lookup loops into a subroutine List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cc25864d4568079cadef46291ddf7d501c81d60a Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=cc25864d4568079cadef46291ddf7d501c81d60a commit cc25864d4568079cadef46291ddf7d501c81d60a Author: Mark Johnston AuthorDate: 2025-05-02 21:35:04 +0000 Commit: Mark Johnston CommitDate: 2025-05-03 00:04:32 +0000 vfs cache: Move hash row lookup loops into a subroutine No functional change intended. Reviewed by: olce, kib MFC after: 2 weeks Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D50106 --- sys/kern/vfs_cache.c | 129 +++++++++++++++++++++++++-------------------------- sys/sys/vnode.h | 1 + 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 670ac66ae6d7..86e5c65ba3da 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -585,6 +585,24 @@ VP2VNODELOCK(struct vnode *vp) return (&vnodelocks[(((uintptr_t)(vp) >> 8) & ncvnodehash)]); } +/* + * Search the hash table for a namecache entry. Either the corresponding bucket + * must be locked, or the caller must be in an SMR read section. + */ +static struct namecache * +cache_ncp_find(struct vnode *dvp, struct componentname *cnp, uint32_t hash) +{ + struct namecache *ncp; + + KASSERT(mtx_owned(HASH2BUCKETLOCK(hash)) || VFS_SMR_ENTERED(), + ("%s: hash %u not locked", __func__, hash)); + CK_SLIST_FOREACH(ncp, NCHHASH(hash), nc_hash) { + if (cache_ncp_match(ncp, dvp, cnp)) + break; + } + return (ncp); +} + static void cache_out_ts(struct namecache *ncp, struct timespec *tsp, int *ticksp) { @@ -1877,12 +1895,7 @@ retry: goto out_no_entry; mtx_lock(blp); - - CK_SLIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) { - if (cache_ncp_match(ncp, dvp, cnp)) - break; - } - + ncp = cache_ncp_find(dvp, cnp, hash); if (ncp == NULL) { mtx_unlock(blp); goto out_no_entry; @@ -2078,11 +2091,7 @@ retry: blp = HASH2BUCKETLOCK(hash); mtx_lock(blp); - CK_SLIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) { - if (cache_ncp_match(ncp, dvp, cnp)) - break; - } - + ncp = cache_ncp_find(dvp, cnp, hash); if (__predict_false(ncp == NULL)) { mtx_unlock(blp); SDT_PROBE2(vfs, namecache, lookup, miss, dvp, cnp->cn_nameptr); @@ -2172,11 +2181,7 @@ cache_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, hash = cache_get_hash(cnp->cn_nameptr, cnp->cn_namelen, dvp); vfs_smr_enter(); - CK_SLIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) { - if (cache_ncp_match(ncp, dvp, cnp)) - break; - } - + ncp = cache_ncp_find(dvp, cnp, hash); if (__predict_false(ncp == NULL)) { vfs_smr_exit(); SDT_PROBE2(vfs, namecache, lookup, miss, dvp, cnp->cn_nameptr); @@ -2494,7 +2499,6 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, struct celockstate cel; struct namecache *ncp, *n2, *ndd; struct namecache_ts *ncp_ts; - struct nchashhead *ncpp; uint32_t hash; int flag; int len; @@ -2571,45 +2575,46 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, * with this name. This can happen with concurrent lookups of * the same path name. */ - ncpp = NCHHASH(hash); - CK_SLIST_FOREACH(n2, ncpp, nc_hash) { - if (cache_ncp_match(n2, dvp, cnp)) { - MPASS(cache_ncp_canuse(n2)); - if ((n2->nc_flag & NCF_NEGATIVE) != 0) - KASSERT(vp == NULL, - ("%s: found entry pointing to a different vnode (%p != %p) ; name [%s]", - __func__, NULL, vp, cnp->cn_nameptr)); - else - KASSERT(n2->nc_vp == vp, - ("%s: found entry pointing to a different vnode (%p != %p) ; name [%s]", - __func__, n2->nc_vp, vp, cnp->cn_nameptr)); - /* - * Entries are supposed to be immutable unless in the - * process of getting destroyed. Accommodating for - * changing timestamps is possible but not worth it. - * This should be harmless in terms of correctness, in - * the worst case resulting in an earlier expiration. - * Alternatively, the found entry can be replaced - * altogether. - */ - MPASS((n2->nc_flag & (NCF_TS | NCF_DTS)) == (ncp->nc_flag & (NCF_TS | NCF_DTS))); + n2 = cache_ncp_find(dvp, cnp, hash); + if (n2 != NULL) { + MPASS(cache_ncp_canuse(n2)); + if ((n2->nc_flag & NCF_NEGATIVE) != 0) + KASSERT(vp == NULL, + ("%s: found entry pointing to a different vnode " + "(%p != %p); name [%s]", + __func__, NULL, vp, cnp->cn_nameptr)); + else + KASSERT(n2->nc_vp == vp, + ("%s: found entry pointing to a different vnode " + "(%p != %p); name [%s]", + __func__, n2->nc_vp, vp, cnp->cn_nameptr)); + /* + * Entries are supposed to be immutable unless in the + * process of getting destroyed. Accommodating for + * changing timestamps is possible but not worth it. + * This should be harmless in terms of correctness, in + * the worst case resulting in an earlier expiration. + * Alternatively, the found entry can be replaced + * altogether. + */ + MPASS((n2->nc_flag & (NCF_TS | NCF_DTS)) == + (ncp->nc_flag & (NCF_TS | NCF_DTS))); #if 0 - if (tsp != NULL) { - KASSERT((n2->nc_flag & NCF_TS) != 0, - ("no NCF_TS")); - n2_ts = __containerof(n2, struct namecache_ts, nc_nc); - n2_ts->nc_time = ncp_ts->nc_time; - n2_ts->nc_ticks = ncp_ts->nc_ticks; - if (dtsp != NULL) { - n2_ts->nc_dotdottime = ncp_ts->nc_dotdottime; - n2_ts->nc_nc.nc_flag |= NCF_DTS; - } + if (tsp != NULL) { + KASSERT((n2->nc_flag & NCF_TS) != 0, + ("no NCF_TS")); + n2_ts = __containerof(n2, struct namecache_ts, nc_nc); + n2_ts->nc_time = ncp_ts->nc_time; + n2_ts->nc_ticks = ncp_ts->nc_ticks; + if (dtsp != NULL) { + n2_ts->nc_dotdottime = ncp_ts->nc_dotdottime; + n2_ts->nc_nc.nc_flag |= NCF_DTS; } -#endif - SDT_PROBE3(vfs, namecache, enter, duplicate, dvp, ncp->nc_name, - vp); - goto out_unlock_free; } +#endif + SDT_PROBE3(vfs, namecache, enter, duplicate, dvp, ncp->nc_name, + vp); + goto out_unlock_free; } if (flag == NCF_ISDOTDOT) { @@ -2675,7 +2680,7 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, * Insert the new namecache entry into the appropriate chain * within the cache entries table. */ - CK_SLIST_INSERT_HEAD(ncpp, ncp, nc_hash); + CK_SLIST_INSERT_HEAD(NCHHASH(hash), ncp, nc_hash); atomic_thread_fence_rel(); /* @@ -3105,12 +3110,10 @@ cache_validate(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) return; blp = HASH2BUCKETLOCK(hash); mtx_lock(blp); - CK_SLIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) { - if (cache_ncp_match(ncp, dvp, cnp)) { - if (ncp->nc_vp != vp) - panic("%s: mismatch (%p != %p); ncp %p [%s] dvp %p\n", - __func__, vp, ncp->nc_vp, ncp, ncp->nc_name, ncp->nc_dvp); - } + ncp = cache_ncp_find(dvp, cnp, hash); + if (ncp != NULL && ncp->nc_vp != vp) { + panic("%s: mismatch (%p != %p); ncp %p [%s] dvp %p\n", + __func__, vp, ncp->nc_vp, ncp, ncp->nc_name, ncp->nc_dvp); } mtx_unlock(blp); } @@ -5554,11 +5557,7 @@ cache_fplookup_next(struct cache_fpl *fpl) MPASS(!cache_fpl_isdotdot(cnp)); - CK_SLIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) { - if (cache_ncp_match(ncp, dvp, cnp)) - break; - } - + ncp = cache_ncp_find(dvp, cnp, hash); if (__predict_false(ncp == NULL)) { return (cache_fplookup_noentry(fpl)); } diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index a2706e6e6b88..bed20f607339 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -1195,6 +1195,7 @@ vn_get_state(struct vnode *vp) #define vfs_smr_exit() smr_exit(VFS_SMR()) #define vfs_smr_synchronize() smr_synchronize(VFS_SMR()) #define vfs_smr_entered_load(ptr) smr_entered_load((ptr), VFS_SMR()) +#define VFS_SMR_ENTERED() SMR_ENTERED(VFS_SMR()) #define VFS_SMR_ASSERT_ENTERED() SMR_ASSERT_ENTERED(VFS_SMR()) #define VFS_SMR_ASSERT_NOT_ENTERED() SMR_ASSERT_NOT_ENTERED(VFS_SMR()) #define VFS_SMR_ZONE_SET(zone) uma_zone_set_smr((zone), VFS_SMR())