All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hao Jia <jiahao.kernel@gmail.com>
To: Yosry Ahmed <yosry@kernel.org>
Cc: akpm@linux-foundation.org, tj@kernel.org, hannes@cmpxchg.org,
	shakeel.butt@linux.dev, mhocko@kernel.org, mkoutny@suse.com,
	nphamcs@gmail.com, chengming.zhou@linux.dev,
	muchun.song@linux.dev, roman.gushchin@linux.dev,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org, Hao Jia <jiahao1@lixiang.com>
Subject: Re: [PATCH v4 1/5] mm/zswap: Extend shrink_memcg() writeback capability
Date: Thu, 25 Jun 2026 19:31:40 +0800	[thread overview]
Message-ID: <1358cfd4-7d3f-1238-e4a8-b2301dc16702@gmail.com> (raw)
In-Reply-To: <CAO9r8zMmnYkXocZ9Fb9DL_rdAHt5xtT_FLMxJD1bHcM3B4wTFw@mail.gmail.com>



On 2026/6/25 00:57, Yosry Ahmed wrote:
>>
>> /*
>>    * Scan up to @nr_to_scan pages across the per-node zswap LRUs of @memcg
>>    * and write back the reclaimable ones.
>>    *
>>    * Since the second-chance algorithm rotates referenced entries to the
>>    * LRU tail, the per-node scan is capped at the current LRU length so
>>    * each entry is scanned at most once per call. It is up to the caller
>>    * to handle retries, deciding whether to scan the next memcg to complete
> 
> Nit: "whether to scan another memcg to complete.."

Will fix in the next version.

> 
>>    * the full iteration, or to rescan the current memcg to drain its zswap
>>    * entries.
>>    *
>>    * Return: The number of compressed bytes written back (>= 0), or -ENOENT
>>    * if @memcg has writeback disabled, is a zombie cgroup, or has empty
>>    * zswap LRUs.
>>    */
>> static long shrink_memcg(struct mem_cgroup *memcg, unsigned long nr_to_scan)
>> {
>>       struct zswap_shrink_walk_arg walk_arg = {
>>           .bytes_written = 0,
>>           .encountered_page_in_swapcache = false,
>>       };
>>       unsigned long nr_remaining = nr_to_scan;
>>       int nid;
>>
>>       if (!mem_cgroup_zswap_writeback_enabled(memcg))
>>           return -ENOENT;
>>
>>       /*
>>        * Skip zombies because their LRUs are reparented and we would be
>>        * reclaiming from the parent instead of the dead memcg.
>>        */
>>       if (memcg && !mem_cgroup_online(memcg))
>>           return -ENOENT;
>>
>>       for_each_node_state(nid, N_NORMAL_MEMORY) {
>>           unsigned long nr_to_walk;
>>
>>           /*
>>            * Cap the walk at the current LRU length to ensure each entry is
>>            * scanned at most once per call. Referenced entries are rotated
>>            * to the tail for a second chance, and this bound prevents them
>>            * from being revisited within a single call. Retries are left to
>>            * the caller, which can choose to rescan the current memcg or
>>            * move on to the next one.
>>            */
> 
> Nit: Make this more concise since it's already explained above.
> 

Will fix in the next version. Thanks a lot for the review!

Thanks,
Hao

> Otherwise this looks good to me, thank you!
> 
>>           nr_to_walk = min(nr_remaining,
>>                    list_lru_count_one(&zswap_list_lru, nid, memcg));
>>           if (!nr_to_walk)
>>               continue;
>>
>>           nr_remaining -= nr_to_walk;
>>           list_lru_walk_one(&zswap_list_lru, nid, memcg, &shrink_memcg_cb,
>>                     &walk_arg, &nr_to_walk);
>>           /* Return the unused share of the budget to the pool. */
>>           nr_remaining += nr_to_walk;
>>
>>           if (!nr_remaining)
>>               break;
>>       }
>>
>>       /* Nothing was scanned: every LRU under @memcg was empty. */
>>       if (nr_remaining == nr_to_scan)
>>           return -ENOENT;
>>
>>       return walk_arg.bytes_written;
>> }
>>


  reply	other threads:[~2026-06-25 11:31 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-18  4:48 [PATCH v4 0/5] mm/zswap: Implement per-cgroup proactive writeback Hao Jia
2026-06-18  4:48 ` [PATCH v4 1/5] mm/zswap: Extend shrink_memcg() writeback capability Hao Jia
2026-06-22 23:33   ` Yosry Ahmed
2026-06-23 13:22     ` Hao Jia
2026-06-23 18:17       ` Yosry Ahmed
2026-06-24 11:58         ` Hao Jia
2026-06-24 16:57           ` Yosry Ahmed
2026-06-25 11:31             ` Hao Jia [this message]
2026-06-18  4:48 ` [PATCH v4 2/5] mm/zswap: Factor writeback loop out of shrink_worker() Hao Jia
2026-06-22 23:36   ` Yosry Ahmed
2026-06-24 11:55     ` Hao Jia
2026-06-24 17:00       ` Yosry Ahmed
2026-06-25 11:28         ` Hao Jia
2026-06-25 17:59           ` Yosry Ahmed
2026-06-26  9:34             ` Hao Jia
2026-06-26 17:09               ` Yosry Ahmed
2026-06-29 11:36                 ` Hao Jia
2026-06-18  4:48 ` [PATCH v4 3/5] mm/zswap: Implement proactive writeback Hao Jia
2026-06-22 23:40   ` Yosry Ahmed
2026-06-18  4:48 ` [PATCH v4 4/5] mm/zswap: Add per-memcg stat for " Hao Jia
2026-06-22 23:42   ` Yosry Ahmed
2026-06-18  4:48 ` [PATCH v4 5/5] selftests/cgroup: Add tests for zswap " Hao Jia
2026-06-21  4:20 ` [PATCH v4 0/5] mm/zswap: Implement per-cgroup " Muchun Song
2026-06-22  6:08   ` Hao Jia
2026-06-22 10:04     ` Youngjun Park
2026-06-22 21:29       ` Yosry Ahmed

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=1358cfd4-7d3f-1238-e4a8-b2301dc16702@gmail.com \
    --to=jiahao.kernel@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=jiahao1@lixiang.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=nphamcs@gmail.com \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=tj@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.