From: Yu Zhao <yuzhao@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH 1/2] mm: multi-gen LRU: retry folios written back while isolated
Date: Wed, 16 Nov 2022 17:12:58 -0700 [thread overview]
Message-ID: <CAOUHufYA8_qG_hYvwnv8m6G5H8D+=9zhxB7PXP3rh+3+dszbYg@mail.gmail.com> (raw)
In-Reply-To: <20221116145952.3a88ac84ea0b6c5dba1056df@linux-foundation.org>
On Wed, Nov 16, 2022 at 3:59 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Tue, 15 Nov 2022 18:38:07 -0700 Yu Zhao <yuzhao@google.com> wrote:
>
> > The page reclaim isolates a batch of folios from the tail of one of
> > the LRU lists and works on those folios one by one. For a suitable
> > swap-backed folio, if the swap device is async, it queues that folio
> > for writeback. After the page reclaim finishes an entire batch, it
> > puts back the folios it queued for writeback to the head of the
> > original LRU list.
> >
> > In the meantime, the page writeback flushes the queued folios also by
> > batches. Its batching logic is independent from that of the page
> > reclaim. For each of the folios it writes back, the page writeback
> > calls folio_rotate_reclaimable() which tries to rotate a folio to the
> > tail.
> >
> > folio_rotate_reclaimable() only works for a folio after the page
> > reclaim has put it back. If an async swap device is fast enough, the
> > page writeback can finish with that folio while the page reclaim is
> > still working on the rest of the batch containing it. In this case,
> > that folio will remain at the head and the page reclaim will not retry
> > it before reaching there.
> >
> > This patch adds a retry to evict_folios(). After evict_folios() has
> > finished an entire batch and before it puts back folios it cannot free
> > immediately, it retries those that may have missed the rotation.
> >
> > Before this patch, ~60% of folios swapped to an Intel Optane missed
> > folio_rotate_reclaimable(). After this patch, ~99% of missed folios
> > were reclaimed upon retry.
> >
> > This problem affects relatively slow async swap devices like Samsung
> > 980 Pro much less and does not affect sync swap devices like zram or
> > zswap at all.
>
> As I understand it, this approach has an implicit assumption that by
> the time evict_folios() has completed its first pass, write IOs will
> have completed and the resulting folios are available for processing on
> evict_folios()'s second pass, yes?
Correct.
> If so, it all kinda works by luck of timing.
Yes, it's betting on luck. But it's a very good bet because the race
window on the second pass is probably 100 times smaller.
The race window on the first pass is the while() loop in
shrink_folio_list(), and it has a lot to work on. The race window on
the second pass is a simple list_for_each_entry_safe_reverse() loop.
This small race window is closed immediately after we put the folios
that are still under writeback back on the LRU list. Then we call
shrink_folio_list() again for the retry.
> If the swap device is
> even slower, the number of folios which are unavailable on the second
> pass will increase?
Correct.
> Can we make this more deterministic? For example change evict_folios()
> to recognize this situation and to then do folio_rotate_reclaimable()'s
> work for it? Or if that isn't practical, do something else?
There are multiple options, none of them is a better tradeoff:
1) the page reclaim telling the page writeback exactly when to flush.
pro: more reliable
con: the page reclaim doesn't know better
2) adding a synchronization mechanism between the two
pro: more reliable
con: a lot more complexity
3) unlock folios and submit bio after they are put back on LRU (my
second choice)
pro: more reliable
con: more complexity (within mm)
> (Is folio_rotate_reclaimable() actually useful? That concept must be
> 20 years old. What breaks if we just delete it and leave the pages
> wherever they are?)
Most people use zram (with rw_page) or zswap nowadays, and they don't
need folio_rotate_reclaimable(). But we still need that function to
support swapping to SSD. (Optane is discontinued.)
next prev parent reply other threads:[~2022-11-17 0:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-16 1:38 [PATCH 1/2] mm: multi-gen LRU: retry folios written back while isolated Yu Zhao
2022-11-16 1:38 ` [PATCH 2/2] mm: multi-gen LRU: remove NULL checks on NODE_DATA() Yu Zhao
2022-11-16 3:07 ` [PATCH 1/2] mm: multi-gen LRU: retry folios written back while isolated Yin, Fengwei
2022-11-16 3:55 ` Yu Zhao
2022-11-16 22:59 ` Andrew Morton
2022-11-17 0:12 ` Yu Zhao [this message]
2022-11-17 7:46 ` Minchan Kim
2022-11-17 22:22 ` Yu Zhao
2022-11-18 1:26 ` Minchan Kim
2022-11-18 1:40 ` Yu Zhao
2022-11-18 21:25 ` Minchan Kim
2022-11-18 21:51 ` Yu Zhao
2022-11-18 22:33 ` Minchan Kim
2022-11-18 23:21 ` Yu Zhao
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='CAOUHufYA8_qG_hYvwnv8m6G5H8D+=9zhxB7PXP3rh+3+dszbYg@mail.gmail.com' \
--to=yuzhao@google.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).