svn commit: r352613 - head/sys/kern
Mateusz Guzik
mjg at FreeBSD.org
Sun Sep 22 20:50:25 UTC 2019
Author: mjg
Date: Sun Sep 22 20:50:24 2019
New Revision: 352613
URL: https://svnweb.freebsd.org/changeset/base/352613
Log:
cache: try to avoid vhold if locks held
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 Sun Sep 22 20:49:17 2019 (r352612)
+++ head/sys/kern/vfs_cache.c Sun Sep 22 20:50:24 2019 (r352613)
@@ -1690,7 +1690,7 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp,
uint32_t hash;
int flag;
int len;
- bool neg_locked;
+ bool neg_locked, held_dvp;
u_long lnumcache;
CTR3(KTR_VFS, "cache_enter(%p, %p, %s)", dvp, vp, cnp->cn_nameptr);
@@ -1769,6 +1769,13 @@ 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);
+ held_dvp = true;
+ }
+
/*
* Calculate the hash key and setup as much of the new
* namecache entry as possible before acquiring the lock.
@@ -1858,8 +1865,21 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp,
if (flag != NCF_ISDOTDOT) {
if (LIST_EMPTY(&dvp->v_cache_src)) {
- vhold(dvp);
- atomic_add_rel_long(&numcachehv, 1);
+ if (!held_dvp) {
+ vhold(dvp);
+ atomic_add_long(&numcachehv, 1);
+ }
+ } else {
+ if (held_dvp) {
+ /*
+ * This will not take the interlock as someone
+ * else already holds the vnode on account of
+ * the namecache and we hold locks preventing
+ * this from changing.
+ */
+ vdrop(dvp);
+ atomic_subtract_long(&numcachehv, 1);
+ }
}
LIST_INSERT_HEAD(&dvp->v_cache_src, ncp, nc_src);
}
@@ -1894,6 +1914,10 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp,
out_unlock_free:
cache_enter_unlock(&cel);
cache_free(ncp);
+ if (held_dvp) {
+ vdrop(dvp);
+ atomic_subtract_long(&numcachehv, 1);
+ }
return;
}
More information about the svn-src-all
mailing list