mirror of
https://github.com/torvalds/linux.git
synced 2026-05-21 05:18:45 +02:00
zram: factor out ZRAM_SAME write
Handling of ZRAM_SAME now uses a goto to the final stages of zram_write_page() plus it introduces a branch and flags variable, which is not making the code any simpler. In reality, we can handle ZRAM_SAME immediately when we detect such pages and remove a goto and a branch. Factor out ZRAM_SAME handling into a separate routine to simplify zram_write_page(). Link: https://lkml.kernel.org/r/20241218063513.297475-4-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
b4444a849f
commit
a5cd78accf
|
|
@ -1625,6 +1625,20 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
|
|||
return zram_read_page(zram, bvec->bv_page, index, bio);
|
||||
}
|
||||
|
||||
static int write_same_filled_page(struct zram *zram, unsigned long fill,
|
||||
u32 index)
|
||||
{
|
||||
zram_slot_lock(zram, index);
|
||||
zram_set_flag(zram, index, ZRAM_SAME);
|
||||
zram_set_handle(zram, index, fill);
|
||||
zram_slot_unlock(zram, index);
|
||||
|
||||
atomic64_inc(&zram->stats.same_pages);
|
||||
atomic64_inc(&zram->stats.pages_stored);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int zram_write_page(struct zram *zram, struct page *page, u32 index)
|
||||
{
|
||||
int ret = 0;
|
||||
|
|
@ -1634,7 +1648,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
|
|||
void *src, *dst, *mem;
|
||||
struct zcomp_strm *zstrm;
|
||||
unsigned long element = 0;
|
||||
enum zram_pageflags flags = 0;
|
||||
bool same_filled;
|
||||
|
||||
/* First, free memory allocated to this slot (if any) */
|
||||
zram_slot_lock(zram, index);
|
||||
|
|
@ -1642,14 +1656,10 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
|
|||
zram_slot_unlock(zram, index);
|
||||
|
||||
mem = kmap_local_page(page);
|
||||
if (page_same_filled(mem, &element)) {
|
||||
kunmap_local(mem);
|
||||
/* Free memory associated with this sector now. */
|
||||
flags = ZRAM_SAME;
|
||||
atomic64_inc(&zram->stats.same_pages);
|
||||
goto out;
|
||||
}
|
||||
same_filled = page_same_filled(mem, &element);
|
||||
kunmap_local(mem);
|
||||
if (same_filled)
|
||||
return write_same_filled_page(zram, element, index);
|
||||
|
||||
compress_again:
|
||||
zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]);
|
||||
|
|
@ -1728,7 +1738,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
|
|||
zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]);
|
||||
zs_unmap_object(zram->mem_pool, handle);
|
||||
atomic64_add(comp_len, &zram->stats.compr_data_size);
|
||||
out:
|
||||
|
||||
zram_slot_lock(zram, index);
|
||||
if (comp_len == PAGE_SIZE) {
|
||||
zram_set_flag(zram, index, ZRAM_HUGE);
|
||||
|
|
@ -1736,13 +1746,8 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
|
|||
atomic64_inc(&zram->stats.huge_pages_since);
|
||||
}
|
||||
|
||||
if (flags) {
|
||||
zram_set_flag(zram, index, flags);
|
||||
zram_set_handle(zram, index, element);
|
||||
} else {
|
||||
zram_set_handle(zram, index, handle);
|
||||
zram_set_obj_size(zram, index, comp_len);
|
||||
}
|
||||
zram_set_handle(zram, index, handle);
|
||||
zram_set_obj_size(zram, index, comp_len);
|
||||
zram_slot_unlock(zram, index);
|
||||
|
||||
/* Update stats */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user