vfs: store precomputed namecache hash in the vnode

This significantly speeds up path lookup, Cascade Lake doing access(2) on ufs
on /usr/obj/usr/src/amd64.amd64/sys/GENERIC/vnode_if.c, ops/s:
before: 2535298
after: 2797621

Over +10%.

The reversed order of computation here does not seem to matter for hash
distribution.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D25921
This commit is contained in:
Mateusz Guzik 2020-08-02 20:02:06 +00:00
parent b145e38934
commit 7ad2f1105e

View File

@ -490,14 +490,22 @@ cache_assert_vnode_locked(struct vnode *vp)
cache_assert_vlp_locked(vlp);
}
/*
* TODO: With the value stored we can do better than computing the hash based
* on the address and the choice of FNV should also be revisisted.
*/
static void
cache_prehash(struct vnode *vp)
{
vp->v_nchash = fnv_32_buf(&vp, sizeof(vp), FNV1_32_INIT);
}
static uint32_t
cache_get_hash(char *name, u_char len, struct vnode *dvp)
{
uint32_t hash;
hash = fnv_32_buf(name, len, FNV1_32_INIT);
hash = fnv_32_buf(&dvp, sizeof(dvp), hash);
return (hash);
return (fnv_32_buf(name, len, dvp->v_nchash));
}
static inline struct rwlock *
@ -2077,6 +2085,7 @@ cache_vnode_init(struct vnode *vp)
LIST_INIT(&vp->v_cache_src);
TAILQ_INIT(&vp->v_cache_dst);
vp->v_cache_dd = NULL;
cache_prehash(vp);
}
void