From: "Kanchana P. Sridhar" <kanchanapsridhar2026@gmail.com>
To: hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com,
chengming.zhou@linux.dev, akpm@linux-foundation.org,
linux-mm@kvack.org, herbert@gondor.apana.org.au,
davem@davemloft.net, linux-crypto@vger.kernel.org,
kanchanapsridhar2026@gmail.com, linux-kernel@vger.kernel.org
Cc: rientjes@google.com, willy@infradead.org, senozhatsky@chromium.org
Subject: [PATCH v5 6/9] mm: zswap: Obtain folio's wb_enabled status once in zswap_store().
Date: Mon, 30 Nov 2026 21:37:08 -0800 [thread overview]
Message-ID: <20261201053711.8090-7-kanchanapsridhar2026@gmail.com> (raw)
In-Reply-To: <20261201053711.8090-1-kanchanapsridhar2026@gmail.com>
Instead of querying mem_cgroup_zswap_writeback_enabled() in each call to
zswap_compress() for large folios, obtain the folio memcg's writeback
enabled status once in zswap_store(), and pass it to zswap_store_page(),
which passes it to zswap_compress(), thus eliminating redundant
computes.
Signed-off-by: Kanchana P. Sridhar <kanchanapsridhar2026@gmail.com>
---
mm/zswap.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/mm/zswap.c b/mm/zswap.c
index cdca497ef8db..c0c00696599b 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -890,7 +890,8 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
}
static bool zswap_compress(struct folio *folio, long index,
- struct zswap_entry *entry, struct zswap_pool *pool)
+ struct zswap_entry *entry, struct zswap_pool *pool,
+ bool wb_enabled)
{
struct zswap_comp_ctx *comp_ctx;
struct scatterlist input, output;
@@ -942,12 +943,8 @@ static bool zswap_compress(struct folio *folio, long index,
* to the active LRU list in the case.
*/
if (comp_ret) {
- rcu_read_lock();
- if (!mem_cgroup_zswap_writeback_enabled(folio_memcg(folio))) {
- rcu_read_unlock();
+ if (!wb_enabled)
goto unlock;
- }
- rcu_read_unlock();
comp_ret = 0;
dlen = PAGE_SIZE;
dst = kmap_local_folio(folio, index * PAGE_SIZE);
@@ -1532,7 +1529,8 @@ static void shrink_worker(struct work_struct *w)
static bool zswap_store_page(struct folio *folio, long index,
struct obj_cgroup *objcg,
- struct zswap_pool *pool)
+ struct zswap_pool *pool,
+ bool wb_enabled)
{
swp_entry_t page_swpentry = folio_swap_entry(folio, index);
struct zswap_entry *entry, *old;
@@ -1545,7 +1543,7 @@ static bool zswap_store_page(struct folio *folio, long index,
return false;
}
- if (!zswap_compress(folio, index, entry, pool))
+ if (!zswap_compress(folio, index, entry, pool, wb_enabled))
goto compress_failed;
/*
@@ -1624,6 +1622,7 @@ bool zswap_store(struct folio *folio)
struct mem_cgroup *memcg = NULL;
struct zswap_pool *pool;
bool ret = false;
+ bool wb_enabled;
long index;
VM_WARN_ON_ONCE(!folio_test_locked(folio));
@@ -1658,8 +1657,12 @@ bool zswap_store(struct folio *folio)
mem_cgroup_put(memcg);
}
+ rcu_read_lock();
+ wb_enabled = mem_cgroup_zswap_writeback_enabled(folio_memcg(folio));
+ rcu_read_unlock();
+
for (index = 0; index < nr_pages; ++index) {
- if (!zswap_store_page(folio, index, objcg, pool))
+ if (!zswap_store_page(folio, index, objcg, pool, wb_enabled))
goto put_pool;
}
--
2.39.5
next prev parent reply other threads:[~2026-12-01 5:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 5:37 [PATCH v5 0/9] Batched zswap_store() framework with compression batching Kanchana P. Sridhar
2026-12-01 5:37 ` [PATCH v5 1/9] crypto: acomp - Define a unit_size in struct acomp_req to enable batching. mm: zswap: Set the unit size for zswap to PAGE_SIZE Kanchana P. Sridhar
2026-12-01 5:37 ` [PATCH v5 2/9] crypto: acomp - Add bit to indicate segmentation support Kanchana P. Sridhar
2026-12-01 5:37 ` [PATCH v5 3/9] crypto: acomp - Add trivial segmentation wrapper Kanchana P. Sridhar
2026-12-01 5:37 ` [PATCH v5 4/9] crypto: acomp - Add API to get a compression algorithm's batch-size Kanchana P. Sridhar
2026-12-01 5:37 ` [PATCH v5 5/9] mm: zswap: Store the folio's node id in the zswap_entry Kanchana P. Sridhar
2026-12-01 5:37 ` Kanchana P. Sridhar [this message]
2026-12-01 5:37 ` [PATCH v5 7/9] mm: zswap: Store large folios in batches Kanchana P. Sridhar
2026-12-01 5:37 ` [PATCH v5 8/9] mm: zswap: Refactor and optimize zswap_store_pages() batch operations Kanchana P. Sridhar
2026-12-01 5:37 ` [PATCH v5 9/9] mm: zswap: Batched zswap_compress() for storing large folios in batches Kanchana P. Sridhar
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=20261201053711.8090-7-kanchanapsridhar2026@gmail.com \
--to=kanchanapsridhar2026@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=davem@davemloft.net \
--cc=hannes@cmpxchg.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=rientjes@google.com \
--cc=senozhatsky@chromium.org \
--cc=willy@infradead.org \
--cc=yosry@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
all inboxes | Powered by JetHome®