From: Nhat Pham <nphamcs@gmail.com>
To: Takero Funaki <flintglass@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
Yosry Ahmed <yosryahmed@google.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
Jonathan Corbet <corbet@lwn.net>,
Andrew Morton <akpm@linux-foundation.org>,
Domenico Cerasuolo <cerasuolodomenico@gmail.com>,
linux-mm@kvack.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/3] mm: zswap: fix global shrinker memcg iteration
Date: Thu, 13 Jun 2024 09:08:05 -0700 [thread overview]
Message-ID: <CAKEwX=MiMMCrQCq2j1DDOR_U6==6pwbqqCnsaoigQ4aEqhgaaw@mail.gmail.com> (raw)
In-Reply-To: <20240608155316.451600-2-flintglass@gmail.com>
On Sat, Jun 8, 2024 at 8:53 AM Takero Funaki <flintglass@gmail.com> wrote:
>
> This patch fixes an issue where the zswap global shrinker stopped
> iterating through the memcg tree.
>
> The problem was that `shrink_worker()` would stop iterating when a memcg
> was being offlined and restart from the tree root. Now, it properly
> handles the offlining memcg and continues shrinking with the next memcg.
>
> This patch also modified handing of the lock for offlined memcg cleaner
> to adapt the change in the iteration, and avoid negligibly rare skipping
> of a memcg from shrink iteration.
>
Honestly, I think this version is even more complicated than v0 :)
Hmmm how about this:
do {
spin_lock(&zswap_pools_lock);
do {
/* no offline caller has been called to memcg yet */
if (memcg == zswap_next_shrink) {
zswap_next_shrink = mem_cgroup_iter(NULL, zswap_next_shrink, NULL);
memcg = zswap_next_shrink;
if (!memcg && ++failure > MAX_FAILURE) {
spin_unlock(&zswap_pools_lock);
return;
}
} while (!zswap_next_shrink || !mem_cgroup_tryget_online(zswap_next_shrink))
spin_unlock(&zswap_pools_lock);
/* proceed with reclaim */
} while (...)
This should achieve all the goals right?
1. No restarting from the top, unless we have traversed the entire hierarchy.
2. No skipping over zswap_next_shrink updated by the memcg offline cleaner.
3. No leaving offlined zswap_next_shrink hanging (and blocking memcg
killing indefinitely).
4. No long running loop unnecessarily. If you want to be extra safe,
we can put a max number of retries on the offline memcg case too (and
restart from the top).
5. At the end of the inner loop, you are guaranteed to hold at least
one reference to memcg (and perhaps 2, if zswap_next_shrink is not
updated by the cleaner).
5. At the end of the inner loop, the selected memcg is known to not
have its cleaner started yet (since it is online with zswap_pools_lock
held). Our selection will undo the cleaner and hold the memcg hostage
forever.
Is there anything that I'm missing? We are not dropping the lock for
the entirety of the inner loop, but honestly I'm fine with this trade
off, for the sake of simplicity :)
If you want it to be even more readable, feel free to refactor the
inner loop into a helper function (but it's probably redundant since
it's only used once).
next prev parent reply other threads:[~2024-06-13 16:08 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-08 15:53 [PATCH v1 0/3] mm: zswap: global shrinker fix and proactive shrink Takero Funaki
2024-06-08 15:53 ` [PATCH v1 1/3] mm: zswap: fix global shrinker memcg iteration Takero Funaki
2024-06-10 19:16 ` Yosry Ahmed
2024-06-11 14:50 ` Takero Funaki
2024-06-11 18:26 ` Nhat Pham
2024-06-11 23:03 ` Shakeel Butt
2024-06-12 18:16 ` Takero Funaki
2024-06-12 18:28 ` Yosry Ahmed
2024-06-13 2:13 ` Takero Funaki
2024-06-13 2:18 ` Yosry Ahmed
2024-06-13 2:35 ` Takero Funaki
2024-06-13 2:57 ` Yosry Ahmed
2024-06-13 15:04 ` Nhat Pham
2024-06-13 16:49 ` Shakeel Butt
2024-06-14 4:39 ` Takero Funaki
2024-06-13 16:08 ` Nhat Pham [this message]
2024-06-13 16:09 ` Nhat Pham
2024-06-08 15:53 ` [PATCH v1 2/3] mm: zswap: fix global shrinker error handling logic Takero Funaki
2024-06-10 20:27 ` Yosry Ahmed
2024-06-11 15:21 ` Takero Funaki
2024-06-11 15:51 ` Nhat Pham
2024-06-11 18:15 ` Nhat Pham
2024-06-08 15:53 ` [PATCH v1 3/3] mm: zswap: proactive shrinking before pool size limit is hit Takero Funaki
2024-06-13 15:13 ` Nhat Pham
2024-06-11 18:10 ` [PATCH v1 0/3] mm: zswap: global shrinker fix and proactive shrink Nhat Pham
2024-06-13 15:22 ` Nhat Pham
2024-06-14 4:09 ` Takero Funaki
2024-06-14 22:34 ` Nhat Pham
2024-06-14 22:48 ` Nhat Pham
2024-06-15 0:19 ` Yosry Ahmed
2024-06-20 1:03 ` Takero Funaki
2024-06-20 22:45 ` Nhat Pham
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='CAKEwX=MiMMCrQCq2j1DDOR_U6==6pwbqqCnsaoigQ4aEqhgaaw@mail.gmail.com' \
--to=nphamcs@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cerasuolodomenico@gmail.com \
--cc=chengming.zhou@linux.dev \
--cc=corbet@lwn.net \
--cc=flintglass@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=yosryahmed@google.com \
/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