Skip to content

Commit a5cd78a

Browse files
sergey-senozhatskyakpm00
authored andcommitted
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/[email protected] Signed-off-by: Sergey Senozhatsky <[email protected]> Cc: Minchan Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b4444a8 commit a5cd78a

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,20 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
16251625
return zram_read_page(zram, bvec->bv_page, index, bio);
16261626
}
16271627

1628+
static int write_same_filled_page(struct zram *zram, unsigned long fill,
1629+
u32 index)
1630+
{
1631+
zram_slot_lock(zram, index);
1632+
zram_set_flag(zram, index, ZRAM_SAME);
1633+
zram_set_handle(zram, index, fill);
1634+
zram_slot_unlock(zram, index);
1635+
1636+
atomic64_inc(&zram->stats.same_pages);
1637+
atomic64_inc(&zram->stats.pages_stored);
1638+
1639+
return 0;
1640+
}
1641+
16281642
static int zram_write_page(struct zram *zram, struct page *page, u32 index)
16291643
{
16301644
int ret = 0;
@@ -1634,22 +1648,18 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
16341648
void *src, *dst, *mem;
16351649
struct zcomp_strm *zstrm;
16361650
unsigned long element = 0;
1637-
enum zram_pageflags flags = 0;
1651+
bool same_filled;
16381652

16391653
/* First, free memory allocated to this slot (if any) */
16401654
zram_slot_lock(zram, index);
16411655
zram_free_page(zram, index);
16421656
zram_slot_unlock(zram, index);
16431657

16441658
mem = kmap_local_page(page);
1645-
if (page_same_filled(mem, &element)) {
1646-
kunmap_local(mem);
1647-
/* Free memory associated with this sector now. */
1648-
flags = ZRAM_SAME;
1649-
atomic64_inc(&zram->stats.same_pages);
1650-
goto out;
1651-
}
1659+
same_filled = page_same_filled(mem, &element);
16521660
kunmap_local(mem);
1661+
if (same_filled)
1662+
return write_same_filled_page(zram, element, index);
16531663

16541664
compress_again:
16551665
zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]);
@@ -1728,21 +1738,16 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
17281738
zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]);
17291739
zs_unmap_object(zram->mem_pool, handle);
17301740
atomic64_add(comp_len, &zram->stats.compr_data_size);
1731-
out:
1741+
17321742
zram_slot_lock(zram, index);
17331743
if (comp_len == PAGE_SIZE) {
17341744
zram_set_flag(zram, index, ZRAM_HUGE);
17351745
atomic64_inc(&zram->stats.huge_pages);
17361746
atomic64_inc(&zram->stats.huge_pages_since);
17371747
}
17381748

1739-
if (flags) {
1740-
zram_set_flag(zram, index, flags);
1741-
zram_set_handle(zram, index, element);
1742-
} else {
1743-
zram_set_handle(zram, index, handle);
1744-
zram_set_obj_size(zram, index, comp_len);
1745-
}
1749+
zram_set_handle(zram, index, handle);
1750+
zram_set_obj_size(zram, index, comp_len);
17461751
zram_slot_unlock(zram, index);
17471752

17481753
/* Update stats */

0 commit comments

Comments
 (0)