Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
zram: switch to 64-bit hash for dedup
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Marco Zanin <[email protected]>
Signed-off-by: snnbyyds <[email protected]>
  • Loading branch information
arter97 authored and reocat committed Jan 18, 2024
1 parent bb5905e commit b735622
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions drivers/block/zram/zram_dedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -156,7 +156,7 @@ static struct zram_entry *__zram_dedup_get(struct zram *zram,
}

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;
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions drivers/block/zram/zram_dedup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/zram/zram_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,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;

Expand Down
2 changes: 1 addition & 1 deletion drivers/block/zram/zram_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ enum zram_pageflags {
struct zram_entry {
struct rb_node rb_node;
u32 len;
u32 checksum;
u64 checksum;
unsigned long refcount;
unsigned long handle;
};
Expand Down

0 comments on commit b735622

Please sign in to comment.