Re: [RFC PATCH v2 0/7] DAMON based 2-tier memory management for CXL memory

From: Honggyu Kim
Date: Mon Mar 18 2024 - 09:28:31 EST


Hi SeongJae,

On Sun, 17 Mar 2024 08:31:44 -0700 SeongJae Park <sj@xxxxxxxxxx> wrote:
> Hi Honggyu,
>
> On Sun, 17 Mar 2024 17:36:29 +0900 Honggyu Kim <honggyu.kim@xxxxxx> wrote:
>
> > Hi SeongJae,
> >
> > Thanks for the confirmation. I have a few comments on young filter so
> > please read the inline comments again.
> >
> > On Wed, 12 Mar 2024 08:53:00 -0800 SeongJae Park <sj@xxxxxxxxxx> wrote:
> > > Hi Honggyu,
> > >
> > > > > -----Original Message-----
> > > > > From: SeongJae Park <sj@xxxxxxxxxx>
> > > > > Sent: Tuesday, March 12, 2024 3:33 AM
> > > > > To: Honggyu Kim <honggyu.kim@xxxxxx>
> > > > > Cc: SeongJae Park <sj@xxxxxxxxxx>; kernel_team <kernel_team@xxxxxxxxxxx>
> > > > > Subject: RE: Re: [RFC PATCH v2 0/7] DAMON based 2-tier memory management for CXL memory
> > > > >
> > > > > Hi Honggyu,
> > > > >
> > > > > On Mon, 11 Mar 2024 12:51:12 +0000 "honggyu.kim@xxxxxx" <honggyu.kim@xxxxxx> wrote:
> > > > >
> > > > > > Hi SeongJae,
> > > > > >
> > > > > > I've tested it again and found that "young" filter has to be set
> > > > > > differently as follows.
> > > > > > - demote action: set "young" filter with "matching" true
> > > > > > - promote action: set "young" filter with "matching" false

Thinking it again, I feel like "matching" true or false looks quite
vague to me as a general user.

Instead, I would like to have more meaningful names for "matching" as
follows.

- matching "true" can be either (filter) "out" or "skip".
- matching "false" can be either (filter) "in" or "apply".

Internally, the type of "matching" can be boolean, but it'd be better
for general users have another ways to set it such as "out"/"in" or
"skip"/"apply" via sysfs interface. I prefer "skip" and "apply" looks
more intuitive, but I don't have strong objection on "out" and "in" as
well.

I also feel the filter name "young" is more for developers not for
general users. I think this can be changed to "accessed" filter
instead.

The demote and promote filters can be set as follows using these.

- demote action: set "accessed" filter with "matching" to "skip"
- promote action: set "accessed" filter with "matching" to "apply"

I also think that you can feel this is more complicated so I would like
to hear how you think about this.

> > > > >
> > > > > DAMOS filter is basically for filtering "out" memory regions that matches to
> > > > > the condition.

Right. In other tools, I see filters are more used as filtering "in"
rather than filtering "out". I feel this makes me more confused.

> > > > > Hence in your setup, young pages are not filtered out from
> > > > > demote action target.
> > > >
> > > > I thought young filter true means "young pages ARE filtered out" for demotion.
> > >
> > > You're correct.
> >
> > Ack.
> >
> > > >
> > > > > That is, you're demoting pages that "not" young.
> > > >
> > > > Your explanation here looks opposite to the previous statement.
> > >
> > > Again, you're correct. My intention was "non-young pages are not ..." but
> > > maybe I was out of my mind and mistakenly removed "non-" part. Sorry for the
> > > confusion.
> >
> > No problem. I also think it's quite confusing.
> >
> > > >
> > > > > And vice versa, so you're applying promote to non-non-young (young) pages.
> > > >
> > > > Yes, I understand "promote non-non-young pages" means "promote young pages".
> > > > This might be understood as "young pages are NOT filtered out" for promotion
> > > > but it doesn't mean that "old pages are filtered out" instead.
> > > > And we just rely hot detection only on DAMOS logics such as access frequency
> > > > and age. Am I correct?
> > >
> > > You're correct.
> >
> > Ack. But if it doesn't mean that "old pages are filtered out" instead,
>
> It does mean that. Here, filtering is exclusive. Hence, "filter-in a type of
> pages" means "filter-out pages of other types". At least that's the intention.
> To quote the documentation
> (https://docs.kernel.org/mm/damon/design.html#filters),
>
> Each filter specifies the type of target memory, and whether it should
> exclude the memory of the type (filter-out), or all except the memory of
> the type (filter-in).

Thanks for the correction.

> > then do we really need this filter for promotion? If not, maybe should
> > we create another "old" filter for promotion? As of now, the promotion
> > is mostly done inaccurately, but the accurate migration is done at
> > demotion level.
>
> Is this based on your theory? Or, a real behavior that you're seeing from your
> setup? If this is a real behavior, I think that should be a bug that need to
> be fixed.

I have observed this in the hot_cold example, but I also found that the
promotion is done very quickly because the age for promote action is set
to 0 to max in my json setup. It makes most pages of the region are
young because there is not enough time for those pages being old. That
means I was wrong.

> > To avoid this issue, I feel we should promotion only "young" pages after
> > filtering "old" pages out.
> >
> > > >
> > > > > I understand this is somewhat complex, but what we have for now.
> > > >
> > > > Thanks for the explanation. I guess you mean my filter setup is correct.
> > > > Is it correct?
> > >
> > > Again, you're correct. Your filter setup is what I expected to :)
> >
> > Thanks. I see that it works fine, but I would like to have more
> > discussion about "young" filter. What I think about filter is that if I
> > apply "young" filter "true" for demotion, then the action applies only
> > for "young" pages, but the current implementation works opposite.
> >
> > I understand the function name of internal implementation is
> > "damos_pa_filter_out" so the basic action is filtering out, but the
> > cgroup filter works in the opposite way for now.
>
> Does memcg filter works in the opposite way? I don't think so because
> __damos_pa_filter_out() sets 'matches' as 'true' only if the the given folio is
> contained in the given memcg. 'young' filter also simply sets 'matches' as
> 'true' only if the given folio is young.
>
> If it works in the opposite way, it's a bug that need to be fixed. Please let
> me know if I'm missing something.

No, it was also my misunderstanding. I used to set the matching false
using my script.

Thanks,
Honggyu

> >
> > I would like to hear how you think about this.
> >
> > > >
> > > > > > Then, I see that "hot_cold" migrates hot/cold memory correctly.
> > > > >
> > > > > Thank you so much for sharing this great news! My tests also show no bad
> > > > > signal so far.
> > > > >
> > > > > >
> > > > > > Could you please upload the "damon_folio_mkold" patch to LKML?
> > > > > > Then I will rebase our changes based on it and run the redis test again.
> > > > >
> > > > > I will do that soon.
> > > >
> > > > Thanks a lot for sharing the RFC v2 for DAMOS young filter.
> > > > https://lore.kernel.org/damon/20240311204545.47097-1-sj@xxxxxxxxxx/
> > > >
> > > > I will rebase our work based on it and share the result.
> > >
> > > Cool, looking forward to it! Hopefully we will make it be merged into the
> > > mainline by v6.10!
> >
> > I hope so. Thanks for your help!
> >
> > Honggyu
>
>
> Thanks,
> SJ