summaryrefslogtreecommitdiff
path: root/fs/bcachefs/checksum.c
diff options
context:
space:
mode:
authorjpsollie <janpieter.sollie@edpnet.be>2021-06-17 13:42:09 +0200
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:07 -0400
commit41e633826a1418f3b492d9137d395289e6e67d15 (patch)
tree85a3d530f3f30e0b3d5ffafac938d73c132845da /fs/bcachefs/checksum.c
parent80ff5d18ee975f201c8913be066ebedf887003f9 (diff)
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>
Diffstat (limited to 'fs/bcachefs/checksum.c')
-rw-r--r--fs/bcachefs/checksum.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/fs/bcachefs/checksum.c b/fs/bcachefs/checksum.c
index 6c23a9073dbf..d20924e579bf 100644
--- a/fs/bcachefs/checksum.c
+++ b/fs/bcachefs/checksum.c
@@ -6,6 +6,7 @@
#include <linux/crc32c.h>
#include <linux/crypto.h>
+#include <linux/xxhash.h>
#include <linux/key.h>
#include <linux/random.h>
#include <linux/scatterlist.h>
@@ -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;