scoutfs-utils: switch to using fnv1a for hashing

Track the scoutfs module's switch to FNV1a for hashing.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2020-07-02 15:15:17 -07:00
committed by Zach Brown
parent 9bb32b8003
commit 35d1ad1422
3 changed files with 54 additions and 4 deletions

View File

@@ -328,11 +328,12 @@ struct scoutfs_bloom_block {
* before the bloom filters fill up and start returning excessive false
* positives.
*/
#define SCOUTFS_FOREST_BLOOM_NRS 7
#define SCOUTFS_FOREST_BLOOM_NRS 3
#define SCOUTFS_FOREST_BLOOM_BITS \
(((SCOUTFS_BLOCK_LG_SIZE - sizeof(struct scoutfs_bloom_block)) / \
member_sizeof(struct scoutfs_bloom_block, bits[0])) * \
member_sizeof(struct scoutfs_bloom_block, bits[0]) * 8) \
member_sizeof(struct scoutfs_bloom_block, bits[0]) * 8)
#define SCOUTFS_FOREST_BLOOM_FUNC_BITS (SCOUTFS_BLOCK_LG_SHIFT + 3)
/*
* Keys are first sorted by major key zones.

49
utils/src/hash.h Normal file
View File

@@ -0,0 +1,49 @@
#ifndef _SCOUTFS_HASH_H_
#define _SCOUTFS_HASH_H_
/*
* We're using FNV1a for now. It's fine. Ish.
*
* The longer term plan is xxh3 but it looks like it'll take just a bit
* more time to be declared stable and then it needs to be ported to the
* kernel.
*
* - https://fastcompression.blogspot.com/2019/03/presenting-xxh3.html
* - https://github.com/Cyan4973/xxHash/releases/tag/v0.7.4
*/
static inline u32 fnv1a32(const void *data, unsigned int len)
{
u32 hash = 0x811c9dc5;
while (len--) {
hash ^= *(u8 *)(data++);
hash *= 0x01000193;
}
return hash;
}
static inline u64 fnv1a64(const void *data, unsigned int len)
{
u64 hash = 0xcbf29ce484222325;
while (len--) {
hash ^= *(u8 *)(data++);
hash *= 0x100000001b3;
}
return hash;
}
static inline u32 scoutfs_hash32(const void *data, unsigned int len)
{
return fnv1a32(data, len);
}
static inline u64 scoutfs_hash64(const void *data, unsigned int len)
{
return fnv1a64(data, len);
}
#endif

View File

@@ -1,7 +1,7 @@
#include "sparse.h"
#include "util.h"
#include "format.h"
#include "crc.h"
#include "hash.h"
#include "leaf_item_hash.h"
/*
@@ -10,7 +10,7 @@
int leaf_item_hash_ind(struct scoutfs_key *key)
{
return crc32c(~0, key, sizeof(struct scoutfs_key)) %
return scoutfs_hash32(key, sizeof(struct scoutfs_key)) %
SCOUTFS_BTREE_LEAF_ITEM_HASH_NR;
}