Skip to content

Commit 277f74b

Browse files
arter97DhineshCool
authored andcommitted
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 <qkrwngud825@gmail.com> Signed-off-by: Marco Zanin <mrczn.bb@gmail.com> Signed-off-by: snnbyyds <snnbyyds@gmail.com>
1 parent 9864f4c commit 277f74b

5 files changed

Lines changed: 14 additions & 13 deletions

File tree

drivers/block/zram/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ config ZRAM
1717
config ZRAM_DEDUP
1818
bool "Deduplication support for ZRAM data"
1919
depends on ZRAM
20+
select XXHASH
2021
default n
2122
help
2223
Deduplicate ZRAM data to reduce amount of memory consumption.

drivers/block/zram/zram_dedup.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
#include <linux/vmalloc.h>
11-
#include <linux/jhash.h>
11+
#include <linux/xxhash.h>
1212
#include <linux/highmem.h>
1313

1414
#include "zram_drv.h"
@@ -28,13 +28,13 @@ u64 zram_dedup_meta_size(struct zram *zram)
2828
return (u64)atomic64_read(&zram->stats.meta_data_size);
2929
}
3030

31-
static u32 zram_dedup_checksum(unsigned char *mem)
31+
static u64 zram_dedup_checksum(unsigned char *mem)
3232
{
33-
return jhash(mem, PAGE_SIZE, 0);
33+
return xxh64(mem, PAGE_SIZE, 0);
3434
}
3535

3636
void zram_dedup_insert(struct zram *zram, struct zram_entry *new,
37-
u32 checksum)
37+
u64 checksum)
3838
{
3939
struct zram_hash *hash;
4040
struct rb_root *rb_root;
@@ -91,7 +91,7 @@ static unsigned long zram_dedup_put(struct zram *zram,
9191
struct zram_entry *entry)
9292
{
9393
struct zram_hash *hash;
94-
u32 checksum;
94+
u64 checksum;
9595
unsigned long val;
9696

9797
checksum = entry->checksum;
@@ -156,7 +156,7 @@ static struct zram_entry *__zram_dedup_get(struct zram *zram,
156156
}
157157

158158
static struct zram_entry *zram_dedup_get(struct zram *zram,
159-
unsigned char *mem, u32 checksum)
159+
unsigned char *mem, u64 checksum)
160160
{
161161
struct zram_hash *hash;
162162
struct zram_entry *entry;
@@ -182,7 +182,7 @@ static struct zram_entry *zram_dedup_get(struct zram *zram,
182182
}
183183

184184
struct zram_entry *zram_dedup_find(struct zram *zram, struct page *page,
185-
u32 *checksum)
185+
u64 *checksum)
186186
{
187187
void *mem;
188188
struct zram_entry *entry;

drivers/block/zram/zram_dedup.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ u64 zram_dedup_dup_size(struct zram *zram);
1010
u64 zram_dedup_meta_size(struct zram *zram);
1111

1212
void zram_dedup_insert(struct zram *zram, struct zram_entry *new,
13-
u32 checksum);
13+
u64 checksum);
1414
struct zram_entry *zram_dedup_find(struct zram *zram, struct page *page,
15-
u32 *checksum);
15+
u64 *checksum);
1616

1717
void zram_dedup_init_entry(struct zram *zram, struct zram_entry *entry,
1818
unsigned long handle, unsigned int len);
@@ -26,9 +26,9 @@ static inline u64 zram_dedup_dup_size(struct zram *zram) { return 0; }
2626
static inline u64 zram_dedup_meta_size(struct zram *zram) { return 0; }
2727

2828
static inline void zram_dedup_insert(struct zram *zram, struct zram_entry *new,
29-
u32 checksum) { }
29+
u64 checksum) { }
3030
static inline struct zram_entry *zram_dedup_find(struct zram *zram,
31-
struct page *page, u32 *checksum) { return NULL; }
31+
struct page *page, u64 *checksum) { return NULL; }
3232

3333
static inline void zram_dedup_init_entry(struct zram *zram,
3434
struct zram_entry *entry, unsigned long handle,

drivers/block/zram/zram_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
14351435
void *src, *dst, *mem;
14361436
struct zcomp_strm *zstrm;
14371437
struct page *page = bvec->bv_page;
1438-
u32 checksum;
1438+
u64 checksum;
14391439
unsigned long element = 0;
14401440
enum zram_pageflags flags = 0;
14411441

drivers/block/zram/zram_drv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ enum zram_pageflags {
6262
struct zram_entry {
6363
struct rb_node rb_node;
6464
u32 len;
65-
u32 checksum;
65+
u64 checksum;
6666
unsigned long refcount;
6767
unsigned long handle;
6868
};

0 commit comments

Comments
 (0)