Skip to contentSkip to conversation

NFS: Replace readdir's use of xxhash() with hash_64()

PATCH In review [email protected] 2 participants 2 messages Mar 31, 2022 – Apr 5, 2022

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 NFS: Replace readdir's use of xxhash() with hash_64()

From: Trond Myklebust <[email protected]>

Both xxhash() and hash_64() appear to give similarly low collision rates with a standard linearly increasing readdir offset. They both give similarly higher collision rates when applied to ext4's offsets.

So switch to using the standard hash_64().

---
 fs/nfs/Kconfig | 4 ----
 fs/nfs/dir.c   | 9 +++------
 2 files changed, 3 insertions(+), 10 deletions(-)
fs/nfs/Kconfig +0 -4
index 47a53b3362b6..14a72224b657 100644
@@ -4,10 +4,6 @@ config NFS_FS
 	depends on INET && FILE_LOCKING && MULTIUSER
 	select LOCKD
 	select SUNRPC
-	select CRYPTO
-	select CRYPTO_HASH
-	select XXHASH
-	select CRYPTO_XXHASH
 	select NFS_ACL_SUPPORT if NFS_V3_ACL
 	help
 	  Choose Y here if you want to access files residing on other
fs/nfs/dir.c +3 -6
index 0365063b85a2..c6b263b5faf1 100644
@@ -39,7 +39,7 @@
 #include <linux/sched.h>
 #include <linux/kmemleak.h>
 #include <linux/xattr.h>
-#include <linux/xxhash.h>
+#include <linux/hash.h>
 
 #include "delegation.h"
 #include "iostat.h"
@@ -350,10 +350,7 @@ static int nfs_readdir_page_array_append(struct page *page,
  * of directory cookies. Content is addressed by the value of the
  * cookie index of the first readdir entry in a page.
  *
- * The xxhash algorithm is chosen because it is fast, and is supposed
- * to result in a decent flat distribution of hashes.
- *
- * We then select only the first 18 bits to avoid issues with excessive
+ * We select only the first 18 bits to avoid issues with excessive
  * memory use for the page cache XArray. 18 bits should allow the caching
  * of 262144 pages of sequences of readdir entries. Since each page holds
  * 127 readdir entries for a typical 64-bit system, that works out to a
@@ -363,7 +360,7 @@ static pgoff_t nfs_readdir_page_cookie_hash(u64 cookie)
 {
 	if (cookie == 0)
 		return 0;
-	return xxhash(&cookie, sizeof(cookie), 0) & NFS_READDIR_COOKIE_MASK;
+	return hash_64(cookie, 18);
 }
 
 static bool nfs_readdir_page_validate(struct page *page, u64 last_cookie,
Signature · 1 line
2.35.1
#1 lore raw

Hi Trond,

Quoted 9 lines · On Wed, 30 Mar 2022, [email protected] wrote:

From: Trond Myklebust <[email protected]>

Both xxhash() and hash_64() appear to give similarly low collision rates with a standard linearly increasing readdir offset. They both give similarly higher collision rates when applied to ext4's offsets.

So switch to using the standard hash_64().

Thanks for your patch!

fs/nfs/Kconfig config NFS_FS · line 7

Quoted 7 lines
fs/nfs/Kconfig +0 -1
@@ -4,10 +4,6 @@ config NFS_FS
 	depends on INET && FILE_LOCKING && MULTIUSER
 	select LOCKD
 	select SUNRPC
-	select CRYPTO

I'm extremely grateful for this part! ;-)

While updating shmobile_defconfig, I was wondering why I was suddenly asked about all those crypto drivers...

fs/nfs/Kconfig config NFS_FS · line 9

Quoted 6 lines
fs/nfs/Kconfig +0 -3
-	select CRYPTO_HASH
-	select XXHASH
-	select CRYPTO_XXHASH
 	select NFS_ACL_SUPPORT if NFS_V3_ACL
 	help
 	  Choose Y here if you want to access files residing on other

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds