1
0
Fork 0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-01-24 09:13:20 -05:00

bcachefs: add bcachefs xxhash support

xxhash is a much faster algorithm compared to crc32.
could be used to speed up checksum calculation.
xxhash 64-bit only, as it is much faster on 64-bit CPUs compared to xxh32.

Signed-off-by: jpsollie <janpieter.sollie@edpnet.be>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
jpsollie 2021-06-17 13:42:09 +02:00 committed by Kent Overstreet
parent 80ff5d18ee
commit 41e633826a
4 changed files with 20 additions and 2 deletions

View file

@ -19,6 +19,7 @@ config BCACHEFS_FS
select KEYS select KEYS
select RAID6_PQ select RAID6_PQ
select XOR_BLOCKS select XOR_BLOCKS
select XXHASH
select SRCU select SRCU
help help
The bcachefs filesystem - a modern, copy on write filesystem, with The bcachefs filesystem - a modern, copy on write filesystem, with

View file

@ -1460,7 +1460,8 @@ enum bch_csum_type {
BCH_CSUM_CHACHA20_POLY1305_128 = 4, BCH_CSUM_CHACHA20_POLY1305_128 = 4,
BCH_CSUM_CRC32C = 5, BCH_CSUM_CRC32C = 5,
BCH_CSUM_CRC64 = 6, BCH_CSUM_CRC64 = 6,
BCH_CSUM_NR = 7, BCH_CSUM_XXHASH = 7,
BCH_CSUM_NR = 8,
}; };
static const unsigned bch_crc_bytes[] = { static const unsigned bch_crc_bytes[] = {
@ -1469,6 +1470,7 @@ static const unsigned bch_crc_bytes[] = {
[BCH_CSUM_CRC32C] = 4, [BCH_CSUM_CRC32C] = 4,
[BCH_CSUM_CRC64_NONZERO] = 8, [BCH_CSUM_CRC64_NONZERO] = 8,
[BCH_CSUM_CRC64] = 8, [BCH_CSUM_CRC64] = 8,
[BCH_CSUM_XXHASH] = 8,
[BCH_CSUM_CHACHA20_POLY1305_80] = 10, [BCH_CSUM_CHACHA20_POLY1305_80] = 10,
[BCH_CSUM_CHACHA20_POLY1305_128] = 16, [BCH_CSUM_CHACHA20_POLY1305_128] = 16,
}; };
@ -1487,7 +1489,8 @@ static inline _Bool bch2_csum_type_is_encryption(enum bch_csum_type type)
#define BCH_CSUM_OPTS() \ #define BCH_CSUM_OPTS() \
x(none, 0) \ x(none, 0) \
x(crc32c, 1) \ x(crc32c, 1) \
x(crc64, 2) x(crc64, 2) \
x(xxhash, 3)
enum bch_csum_opts { enum bch_csum_opts {
#define x(t, n) BCH_CSUM_OPT_##t = n, #define x(t, n) BCH_CSUM_OPT_##t = n,

View file

@ -6,6 +6,7 @@
#include <linux/crc32c.h> #include <linux/crc32c.h>
#include <linux/crypto.h> #include <linux/crypto.h>
#include <linux/xxhash.h>
#include <linux/key.h> #include <linux/key.h>
#include <linux/random.h> #include <linux/random.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
@ -26,6 +27,7 @@
struct bch2_checksum_state { struct bch2_checksum_state {
union { union {
u64 seed; u64 seed;
struct xxh64_state h64state;
}; };
unsigned int type; unsigned int type;
}; };
@ -44,6 +46,9 @@ static void bch2_checksum_init(struct bch2_checksum_state *state)
case BCH_CSUM_CRC64_NONZERO: case BCH_CSUM_CRC64_NONZERO:
state->seed = U64_MAX; state->seed = U64_MAX;
break; break;
case BCH_CSUM_XXHASH:
xxh64_reset(&state->h64state, 0);
break;
default: default:
BUG(); BUG();
} }
@ -60,6 +65,8 @@ static u64 bch2_checksum_final(const struct bch2_checksum_state *state)
return state->seed ^ U32_MAX; return state->seed ^ U32_MAX;
case BCH_CSUM_CRC64_NONZERO: case BCH_CSUM_CRC64_NONZERO:
return state->seed ^ U64_MAX; return state->seed ^ U64_MAX;
case BCH_CSUM_XXHASH:
return xxh64_digest(&state->h64state);
default: default:
BUG(); BUG();
} }
@ -78,6 +85,9 @@ static void bch2_checksum_update(struct bch2_checksum_state *state, const void *
case BCH_CSUM_CRC64: case BCH_CSUM_CRC64:
state->seed = crc64_be(state->seed, data, len); state->seed = crc64_be(state->seed, data, len);
break; break;
case BCH_CSUM_XXHASH:
xxh64_update(&state->h64state, data, len);
break;
default: default:
BUG(); BUG();
} }
@ -155,6 +165,7 @@ struct bch_csum bch2_checksum(struct bch_fs *c, unsigned type,
case BCH_CSUM_CRC32C_NONZERO: case BCH_CSUM_CRC32C_NONZERO:
case BCH_CSUM_CRC64_NONZERO: case BCH_CSUM_CRC64_NONZERO:
case BCH_CSUM_CRC32C: case BCH_CSUM_CRC32C:
case BCH_CSUM_XXHASH:
case BCH_CSUM_CRC64: { case BCH_CSUM_CRC64: {
struct bch2_checksum_state state; struct bch2_checksum_state state;
@ -206,6 +217,7 @@ static struct bch_csum __bch2_checksum_bio(struct bch_fs *c, unsigned type,
case BCH_CSUM_CRC32C_NONZERO: case BCH_CSUM_CRC32C_NONZERO:
case BCH_CSUM_CRC64_NONZERO: case BCH_CSUM_CRC64_NONZERO:
case BCH_CSUM_CRC32C: case BCH_CSUM_CRC32C:
case BCH_CSUM_XXHASH:
case BCH_CSUM_CRC64: { case BCH_CSUM_CRC64: {
struct bch2_checksum_state state; struct bch2_checksum_state state;

View file

@ -83,6 +83,8 @@ static inline enum bch_csum_type bch2_csum_opt_to_type(enum bch_csum_opts type,
return data ? BCH_CSUM_CRC32C : BCH_CSUM_CRC32C_NONZERO; return data ? BCH_CSUM_CRC32C : BCH_CSUM_CRC32C_NONZERO;
case BCH_CSUM_OPT_crc64: case BCH_CSUM_OPT_crc64:
return data ? BCH_CSUM_CRC64 : BCH_CSUM_CRC64_NONZERO; return data ? BCH_CSUM_CRC64 : BCH_CSUM_CRC64_NONZERO;
case BCH_CSUM_OPT_xxhash:
return BCH_CSUM_XXHASH;
default: default:
BUG(); BUG();
} }