From: Kairui Song <ryncsn@gmail.com>
To: Chris Li <chrisl@kernel.org>
Cc: linux-mm <linux-mm@kvack.org>,
Andrew Morton <akpm@linux-foundation.org>,
Yu Zhao <yuzhao@google.com>, Wei Xu <weixugc@google.com>,
Matthew Wilcox <willy@infradead.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 1/3] mm, lru_gen: try to prefetch next page when scanning LRU
Date: Fri, 26 Jan 2024 18:31:24 +0800 [thread overview]
Message-ID: <CAMgjq7AMZv7dmhoL_XgROnfHFWhsDDvFhZ--b-jzC47j=z-8ug@mail.gmail.com> (raw)
In-Reply-To: <ZbMDO5mkAFmN2LHz@google.com>
[-- Attachment #1: Type: text/plain, Size: 4102 bytes --]
On Fri, Jan 26, 2024 at 8:56 AM Chris Li <chrisl@kernel.org> wrote:
> On Fri, Jan 26, 2024 at 01:51:44AM +0800, Kairui Song wrote:
> > > > mm/vmscan.c | 30 ++++++++++++++++++++++++++----
> > > > 1 file changed, 26 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > > > index 4f9c854ce6cc..03631cedb3ab 100644
> > > > --- a/mm/vmscan.c
> > > > +++ b/mm/vmscan.c
> > > > @@ -3681,15 +3681,26 @@ static bool inc_min_seq(struct lruvec
*lruvec, int type, bool can_swap)
> > > > /* prevent cold/hot inversion if force_scan is true */
> > > > for (zone = 0; zone < MAX_NR_ZONES; zone++) {
> > > > struct list_head *head =
&lrugen->folios[old_gen][type][zone];
> > > > + struct folio *prev = NULL;
> > > >
> > > > - while (!list_empty(head)) {
> > > > - struct folio *folio = lru_to_folio(head);
> > > > + if (!list_empty(head))
> > > > + prev = lru_to_folio(head);
> > > > +
> > > > + while (prev) {
> > > > + struct folio *folio = prev;
> > > >
> > > >
VM_WARN_ON_ONCE_FOLIO(folio_test_unevictable(folio), folio);
> > > >
VM_WARN_ON_ONCE_FOLIO(folio_test_active(folio), folio);
> > > >
VM_WARN_ON_ONCE_FOLIO(folio_is_file_lru(folio) != type, folio);
> > > > VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio)
!= zone, folio);
> > > >
> > > > + if (unlikely(list_is_first(&folio->lru,
head))) {
> > > > + prev = NULL;
> > > > + } else {
> > > > + prev = lru_to_folio(&folio->lru);
> > > > + prefetchw(&prev->flags);
> > > > + }
> > >
> > > This makes the code flow much harder to follow. Also for architecture
> > > that does not support prefetch, this will be a net loss.
> > >
> > > Can you use refetchw_prev_lru_folio() instead? It will make the code
> > > much easier to follow. It also turns into no-op when prefetch is not
> > > supported.
> > >
> > > Chris
> > >
> >
> > Hi Chris,
> >
> > Thanks for the suggestion.
> >
> > Yes, that's doable, I made it this way because in previous series (V1
> > & V2) I applied the bulk move patch first which needed and introduced
> > the `prev` variable here, so the prefetch logic just used it.
> > For V3 I did a rebase and moved the prefetch commit to be the first
> > one, since it seems to be the most effective one, and just kept the
>
> Maybe something like this? Totally not tested. Feel free to use it any
way you want.
>
> Chris
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 4f9c854ce6cc..2100e786ccc6 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -3684,6 +3684,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int
type, bool can_swap)
>
> while (!list_empty(head)) {
> struct folio *folio = lru_to_folio(head);
> + prefetchw_prev_lru_folio(folio, head, flags);
>
>
VM_WARN_ON_ONCE_FOLIO(folio_test_unevictable(folio), folio);
> VM_WARN_ON_ONCE_FOLIO(folio_test_active(folio),
folio);
> @@ -4346,7 +4347,10 @@ static int scan_folios(struct lruvec *lruvec,
struct scan_control *sc,
>
> while (!list_empty(head)) {
> struct folio *folio = lru_to_folio(head);
> - int delta = folio_nr_pages(folio);
> + int delta;
> +
> + prefetchw_prev_lru_folio(folio, head, flags);
> + delta = folio_nr_pages(folio);
>
>
VM_WARN_ON_ONCE_FOLIO(folio_test_unevictable(folio), folio);
> VM_WARN_ON_ONCE_FOLIO(folio_test_active(folio),
folio);
>
Thanks!
Actually if benefits from 2/3 and 3/3 is trivial compared to the complexity
and not appealing, then let's only keep the prefetch one, which will be
just a one liner change with good result.
[-- Attachment #2: Type: text/html, Size: 5787 bytes --]
next prev parent reply other threads:[~2024-01-26 10:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 18:45 [PATCH v3 0/3] mm, lru_gen: batch update pages when aging Kairui Song
2024-01-23 18:45 ` [PATCH v3 1/3] mm, lru_gen: try to prefetch next page when scanning LRU Kairui Song
2024-01-25 7:32 ` Chris Li
2024-01-25 17:51 ` Kairui Song
2024-01-26 0:56 ` Chris Li
2024-01-26 10:31 ` Kairui Song [this message]
2024-01-26 21:19 ` Chris Li
2024-01-23 18:45 ` [PATCH v3 2/3] mm, lru_gen: batch update counters on aging Kairui Song
2024-01-23 18:45 ` [PATCH v3 3/3] mm, lru_gen: move pages in bulk when aging Kairui Song
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='CAMgjq7AMZv7dmhoL_XgROnfHFWhsDDvFhZ--b-jzC47j=z-8ug@mail.gmail.com' \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=weixugc@google.com \
--cc=willy@infradead.org \
--cc=yuzhao@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