From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Minchan Kim <minchan@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: [PATCHv2 3/7] zram: factor out ZRAM_SAME write
Date: Wed, 18 Dec 2024 15:34:20 +0900 [thread overview]
Message-ID: <20241218063513.297475-4-senozhatsky@chromium.org> (raw)
In-Reply-To: <20241218063513.297475-1-senozhatsky@chromium.org>
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().
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
drivers/block/zram/zram_drv.c | 37 ++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 8c71ddd17024..89f3aaa23329 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1624,6 +1624,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;
@@ -1633,7 +1647,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);
@@ -1641,14 +1655,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]);
@@ -1727,7 +1737,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);
@@ -1735,13 +1745,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.1.613.gc27f4b7a9f-goog
next prev parent reply other threads:[~2024-12-18 6:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-18 6:34 [PATCHv2 0/7] zram: split page type read/write handling Sergey Senozhatsky
2024-12-18 6:34 ` [PATCHv2 1/7] zram: free slot memory early during write Sergey Senozhatsky
2024-12-18 6:34 ` [PATCHv2 2/7] zram: remove entry element member Sergey Senozhatsky
2024-12-18 6:34 ` Sergey Senozhatsky [this message]
2024-12-18 6:34 ` [PATCHv2 4/7] zram: factor out ZRAM_HUGE write Sergey Senozhatsky
2024-12-18 6:34 ` [PATCHv2 5/7] zram: factor out different page types read Sergey Senozhatsky
2024-12-18 6:34 ` [PATCHv2 6/7] zram: use zram_read_from_zspool() in writeback Sergey Senozhatsky
2024-12-18 6:34 ` [PATCHv2 7/7] zram: cond_resched() in writeback loop Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241218063513.297475-4-senozhatsky@chromium.org \
--to=senozhatsky@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox