From: Nhat Pham <nphamcs@gmail.com>
To: Yu Zhao <yuzhao@google.com>
Cc: akpm@linux-foundation.org, hannes@cmpxchg.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
bfoster@redhat.com, willy@infradead.org, kernel-team@meta.com
Subject: Re: [PATCH v2 2/4] workingset: refactor LRU refault to expose refault recency check
Date: Thu, 8 Dec 2022 10:07:49 -0800 [thread overview]
Message-ID: <CAKEwX=NwbtFeVyL+J+d8hLeRhoBgfhof+w9_heN++J09XToxCg@mail.gmail.com> (raw)
In-Reply-To: <CAOUHufZ6vehkF5CN-SvgKGmsTCVUgXHmZe4=sOojdQ5Qd9jb+g@mail.gmail.com>
On Mon, Dec 5, 2022 at 6:26 PM Yu Zhao <yuzhao@google.com> wrote:
>
> On Mon, Dec 5, 2022 at 7:22 PM Nhat Pham <nphamcs@gmail.com> wrote:
> >
> > On Mon, Dec 5, 2022 at 5:29 PM Yu Zhao <yuzhao@google.com> wrote:
> > >
> > > On Mon, Dec 5, 2022 at 6:19 PM Nhat Pham <nphamcs@gmail.com> wrote:
> > > >
> > > > On Mon, Dec 5, 2022 at 3:49 PM Yu Zhao <yuzhao@google.com> wrote:
> > > > >
> > > > > On Mon, Dec 5, 2022 at 10:51 AM Nhat Pham <nphamcs@gmail.com> wrote:
> > > > > >
> > > > > > In preparation for computing recently evicted pages in cachestat,
> > > > > > refactor workingset_refault and lru_gen_refault to expose a helper
> > > > > > function that would test if an evicted page is recently evicted.
> > > > > >
> > > > > > Signed-off-by: Nhat Pham <nphamcs@gmail.com>
> > > > > > ---
> > > > > > include/linux/swap.h | 1 +
> > > > > > mm/workingset.c | 143 +++++++++++++++++++++++++++++--------------
> > > > > > 2 files changed, 99 insertions(+), 45 deletions(-)
> > > > > >
> > > > > > diff --git a/include/linux/swap.h b/include/linux/swap.h
> > > > > > index a18cf4b7c724..dae6f6f955eb 100644
> > > > > > --- a/include/linux/swap.h
> > > > > > +++ b/include/linux/swap.h
> > > > > > @@ -361,6 +361,7 @@ static inline void folio_set_swap_entry(struct folio *folio, swp_entry_t entry)
> > > > > > }
> > > > > >
> > > > > > /* linux/mm/workingset.c */
> > > > > > +bool workingset_test_recent(void *shadow, bool file, bool *workingset);
> > > > > > void workingset_age_nonresident(struct lruvec *lruvec, unsigned long nr_pages);
> > > > > > void *workingset_eviction(struct folio *folio, struct mem_cgroup *target_memcg);
> > > > > > void workingset_refault(struct folio *folio, void *shadow);
> > > > > > diff --git a/mm/workingset.c b/mm/workingset.c
> > > > > > index 79585d55c45d..44b331ce3040 100644
> > > > > > --- a/mm/workingset.c
> > > > > > +++ b/mm/workingset.c
> > > > > > @@ -244,6 +244,30 @@ static void *lru_gen_eviction(struct folio *folio)
> > > > > > return pack_shadow(mem_cgroup_id(memcg), pgdat, token, refs);
> > > > > > }
> > > > > >
> > > > > > +/*
> > > > > > + * Test if the folio is recently evicted.
> > > > > > + *
> > > > > > + * As a side effect, also populates the references with
> > > > > > + * values unpacked from the shadow of the evicted folio.
> > > > > > + */
> > > > > > +static bool lru_gen_test_recent(void *shadow, bool file, int *memcgid,
> > > > > > + struct pglist_data **pgdat, unsigned long *token, bool *workingset)
> > > > > > +{
> > > > > > + struct mem_cgroup *eviction_memcg;
> > > > > > + struct lruvec *lruvec;
> > > > > > + struct lru_gen_struct *lrugen;
> > > > > > + unsigned long min_seq;
> > > > > > +
> > > > > > + unpack_shadow(shadow, memcgid, pgdat, token, workingset);
> > > > > > + eviction_memcg = mem_cgroup_from_id(*memcgid);
> > > > > > +
> > > > > > + lruvec = mem_cgroup_lruvec(eviction_memcg, *pgdat);
> > > > > > + lrugen = &lruvec->lrugen;
> > > > > > +
> > > > > > + min_seq = READ_ONCE(lrugen->min_seq[file]);
> > > > > > + return !((*token >> LRU_REFS_WIDTH) != (min_seq & (EVICTION_MASK >> LRU_REFS_WIDTH)));
> > > > > > +}
> > > > >
> > > > > Nit: not refactoring actually looks cleaner to me -- there are only a
> > > > > few lines of duplicated code and you can get rid of 4 parameters
> > > > > including the unused workingset in the next patch.
> > > >
> > > > (resending this because I forgot to forward to the rest of the
> > > > group!)
> > > >
> > > > Thanks for the comment, Yu!
> > > >
> > > > Personally, I prefer refactoring this piece of logic - I do think that
> > > > it is cleaner than copying the logic into the syscall implementation.
> > >
> > > Let me clarify.
> > >
> > > You can add
> > > lru_gen_test_recent(void *shadow, bool file)
> > > without refactoring the existing
> > > lru_gen_refault().
> > >
> > > Set the boilerplate aside, you only repeat one line of code, which is
> > > the last line in the new function.
> > >
> > > (The boilerplate code is repeated in many places, and that's why it's
> > > called boilerplate.)
> >
> > Oh maybe I've misunderstood your original comment. Your
> > suggestion is to repeat the eviction recency check in workingset.c
> > (i.e keep the *_gen_refault unchanged - just copy that logic to
> > *_test_recent)?
>
> Correct.
Thanks for the suggestion, Yu! I'll update if there are complications with
this, but otherwise the change will be in v3 of this patch series.
next prev parent reply other threads:[~2022-12-08 18:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 17:51 [PATCH v2 0/4] cachestat: a new syscall for page cache state of files Nhat Pham
2022-12-05 17:51 ` [PATCH v2 1/4] workingset: fix confusion around eviction vs refault container Nhat Pham
2022-12-05 17:51 ` [PATCH v2 2/4] workingset: refactor LRU refault to expose refault recency check Nhat Pham
2022-12-05 23:49 ` Yu Zhao
2022-12-06 1:19 ` Nhat Pham
2022-12-06 1:28 ` Yu Zhao
2022-12-06 2:22 ` Nhat Pham
2022-12-06 2:25 ` Yu Zhao
2022-12-08 18:07 ` Nhat Pham [this message]
2022-12-06 15:22 ` Matthew Wilcox
2022-12-07 17:28 ` Nhat Pham
2022-12-05 17:51 ` [PATCH v2 3/4] cachestat: implement cachestat syscall Nhat Pham
2022-12-05 23:15 ` kernel test robot
2022-12-06 4:48 ` kernel test robot
2022-12-06 4:59 ` kernel test robot
2022-12-07 1:42 ` kernel test robot
2022-12-10 23:51 ` Al Viro
2022-12-12 13:22 ` Brian Foster
2022-12-12 16:50 ` Nhat Pham
2022-12-12 16:23 ` Nhat Pham
2022-12-12 16:24 ` Matthew Wilcox
2022-12-12 16:37 ` Nhat Pham
2022-12-05 17:51 ` [PATCH v2 4/4] selftests: Add selftests for cachestat 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=NwbtFeVyL+J+d8hLeRhoBgfhof+w9_heN++J09XToxCg@mail.gmail.com' \
--to=nphamcs@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bfoster@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--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