diff --git a/utils/src/format.h b/utils/src/format.h index 8418a638..ac05fecf 100644 --- a/utils/src/format.h +++ b/utils/src/format.h @@ -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. diff --git a/utils/src/hash.h b/utils/src/hash.h new file mode 100644 index 00000000..9b169877 --- /dev/null +++ b/utils/src/hash.h @@ -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 diff --git a/utils/src/leaf_item_hash.c b/utils/src/leaf_item_hash.c index 4955b1b2..b2946d4b 100644 --- a/utils/src/leaf_item_hash.c +++ b/utils/src/leaf_item_hash.c @@ -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; }