Re: [PATCH v5 2/6] mm/zswap: Support batch writeback in shrink_memcg()

From: Hao Jia

Date: Mon Jun 29 2026 - 21:18:47 EST




On 2026/6/30 08:21, Yosry Ahmed wrote:
On Mon, Jun 29, 2026 at 07:20:28PM +0800, Hao Jia wrote:

static void shrink_worker(struct work_struct *w)
{
struct mem_cgroup *memcg;
- int ret, failures = 0, attempts = 0;
+ int failures = 0, attempts = 0;
unsigned long thr;
+ long ret;
/* Reclaim down to the accept threshold */
thr = zswap_accept_thr_pages();
@@ -1373,7 +1422,7 @@ static void shrink_worker(struct work_struct *w)
goto resched;
}
- ret = shrink_memcg(memcg);
+ ret = shrink_memcg(memcg, NR_ZSWAP_WB_BATCH);
/* drop the extra reference */
mem_cgroup_put(memcg);
@@ -1394,7 +1443,7 @@ static void shrink_worker(struct work_struct *w)
}
++attempts;
- if (ret && ++failures == MAX_RECLAIM_RETRIES)
+ if (ret <= 0 && ++failures == MAX_RECLAIM_RETRIES)
break;
resched:
cond_resched();
@@ -1504,7 +1553,7 @@ bool zswap_store(struct folio *folio)
objcg = get_obj_cgroup_from_folio(folio);
if (objcg && !obj_cgroup_may_zswap(objcg)) {
memcg = get_mem_cgroup_from_objcg(objcg);
- if (shrink_memcg(memcg)) {
+ if (shrink_memcg(memcg, num_node_state(N_NORMAL_MEMORY)) <= 0) {

Why not just 1?

I guess the current behavior will try each node. But this doesn't really
match it, as we may reclaim everything from the first node. Right?


Yes, it just keeps the number the same as before, but the behavior is not exactly the same.

I think it's probably fine to just do 1 here, fairness is not the main
concern in this code path, we're really just trying to free up some
space to free up some space for the incoming page. I doubt these limits
are actually being used extensively anyway, so we can revisit this later
if needed.

Okay, I'll do this in the next version.

Thanks,
Hao

mem_cgroup_put(memcg);
goto put_objcg;
}
--
2.34.1