linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yu Zhao <yuzhao@google.com>
To: Minchan Kim <minchan@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org
Subject: Re: [PATCH 1/2] mm: multi-gen LRU: retry folios written back while isolated
Date: Thu, 17 Nov 2022 15:22:42 -0700	[thread overview]
Message-ID: <CAOUHufb_w+X_HprFx_T5fS3ht5YrwsEn=7dBGf0N2v8XHzRCHA@mail.gmail.com> (raw)
In-Reply-To: <Y3Xm8GcFXW4OHXr7@google.com>

On Thu, Nov 17, 2022 at 12:47 AM Minchan Kim <minchan@kernel.org> wrote:
>
> On Tue, Nov 15, 2022 at 06:38:07PM -0700, Yu Zhao 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.
>
> Can we make something like this?

This works for both the active/inactive LRU and MGLRU.

But it's not my prefered way because of these two subtle differences:
1. Folios eligible for retry take an unnecessary round trip below --
they are first added to the LRU list and then removed from there for
retry. For high speed swap devices, the LRU lock contention is already
quite high (>10% in CPU profile under heavy memory pressure). So I'm
hoping we can avoid this round trip.
2. The number of retries of a folio on folio_wb_list is unlimited,
whereas this patch limits the retry to one. So in theory, we can spin
on a bunch of folios that keep failing.

The most ideal solution would be to have the one-off retry logic in
shrink_folio_list(). But right now, that function is very cluttered. I
plan to refactor it (low priority at the moment), and probably after
that, we can add a generic retry for both the active/inactive LRU and
MGLRU. I'll raise its priority if you strongly prefer this. Please
feel free to let me know.

Thanks.


>     shrink_folio_list(struct list_head *folio_list, struct list_head *folio_wb_list, )
>         pageout
>             goto keep
>         ..
>         ..
>
>         keep:
>             if (folio_test_writeback(folio) &&
>                     folio_test_reclaim(folio))
>                 list_add(&folio->lru, &ret_writeback_folio);
>
>     move_folios_to_lru(&folio_list, &folio_wb_list);
>         struct folio *wb_folio = lru_to_folio(folio_wb_list);
>
>         /*
>          * If writeback is already done, move the page into tail.
>          * Otherwise, put the page into head and folio_rotate_reclaimable
>          * will move it to the tail when the writeback is done
>          */
>         if (!folio_test_writeback(wb_folio)) &&
>                     folio_test_reclaim(wb_folio))
>             lruvec_add_folio_tail(lruvec, folio);


  reply	other threads:[~2022-11-17 22:23 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
2022-11-17  7:46 ` Minchan Kim
2022-11-17 22:22   ` Yu Zhao [this message]
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='CAOUHufb_w+X_HprFx_T5fS3ht5YrwsEn=7dBGf0N2v8XHzRCHA@mail.gmail.com' \
    --to=yuzhao@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@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 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).