Skip to contentSkip to conversation

knfsd: repcache: make REQHASH a function

PATCH In review Greg Banks 1 participant 1 message Oct 11, 2006

Subsystems (2)
lore
Share & tools
lore

Greg Banks

author
#0 lore raw

PATCH 2/8 knfsd: repcache: make REQHASH a function

knfsd: Make the REQHASH() macro in the duplicate request cache an inline function, as interesting things will happen to it soon. Also, make sure we get lots of variation in the low bits regardless of which end of the xid the clients increment. Finally add a comment.

---

 fs/nfsd/nfscache.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
fs/nfsd/nfscache.c +16 -3
Index: linux-git-20061009/fs/nfsd/nfscache.c
===================================================================
@@ -29,12 +29,25 @@
  */
 #define CACHESIZE		1024
 #define HASHSIZE		64
-#define REQHASH(xid)		((((xid) >> 24) ^ (xid)) & (HASHSIZE-1))
 
 static struct hlist_head *	hash_list;
 static struct list_head 	lru_head;
 static int			cache_disabled = 1;
 
+/*
+ * Calculate the hash index from an XID.  Note, some clients increment
+ * their XIDs in host order, which can result in all the variation being
+ * in the top bits we see here.  So we fold those bits down.
+ */
+static inline u32
+request_hash(u32 xid)
+{
+	u32 h = xid;
+	h ^= (xid >> 24);
+	h ^= ((xid & 0xff0000) >> 8);
+	return h & (HASHSIZE-1);
+}
+
 static int	nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec);
 
 /*
@@ -114,7 +127,7 @@ static void
 hash_refile(struct svc_cacherep *rp)
 {
 	hlist_del_init(&rp->c_hash);
-	hlist_add_head(&rp->c_hash, hash_list + REQHASH(rp->c_xid));
+	hlist_add_head(&rp->c_hash, hash_list + request_hash(rp->c_xid));
 }
 
 /*
@@ -145,7 +158,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp
 	spin_lock(&cache_lock);
 	rtn = RC_DOIT;
 
-	rh = &hash_list[REQHASH(xid)];
+	rh = &hash_list[request_hash(xid)];
 	hlist_for_each_entry(rp, hn, rh, c_hash) {
 		if (rp->c_state != RC_UNUSED &&
 		    xid == rp->c_xid && proc == rp->c_proc &&
Signature · 13 lines
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
I don't speak for SGI.



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs