From: jpsollie Date: Thu, 17 Jun 2021 11:42:09 +0000 (+0200) Subject: bcachefs: add bcachefs xxhash support X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=41e633826a1418f3b492d9137d395289e6e67d15;p=linux.git 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 Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/Kconfig b/fs/bcachefs/Kconfig index 151c4b10d5435..bfe7e6c9c0649 100644 --- a/fs/bcachefs/Kconfig +++ b/fs/bcachefs/Kconfig @@ -19,6 +19,7 @@ config BCACHEFS_FS select KEYS select RAID6_PQ select XOR_BLOCKS + select XXHASH select SRCU help The bcachefs filesystem - a modern, copy on write filesystem, with diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h index 6cfb8959d5794..63f7c7c8f390b 100644 --- a/fs/bcachefs/bcachefs_format.h +++ b/fs/bcachefs/bcachefs_format.h @@ -1460,7 +1460,8 @@ enum bch_csum_type { BCH_CSUM_CHACHA20_POLY1305_128 = 4, BCH_CSUM_CRC32C = 5, BCH_CSUM_CRC64 = 6, - BCH_CSUM_NR = 7, + BCH_CSUM_XXHASH = 7, + BCH_CSUM_NR = 8, }; static const unsigned bch_crc_bytes[] = { @@ -1469,6 +1470,7 @@ static const unsigned bch_crc_bytes[] = { [BCH_CSUM_CRC32C] = 4, [BCH_CSUM_CRC64_NONZERO] = 8, [BCH_CSUM_CRC64] = 8, + [BCH_CSUM_XXHASH] = 8, [BCH_CSUM_CHACHA20_POLY1305_80] = 10, [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() \ x(none, 0) \ x(crc32c, 1) \ - x(crc64, 2) + x(crc64, 2) \ + x(xxhash, 3) enum bch_csum_opts { #define x(t, n) BCH_CSUM_OPT_##t = n, diff --git a/fs/bcachefs/checksum.c b/fs/bcachefs/checksum.c index 6c23a9073dbfa..d20924e579bff 100644 --- a/fs/bcachefs/checksum.c +++ b/fs/bcachefs/checksum.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,7 @@ struct bch2_checksum_state { union { u64 seed; + struct xxh64_state h64state; }; unsigned int type; }; @@ -44,6 +46,9 @@ static void bch2_checksum_init(struct bch2_checksum_state *state) case BCH_CSUM_CRC64_NONZERO: state->seed = U64_MAX; break; + case BCH_CSUM_XXHASH: + xxh64_reset(&state->h64state, 0); + break; default: BUG(); } @@ -60,6 +65,8 @@ static u64 bch2_checksum_final(const struct bch2_checksum_state *state) return state->seed ^ U32_MAX; case BCH_CSUM_CRC64_NONZERO: return state->seed ^ U64_MAX; + case BCH_CSUM_XXHASH: + return xxh64_digest(&state->h64state); default: BUG(); } @@ -78,6 +85,9 @@ static void bch2_checksum_update(struct bch2_checksum_state *state, const void * case BCH_CSUM_CRC64: state->seed = crc64_be(state->seed, data, len); break; + case BCH_CSUM_XXHASH: + xxh64_update(&state->h64state, data, len); + break; default: BUG(); } @@ -155,6 +165,7 @@ struct bch_csum bch2_checksum(struct bch_fs *c, unsigned type, case BCH_CSUM_CRC32C_NONZERO: case BCH_CSUM_CRC64_NONZERO: case BCH_CSUM_CRC32C: + case BCH_CSUM_XXHASH: case BCH_CSUM_CRC64: { 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_CRC64_NONZERO: case BCH_CSUM_CRC32C: + case BCH_CSUM_XXHASH: case BCH_CSUM_CRC64: { struct bch2_checksum_state state; diff --git a/fs/bcachefs/checksum.h b/fs/bcachefs/checksum.h index 728b7ef1a1490..6841fb16568a6 100644 --- a/fs/bcachefs/checksum.h +++ b/fs/bcachefs/checksum.h @@ -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; case BCH_CSUM_OPT_crc64: return data ? BCH_CSUM_CRC64 : BCH_CSUM_CRC64_NONZERO; + case BCH_CSUM_OPT_xxhash: + return BCH_CSUM_XXHASH; default: BUG(); }