From e87044e4c9dfaad02f7f3fdc5f6a1fc073faa00e Mon Sep 17 00:00:00 2001 From: Juhyung Park Date: Sun, 3 Oct 2021 17:38:24 +0900 Subject: [PATCH] zram: switch to 64-bit hash for dedup The original dedup code does not handle collision from the observation that it practically does not happen. For additional peace of mind, use a bigger hash size for reducing the possibility of collision even further. Signed-off-by: Juhyung Park Signed-off-by: Alexander Winkowski Change-Id: I4543ce22d69a21b2edcc72a72790d2c55a9e312c --- drivers/block/zram/zram_dedup.c | 12 ++++++------ drivers/block/zram/zram_dedup.h | 8 ++++---- drivers/block/zram/zram_drv.c | 2 +- drivers/block/zram/zram_drv.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/block/zram/zram_dedup.c b/drivers/block/zram/zram_dedup.c index c7e6b890352f..22f2312e18c4 100755 --- a/drivers/block/zram/zram_dedup.c +++ b/drivers/block/zram/zram_dedup.c @@ -28,13 +28,13 @@ u64 zram_dedup_meta_size(struct zram *zram) return (u64)atomic64_read(&zram->stats.meta_data_size); } -static u32 zram_dedup_checksum(unsigned char *mem) +static u64 zram_dedup_checksum(unsigned char *mem) { - return xxhash(mem, PAGE_SIZE, 0); + return xxh64(mem, PAGE_SIZE, 0); } void zram_dedup_insert(struct zram *zram, struct zram_entry *new, - u32 checksum) + u64 checksum) { struct zram_hash *hash; struct rb_root *rb_root; @@ -91,7 +91,7 @@ static unsigned long zram_dedup_put(struct zram *zram, struct zram_entry *entry) { struct zram_hash *hash; - u32 checksum; + u64 checksum; unsigned long val; checksum = entry->checksum; @@ -156,7 +156,7 @@ again: } static struct zram_entry *zram_dedup_get(struct zram *zram, - unsigned char *mem, u32 checksum) + unsigned char *mem, u64 checksum) { struct zram_hash *hash; struct zram_entry *entry; @@ -182,7 +182,7 @@ static struct zram_entry *zram_dedup_get(struct zram *zram, } struct zram_entry *zram_dedup_find(struct zram *zram, struct page *page, - u32 *checksum) + u64 *checksum) { void *mem; struct zram_entry *entry; diff --git a/drivers/block/zram/zram_dedup.h b/drivers/block/zram/zram_dedup.h index 8ab267b0b956..d8ee79654604 100755 --- a/drivers/block/zram/zram_dedup.h +++ b/drivers/block/zram/zram_dedup.h @@ -10,9 +10,9 @@ u64 zram_dedup_dup_size(struct zram *zram); u64 zram_dedup_meta_size(struct zram *zram); void zram_dedup_insert(struct zram *zram, struct zram_entry *new, - u32 checksum); + u64 checksum); struct zram_entry *zram_dedup_find(struct zram *zram, struct page *page, - u32 *checksum); + u64 *checksum); void zram_dedup_init_entry(struct zram *zram, struct zram_entry *entry, unsigned long handle, unsigned int len); @@ -26,9 +26,9 @@ static inline u64 zram_dedup_dup_size(struct zram *zram) { return 0; } static inline u64 zram_dedup_meta_size(struct zram *zram) { return 0; } static inline void zram_dedup_insert(struct zram *zram, struct zram_entry *new, - u32 checksum) { } + u64 checksum) { } static inline struct zram_entry *zram_dedup_find(struct zram *zram, - struct page *page, u32 *checksum) { return NULL; } + struct page *page, u64 *checksum) { return NULL; } static inline void zram_dedup_init_entry(struct zram *zram, struct zram_entry *entry, unsigned long handle, diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 979e0f919bdc..357bde879e7c 100755 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -3093,7 +3093,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, void *src, *dst, *mem; struct zcomp_strm *zstrm; struct page *page = bvec->bv_page; - u32 checksum; + u64 checksum; unsigned long element = 0; enum zram_pageflags flags = 0; #ifdef CONFIG_ZRAM_LRU_WRITEBACK diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index f533a342d9d4..4f4310fab48d 100755 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -68,7 +68,7 @@ enum zram_pageflags { struct zram_entry { struct rb_node rb_node; u32 len; - u32 checksum; + u64 checksum; unsigned long refcount; unsigned long handle; };