[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20241118103054.3191944-5-senozhatsky@chromium.org>
Date: Mon, 18 Nov 2024 19:30:35 +0900
From: Sergey Senozhatsky <senozhatsky@...omium.org>
To: Andrew Morton <akpm@...ux-foundation.org>,
Minchan Kim <minchan@...nel.org>
Cc: linux-kernel@...r.kernel.org,
Sergey Senozhatsky <senozhatsky@...omium.org>
Subject: [RFC PATCH 4/8] zram: handle ZRAM_SAME immediately
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.
Signed-off-by: Sergey Senozhatsky <senozhatsky@...omium.org>
---
drivers/block/zram/zram_drv.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index e80b4d15b74b..76ff74a75125 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1625,7 +1625,6 @@ 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;
/* First, free memory allocated to this slot (if any) */
zram_slot_lock(zram, index);
@@ -1635,10 +1634,10 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 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;
+ zram_set_flag(zram, index, ZRAM_SAME);
+ zram_set_handle(zram, index, element);
+ return 0;
}
kunmap_local(mem);
@@ -1719,7 +1718,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);
@@ -1727,13 +1726,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 */
--
2.47.0.338.g60cca15819-goog
Powered by blists - more mailing lists