Date: Sun, 19 Jan 2020 05:37:27 +0000 (UTC) From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356880 - head/sys/kern Message-ID: <202001190537.00J5bRw7090354@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mjg Date: Sun Jan 19 05:37:27 2020 New Revision: 356880 URL: https://svnweb.freebsd.org/changeset/base/356880 Log: cache: convert numcachehv to counter(9) on 64-bit platforms Modified: head/sys/kern/vfs_cache.c Modified: head/sys/kern/vfs_cache.c ============================================================================== --- head/sys/kern/vfs_cache.c Sun Jan 19 05:36:45 2020 (r356879) +++ head/sys/kern/vfs_cache.c Sun Jan 19 05:37:27 2020 (r356880) @@ -205,7 +205,6 @@ SYSCTL_ULONG(_vfs, OID_AUTO, ncnegfactor, CTLFLAG_RW, "Ratio of negative namecache entries"); static u_long __exclusive_cache_line numneg; /* number of negative entries allocated */ static u_long __exclusive_cache_line numcache;/* number of cache entries allocated */ -static u_long __exclusive_cache_line numcachehv;/* number of cache entries with vnodes held */ u_int ncsizefactor = 2; SYSCTL_UINT(_vfs, OID_AUTO, ncsizefactor, CTLFLAG_RW, &ncsizefactor, 0, "Size factor for namecache"); @@ -341,6 +340,16 @@ SYSCTL_INT(_debug_sizeof, OID_AUTO, namecache, CTLFLAG sizeof(struct namecache), "sizeof(struct namecache)"); /* + * Use counter(9) for numcachehv if the machine is 64-bit. + * + * Stick to an atomic for the rest since there is no long-sized equivalent and + * 64-bit size is both way more than needed and a pessimization. + */ +#ifdef __LP64__ +#define CACHE_NUMCACHEHV_U64 +#endif + +/* * The new name cache statistics */ static SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW, 0, @@ -352,7 +361,12 @@ static SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW, SYSCTL_COUNTER_U64(_vfs_cache, OID_AUTO, name, CTLFLAG_RD, &name, descr); STATNODE_ULONG(numneg, "Number of negative cache entries"); STATNODE_ULONG(numcache, "Number of cache entries"); +#ifdef CACHE_NUMCACHEHV_U64 +STATNODE_COUNTER(numcachehv, "Number of namecache entries with vnodes held"); +#else +static u_long __exclusive_cache_line numcachehv;/* number of cache entries with vnodes held */ STATNODE_ULONG(numcachehv, "Number of namecache entries with vnodes held"); +#endif STATNODE_COUNTER(numcalls, "Number of cache lookups"); STATNODE_COUNTER(dothits, "Number of '.' hits"); STATNODE_COUNTER(dotdothits, "Number of '..' hits"); @@ -393,6 +407,36 @@ static int vn_fullpath1(struct thread *td, struct vnod static MALLOC_DEFINE(M_VFSCACHE, "vfscache", "VFS name cache entries"); +#ifdef CACHE_NUMCACHEHV_U64 +static void +cache_numcachehv_inc(void) +{ + + counter_u64_add_protected(numcachehv, 1); +} + +static void +cache_numcachehv_dec(void) +{ + + counter_u64_add_protected(numcachehv, -1); +} +#else +static void +cache_numcachehv_inc(void) +{ + + atomic_add_long(&numcachehv, 1); +} + +static void +cache_numcachehv_dec(void) +{ + + atomic_subtract_long(&numcachehv, 1); +} +#endif + static int cache_yield; SYSCTL_INT(_vfs_cache, OID_AUTO, yield, CTLFLAG_RD, &cache_yield, 0, "Number of times cache called yield"); @@ -873,7 +917,7 @@ cache_zap_locked(struct namecache *ncp, bool neg_locke LIST_REMOVE(ncp, nc_src); if (LIST_EMPTY(&ncp->nc_dvp->v_cache_src)) { ncp->nc_flag |= NCF_DVDROP; - atomic_subtract_rel_long(&numcachehv, 1); + cache_numcachehv_dec(); } } atomic_subtract_rel_long(&numcache, 1); @@ -1742,7 +1786,7 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, held_dvp = false; if (LIST_EMPTY(&dvp->v_cache_src) && flag != NCF_ISDOTDOT) { vhold(dvp); - atomic_add_long(&numcachehv, 1); + cache_numcachehv_inc(); held_dvp = true; } @@ -1837,7 +1881,7 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, if (LIST_EMPTY(&dvp->v_cache_src)) { if (!held_dvp) { vhold(dvp); - atomic_add_long(&numcachehv, 1); + cache_numcachehv_inc(); } } else { if (held_dvp) { @@ -1848,7 +1892,7 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, * this from changing. */ vdrop(dvp); - atomic_subtract_long(&numcachehv, 1); + cache_numcachehv_dec(); } } LIST_INSERT_HEAD(&dvp->v_cache_src, ncp, nc_src); @@ -1886,7 +1930,7 @@ out_unlock_free: cache_free(ncp); if (held_dvp) { vdrop(dvp); - atomic_subtract_long(&numcachehv, 1); + cache_numcachehv_dec(); } return; } @@ -1957,6 +2001,9 @@ nchinit(void *dummy __unused) mtx_init(&ncneg_shrink_lock, "ncnegs", NULL, MTX_DEF); +#ifdef CACHE_NUMCACHEHV_U64 + numcachehv = counter_u64_alloc(M_WAITOK); +#endif numcalls = counter_u64_alloc(M_WAITOK); dothits = counter_u64_alloc(M_WAITOK); dotdothits = counter_u64_alloc(M_WAITOK);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202001190537.00J5bRw7090354>