From: Johannes Weiner <hannes@cmpxchg.org>
To: Nhat Pham <nphamcs@gmail.com>
Cc: akpm@linux-foundation.org, yosryahmed@google.com,
shakeel.butt@linux.dev, linux-mm@kvack.org, kernel-team@meta.com,
linux-kernel@vger.kernel.org, flintglass@gmail.com,
chengming.zhou@linux.dev
Subject: Re: [PATCH v3 1/2] zswap: implement a second chance algorithm for dynamic zswap shrinker
Date: Wed, 7 Aug 2024 07:03:41 -0400 [thread overview]
Message-ID: <20240807110341.GA1726375@cmpxchg.org> (raw)
In-Reply-To: <20240805232243.2896283-2-nphamcs@gmail.com>
On Mon, Aug 05, 2024 at 04:22:42PM -0700, Nhat Pham wrote:
> Current zswap shrinker's heuristics to prevent overshrinking is brittle
> and inaccurate, specifically in the way we decay the protection size
> (i.e making pages in the zswap LRU eligible for reclaim).
>
> We currently decay protection aggressively in zswap_lru_add() calls.
> This leads to the following unfortunate effect: when a new batch of
> pages enter zswap, the protection size rapidly decays to below 25% of
> the zswap LRU size, which is way too low.
>
> We have observed this effect in production, when experimenting with the
> zswap shrinker: the rate of shrinking shoots up massively right after a
> new batch of zswap stores. This is somewhat the opposite of what we want
> originally - when new pages enter zswap, we want to protect both these
> new pages AND the pages that are already protected in the zswap LRU.
>
> Replace existing heuristics with a second chance algorithm
>
> 1. When a new zswap entry is stored in the zswap pool, its referenced
> bit is set.
> 2. When the zswap shrinker encounters a zswap entry with the referenced
> bit set, give it a second chance - only flips the referenced bit and
> rotate it in the LRU.
> 3. If the shrinker encounters the entry again, this time with its
> referenced bit unset, then it can reclaim the entry.
>
> In this manner, the aging of the pages in the zswap LRUs are decoupled
> from zswap stores, and picks up the pace with increasing memory pressure
> (which is what we want).
>
> The second chance scheme allows us to modulate the writeback rate based
> on recent pool activities. Entries that recently entered the pool will
> be protected, so if the pool is dominated by such entries the writeback
> rate will reduce proportionally, protecting the workload's workingset.On
> the other hand, stale entries will be written back quickly, which
> increases the effective writeback rate.
>
> The referenced bit is added at the hole after the `length` field of
> struct zswap_entry, so there is no extra space overhead for this
> algorithm.
>
> We will still maintain the count of swapins, which is consumed and
> subtracted from the lru size in zswap_shrinker_count(), to further
> penalize past overshrinking that led to disk swapins. The idea is that
> had we considered this many more pages in the LRU active/protected, they
> would not have been written back and we would not have had to swapped
> them in.
>
> To test this new heuristics, I built the kernel under a cgroup with
> memory.max set to 2G, on a host with 36 cores:
>
> With the old shrinker:
>
> real: 263.89s
> user: 4318.11s
> sys: 673.29s
> swapins: 227300.5
>
> With the second chance algorithm:
>
> real: 244.85s
> user: 4327.22s
> sys: 664.39s
> swapins: 94663
>
> (average over 5 runs)
>
> We observe an 1.3% reduction in kernel CPU usage, and around 7.2%
> reduction in real time. Note that the number of swapped in pages
> dropped by 58%.
>
> Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Nhat Pham <nphamcs@gmail.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
next prev parent reply other threads:[~2024-08-07 11:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 23:22 [PATCH v3 0/2] improving dynamic zswap shrinker protection scheme Nhat Pham
2024-08-05 23:22 ` [PATCH v3 1/2] zswap: implement a second chance algorithm for dynamic zswap shrinker Nhat Pham
2024-08-06 0:13 ` Yosry Ahmed
2024-08-06 0:34 ` Nhat Pham
2024-08-06 0:34 ` [PATCH v3 1/2] zswap: implement a second chance algorithm for dynamic zswap shrinker (fix) Nhat Pham
2024-08-06 1:07 ` Yosry Ahmed
2024-08-07 11:03 ` Johannes Weiner [this message]
2024-08-05 23:22 ` [PATCH v3 2/2] zswap: track swapins from disk more accurately Nhat Pham
2024-08-06 0:14 ` Yosry Ahmed
2024-08-06 0:47 ` Nhat Pham
2024-08-06 0:45 ` [PATCH v3 2/2] zswap: track swapins from disk more accurately (fix) Nhat Pham
2024-08-07 11:09 ` [PATCH v3 2/2] zswap: track swapins from disk more accurately Johannes Weiner
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=20240807110341.GA1726375@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=flintglass@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=shakeel.butt@linux.dev \
--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