From owner-svn-src-all@freebsd.org Sun Sep 4 08:58:36 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DB450BCED41; Sun, 4 Sep 2016 08:58:36 +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 mx1.freebsd.org (Postfix) with ESMTPS id 947C3E1F; Sun, 4 Sep 2016 08:58:36 +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 u848wZ9g055340; Sun, 4 Sep 2016 08:58:35 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u848wZgt055339; Sun, 4 Sep 2016 08:58:35 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201609040858.u848wZgt055339@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sun, 4 Sep 2016 08:58:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305379 - head/sys/kern X-SVN-Group: head 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.22 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: Sun, 04 Sep 2016 08:58:37 -0000 Author: mjg Date: Sun Sep 4 08:58:35 2016 New Revision: 305379 URL: https://svnweb.freebsd.org/changeset/base/305379 Log: cache: manage negative entry list with a dedicated lock Since negative entries are managed with a LRU list, a hit requires a modificaton. Currently the code tries to upgrade the global lock if needed and is forced to retry the lookup if it fails. Provide a dedicated lock for use when the cache is only shared-locked. Reviewed by: kib MFC after: 1 week Modified: head/sys/kern/vfs_cache.c Modified: head/sys/kern/vfs_cache.c ============================================================================== --- head/sys/kern/vfs_cache.c Sun Sep 4 08:55:15 2016 (r305378) +++ head/sys/kern/vfs_cache.c Sun Sep 4 08:58:35 2016 (r305379) @@ -186,6 +186,9 @@ RW_SYSINIT(vfscache, &cache_lock, "Name #define CACHE_WLOCK() rw_wlock(&cache_lock) #define CACHE_WUNLOCK() rw_wunlock(&cache_lock) +static struct mtx_padalign ncneg_mtx; +MTX_SYSINIT(vfscache_neg, &ncneg_mtx, "Name Cache neg", MTX_DEF); + /* * UMA zones for the VFS cache. * @@ -436,12 +439,21 @@ SYSCTL_PROC(_debug_hashstat, OID_AUTO, n * Negative entries management */ static void -cache_negative_hit(struct namecache *ncp) +cache_negative_hit(struct namecache *ncp, int wlocked) { - rw_assert(&cache_lock, RA_WLOCKED); + if (!wlocked) { + rw_assert(&cache_lock, RA_RLOCKED); + mtx_lock(&ncneg_mtx); + } else { + rw_assert(&cache_lock, RA_WLOCKED); + } + TAILQ_REMOVE(&ncneg, ncp, nc_dst); TAILQ_INSERT_TAIL(&ncneg, ncp, nc_dst); + + if (!wlocked) + mtx_unlock(&ncneg_mtx); } static void @@ -680,16 +692,17 @@ negative_success: return (0); } - if (!wlocked && !CACHE_UPGRADE_LOCK()) - goto wlock; counter_u64_add(numneghits, 1); - cache_negative_hit(ncp); + cache_negative_hit(ncp, wlocked); if (ncp->nc_flag & NCF_WHITE) cnp->cn_flags |= ISWHITEOUT; SDT_PROBE2(vfs, namecache, lookup, hit__negative, dvp, nc_get_name(ncp)); cache_out_ts(ncp, tsp, ticksp); - CACHE_WUNLOCK(); + if (wlocked) + CACHE_WUNLOCK(); + else + CACHE_RUNLOCK(); return (ENOENT); wlock: