From owner-svn-src-head@freebsd.org Tue Sep 10 20:08:25 2019 Return-Path: Delivered-To: svn-src-head@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 062C2E2D96; Tue, 10 Sep 2019 20:08: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) server-signature RSA-PSS (4096 bits) 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 46Sbgr67L3z3xGp; Tue, 10 Sep 2019 20:08:24 +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 9C70D2B4A2; Tue, 10 Sep 2019 20:08:24 +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 x8AK8OEJ045712; Tue, 10 Sep 2019 20:08:24 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x8AK8Ot6045711; Tue, 10 Sep 2019 20:08:24 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201909102008.x8AK8Ot6045711@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Tue, 10 Sep 2019 20:08:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r352177 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 352177 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Sep 2019 20:08:25 -0000 Author: mjg Date: Tue Sep 10 20:08:24 2019 New Revision: 352177 URL: https://svnweb.freebsd.org/changeset/base/352177 Log: cache: assorted cleanups Sponsored by: The FreeBSD Foundation Modified: head/sys/kern/vfs_cache.c Modified: head/sys/kern/vfs_cache.c ============================================================================== --- head/sys/kern/vfs_cache.c Tue Sep 10 19:08:01 2019 (r352176) +++ head/sys/kern/vfs_cache.c Tue Sep 10 20:08:24 2019 (r352177) @@ -380,6 +380,8 @@ STATNODE_COUNTER(numfullpathfail4, "Number of fullpath STATNODE_COUNTER(numfullpathfound, "Number of successful fullpath calls"); static long zap_and_exit_bucket_fail; STATNODE_ULONG(zap_and_exit_bucket_fail, "Number of times zap_and_exit failed to lock"); +static long zap_and_exit_bucket_fail2; STATNODE_ULONG(zap_and_exit_bucket_fail2, + "Number of times zap_and_exit failed to lock"); static long cache_lock_vnodes_cel_3_failures; STATNODE_ULONG(cache_lock_vnodes_cel_3_failures, "Number of times 3-way vnode locking failed"); @@ -394,7 +396,7 @@ static int cache_yield; SYSCTL_INT(_vfs_cache, OID_AUTO, yield, CTLFLAG_RD, &cache_yield, 0, "Number of times cache called yield"); -static void +static void __noinline cache_maybe_yield(void) { @@ -453,12 +455,14 @@ cache_assert_bucket_locked(struct namecache *ncp, int #define cache_assert_bucket_locked(x, y) do { } while (0) #endif -#define cache_sort(x, y) _cache_sort((void **)(x), (void **)(y)) +#define cache_sort_vnodes(x, y) _cache_sort_vnodes((void **)(x), (void **)(y)) static void -_cache_sort(void **p1, void **p2) +_cache_sort_vnodes(void **p1, void **p2) { void *tmp; + MPASS(*p1 != NULL || *p2 != NULL); + if (*p1 > *p2) { tmp = *p2; *p2 = *p1; @@ -506,8 +510,7 @@ static int cache_trylock_vnodes(struct mtx *vlp1, struct mtx *vlp2) { - cache_sort(&vlp1, &vlp2); - MPASS(vlp2 != NULL); + cache_sort_vnodes(&vlp1, &vlp2); if (vlp1 != NULL) { if (!mtx_trylock(vlp1)) @@ -924,7 +927,7 @@ cache_zap_locked_vnode_kl2(struct namecache *ncp, stru mtx_unlock(*vlpp); *vlpp = NULL; } - cache_sort(&vlp1, &vlp2); + cache_sort_vnodes(&vlp1, &vlp2); if (vlp1 == pvlp) { mtx_lock(vlp2); to_unlock = vlp2; @@ -950,7 +953,7 @@ out_relock: return (false); } -static int +static int __noinline cache_zap_locked_vnode(struct namecache *ncp, struct vnode *vp) { struct mtx *pvlp, *vlp1, *vlp2, *to_unlock; @@ -969,7 +972,7 @@ cache_zap_locked_vnode(struct namecache *ncp, struct v blp = NCP2BUCKETLOCK(ncp); vlp1 = VP2VNODELOCK(ncp->nc_dvp); vlp2 = VP2VNODELOCK(ncp->nc_vp); - cache_sort(&vlp1, &vlp2); + cache_sort_vnodes(&vlp1, &vlp2); if (vlp1 == pvlp) { mtx_lock(vlp2); to_unlock = vlp2; @@ -1047,7 +1050,7 @@ cache_zap_wlocked_bucket_kl(struct namecache *ncp, str vlp = NULL; if (!(ncp->nc_flag & NCF_NEGATIVE)) vlp = VP2VNODELOCK(ncp->nc_vp); - cache_sort(&dvlp, &vlp); + cache_sort_vnodes(&dvlp, &vlp); if (*vlpp1 == dvlp && *vlpp2 == vlp) { cache_zap_locked(ncp, false); @@ -1194,14 +1197,13 @@ retry: goto out_no_entry; } - counter_u64_add(numposzaps, 1); - error = cache_zap_wlocked_bucket(ncp, blp); - if (error != 0) { + if (__predict_false(error != 0)) { zap_and_exit_bucket_fail++; cache_maybe_yield(); goto retry; } + counter_u64_add(numposzaps, 1); cache_free(ncp); return (0); out_no_entry: @@ -1397,8 +1399,8 @@ zap_and_exit: error = cache_zap_rlocked_bucket(ncp, blp); else error = cache_zap_locked_vnode(ncp, dvp); - if (error != 0) { - zap_and_exit_bucket_fail++; + if (__predict_false(error != 0)) { + zap_and_exit_bucket_fail2++; cache_maybe_yield(); goto retry; } @@ -1434,7 +1436,7 @@ cache_lock_vnodes_cel(struct celockstate *cel, struct vlp1 = VP2VNODELOCK(vp); vlp2 = VP2VNODELOCK(dvp); - cache_sort(&vlp1, &vlp2); + cache_sort_vnodes(&vlp1, &vlp2); if (vlp1 != NULL) { mtx_lock(vlp1); @@ -1504,7 +1506,7 @@ cache_lock_buckets_cel(struct celockstate *cel, struct MPASS(cel->blp[0] == NULL); MPASS(cel->blp[1] == NULL); - cache_sort(&blp1, &blp2); + cache_sort_vnodes(&blp1, &blp2); if (blp1 != NULL) { rw_wlock(blp1);