cache: try to avoid vhold if locks held

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Mateusz Guzik 2019-09-22 20:50:24 +00:00
parent cd2112c305
commit 7505cffa56
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=352613

View File

@ -1690,7 +1690,7 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp,
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, struct componentname *cnp,
}
}
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, struct componentname *cnp,
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, struct componentname *cnp,
out_unlock_free:
cache_enter_unlock(&cel);
cache_free(ncp);
if (held_dvp) {
vdrop(dvp);
atomic_subtract_long(&numcachehv, 1);
}
return;
}