svn commit: r363782 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Sun Aug 2 20:02:06 UTC 2020


Author: mjg
Date: Sun Aug  2 20:02:06 2020
New Revision: 363782
URL: https://svnweb.freebsd.org/changeset/base/363782

Log:
  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

Modified:
  head/sys/kern/vfs_cache.c

Modified: head/sys/kern/vfs_cache.c
==============================================================================
--- head/sys/kern/vfs_cache.c	Sun Aug  2 20:00:43 2020	(r363781)
+++ head/sys/kern/vfs_cache.c	Sun Aug  2 20:02:06 2020	(r363782)
@@ -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


More information about the svn-src-all mailing list