diff mbox series

[v3,2/2] mm/damon: introduce DAMOS filter type hugepage

Message ID 20250120181959.2564362-2-usamaarif642@gmail.com (mailing list archive)
State New
Headers show
Series [v3,1/2] mm/damon: have damon_get_folio return folio even for tail pages | expand

Commit Message

Usama Arif Jan. 20, 2025, 6:19 p.m. UTC
This is to gather statistics to check if memory regions of specific
access tempratures are backed by hugepages. This includes both THPs
and hugetlbfs.
This filter can help to observe and prove the effectivenes of
different schemes for shrinking/collapsing hugepages.

Signed-off-by: Usama Arif <usamaarif642@gmail.com>
---
v2 -> v3:
- expose hugepage via sysfs even if the kernel is
  built without hugepage support. DAMON will just
  just return 0. (SJ Park)

v1 -> v2:
- Wrap DAMOS_FILTER_TYPE_HUGEPAGE case with
  CONFIG_PGTABLE_HAS_HUGE_LEAVES (SJ Park)
---
 include/linux/damon.h    | 2 ++
 mm/damon/paddr.c         | 5 +++++
 mm/damon/sysfs-schemes.c | 1 +
 3 files changed, 8 insertions(+)

Comments

SeongJae Park Jan. 20, 2025, 6:33 p.m. UTC | #1
On Mon, 20 Jan 2025 18:19:59 +0000 Usama Arif <usamaarif642@gmail.com> wrote:

> This is to gather statistics to check if memory regions of specific
> access tempratures are backed by hugepages. This includes both THPs
> and hugetlbfs.
> This filter can help to observe and prove the effectivenes of
> different schemes for shrinking/collapsing hugepages.
> 
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>

Reviewed-by: SeongJae Park <sj@kernel.org>

> ---
> v2 -> v3:
> - expose hugepage via sysfs even if the kernel is
>   built without hugepage support. DAMON will just
>   just return 0. (SJ Park)
> 
> v1 -> v2:
> - Wrap DAMOS_FILTER_TYPE_HUGEPAGE case with
>   CONFIG_PGTABLE_HAS_HUGE_LEAVES (SJ Park)

Thank you for writing and patiently revisioning this nice patch!


Thanks,
SJ

[...]
David Hildenbrand Jan. 20, 2025, 6:57 p.m. UTC | #2
On 20.01.25 19:19, Usama Arif wrote:
> This is to gather statistics to check if memory regions of specific
> access tempratures are backed by hugepages. This includes both THPs
> and hugetlbfs.
> This filter can help to observe and prove the effectivenes of
> different schemes for shrinking/collapsing hugepages.
> 
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
> ---
> v2 -> v3:
> - expose hugepage via sysfs even if the kernel is
>    built without hugepage support. DAMON will just
>    just return 0. (SJ Park)
> 
> v1 -> v2:
> - Wrap DAMOS_FILTER_TYPE_HUGEPAGE case with
>    CONFIG_PGTABLE_HAS_HUGE_LEAVES (SJ Park)
> ---
>   include/linux/damon.h    | 2 ++
>   mm/damon/paddr.c         | 5 +++++
>   mm/damon/sysfs-schemes.c | 1 +
>   3 files changed, 8 insertions(+)
> 
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index af525252b853..1d94d7d88b36 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
> @@ -326,6 +326,7 @@ struct damos_stat {
>    * @DAMOS_FILTER_TYPE_ANON:	Anonymous pages.
>    * @DAMOS_FILTER_TYPE_MEMCG:	Specific memcg's pages.
>    * @DAMOS_FILTER_TYPE_YOUNG:	Recently accessed pages.
> + * @DAMOS_FILTER_TYPE_HUGEPAGE:	Page is part of a hugepage.
>    * @DAMOS_FILTER_TYPE_ADDR:	Address range.
>    * @DAMOS_FILTER_TYPE_TARGET:	Data Access Monitoring target.
>    * @NR_DAMOS_FILTER_TYPES:	Number of filter types.
> @@ -345,6 +346,7 @@ enum damos_filter_type {
>   	DAMOS_FILTER_TYPE_ANON,
>   	DAMOS_FILTER_TYPE_MEMCG,
>   	DAMOS_FILTER_TYPE_YOUNG,
> +	DAMOS_FILTER_TYPE_HUGEPAGE,
>   	DAMOS_FILTER_TYPE_ADDR,
>   	DAMOS_FILTER_TYPE_TARGET,
>   	NR_DAMOS_FILTER_TYPES,
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index c0ccf4fade24..224308140441 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -222,6 +222,11 @@ static bool damos_pa_filter_match(struct damos_filter *filter,
>   		if (matched)
>   			damon_folio_mkold(folio);
>   		break;
> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
> +	case DAMOS_FILTER_TYPE_HUGEPAGE:
> +		matched = folio_size(folio) == HPAGE_PMD_SIZE;


Can we directly embed in the name and the comments/docs that we are only 
talking about PMD size (both, THP and hugetlb)?

DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
SeongJae Park Jan. 20, 2025, 7:16 p.m. UTC | #3
On Mon, 20 Jan 2025 19:57:10 +0100 David Hildenbrand <david@redhat.com> wrote:

> On 20.01.25 19:19, Usama Arif wrote:
> > This is to gather statistics to check if memory regions of specific
> > access tempratures are backed by hugepages. This includes both THPs
> > and hugetlbfs.
> > This filter can help to observe and prove the effectivenes of
> > different schemes for shrinking/collapsing hugepages.
> > 
> > Signed-off-by: Usama Arif <usamaarif642@gmail.com>
> > ---
> > v2 -> v3:
> > - expose hugepage via sysfs even if the kernel is
> >    built without hugepage support. DAMON will just
> >    just return 0. (SJ Park)
> > 
> > v1 -> v2:
> > - Wrap DAMOS_FILTER_TYPE_HUGEPAGE case with
> >    CONFIG_PGTABLE_HAS_HUGE_LEAVES (SJ Park)
> > ---
> >   include/linux/damon.h    | 2 ++
> >   mm/damon/paddr.c         | 5 +++++
> >   mm/damon/sysfs-schemes.c | 1 +
> >   3 files changed, 8 insertions(+)
> > 
> > diff --git a/include/linux/damon.h b/include/linux/damon.h
> > index af525252b853..1d94d7d88b36 100644
> > --- a/include/linux/damon.h
> > +++ b/include/linux/damon.h
> > @@ -326,6 +326,7 @@ struct damos_stat {
> >    * @DAMOS_FILTER_TYPE_ANON:	Anonymous pages.
> >    * @DAMOS_FILTER_TYPE_MEMCG:	Specific memcg's pages.
> >    * @DAMOS_FILTER_TYPE_YOUNG:	Recently accessed pages.
> > + * @DAMOS_FILTER_TYPE_HUGEPAGE:	Page is part of a hugepage.
> >    * @DAMOS_FILTER_TYPE_ADDR:	Address range.
> >    * @DAMOS_FILTER_TYPE_TARGET:	Data Access Monitoring target.
> >    * @NR_DAMOS_FILTER_TYPES:	Number of filter types.
> > @@ -345,6 +346,7 @@ enum damos_filter_type {
> >   	DAMOS_FILTER_TYPE_ANON,
> >   	DAMOS_FILTER_TYPE_MEMCG,
> >   	DAMOS_FILTER_TYPE_YOUNG,
> > +	DAMOS_FILTER_TYPE_HUGEPAGE,
> >   	DAMOS_FILTER_TYPE_ADDR,
> >   	DAMOS_FILTER_TYPE_TARGET,
> >   	NR_DAMOS_FILTER_TYPES,
> > diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> > index c0ccf4fade24..224308140441 100644
> > --- a/mm/damon/paddr.c
> > +++ b/mm/damon/paddr.c
> > @@ -222,6 +222,11 @@ static bool damos_pa_filter_match(struct damos_filter *filter,
> >   		if (matched)
> >   			damon_folio_mkold(folio);
> >   		break;
> > +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
> > +	case DAMOS_FILTER_TYPE_HUGEPAGE:
> > +		matched = folio_size(folio) == HPAGE_PMD_SIZE;
> 
> 
> Can we directly embed in the name and the comments/docs that we are only 
> talking about PMD size (both, THP and hugetlb)?
> 
> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.

Nice suggestion, thank you!  And we might later add more filter types for
different size huge pages.  What about extending this to handle more general
case, though?  That is, we can let the filter receives a range of the folio
size to match, like DAMOS_FILTER_TYPE_ADDR does.  Then, the filter could be
used for any size of interest.

I think such extension is not a strong blocker for this patch.  We can do the
extension later without breaking users by having the PAGE_PMD_SIZE as the
default value of the address range input.  I have no strong opinion about this,
though.

What do you think?


Thanks,
SJ

[...]
Usama Arif Jan. 20, 2025, 7:18 p.m. UTC | #4
On 20/01/2025 18:57, David Hildenbrand wrote:
> On 20.01.25 19:19, Usama Arif wrote:
>> This is to gather statistics to check if memory regions of specific
>> access tempratures are backed by hugepages. This includes both THPs
>> and hugetlbfs.
>> This filter can help to observe and prove the effectivenes of
>> different schemes for shrinking/collapsing hugepages.
>>
>> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
>> ---
>> v2 -> v3:
>> - expose hugepage via sysfs even if the kernel is
>>    built without hugepage support. DAMON will just
>>    just return 0. (SJ Park)
>>
>> v1 -> v2:
>> - Wrap DAMOS_FILTER_TYPE_HUGEPAGE case with
>>    CONFIG_PGTABLE_HAS_HUGE_LEAVES (SJ Park)
>> ---
>>   include/linux/damon.h    | 2 ++
>>   mm/damon/paddr.c         | 5 +++++
>>   mm/damon/sysfs-schemes.c | 1 +
>>   3 files changed, 8 insertions(+)
>>
>> diff --git a/include/linux/damon.h b/include/linux/damon.h
>> index af525252b853..1d94d7d88b36 100644
>> --- a/include/linux/damon.h
>> +++ b/include/linux/damon.h
>> @@ -326,6 +326,7 @@ struct damos_stat {
>>    * @DAMOS_FILTER_TYPE_ANON:    Anonymous pages.
>>    * @DAMOS_FILTER_TYPE_MEMCG:    Specific memcg's pages.
>>    * @DAMOS_FILTER_TYPE_YOUNG:    Recently accessed pages.
>> + * @DAMOS_FILTER_TYPE_HUGEPAGE:    Page is part of a hugepage.
>>    * @DAMOS_FILTER_TYPE_ADDR:    Address range.
>>    * @DAMOS_FILTER_TYPE_TARGET:    Data Access Monitoring target.
>>    * @NR_DAMOS_FILTER_TYPES:    Number of filter types.
>> @@ -345,6 +346,7 @@ enum damos_filter_type {
>>       DAMOS_FILTER_TYPE_ANON,
>>       DAMOS_FILTER_TYPE_MEMCG,
>>       DAMOS_FILTER_TYPE_YOUNG,
>> +    DAMOS_FILTER_TYPE_HUGEPAGE,
>>       DAMOS_FILTER_TYPE_ADDR,
>>       DAMOS_FILTER_TYPE_TARGET,
>>       NR_DAMOS_FILTER_TYPES,
>> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
>> index c0ccf4fade24..224308140441 100644
>> --- a/mm/damon/paddr.c
>> +++ b/mm/damon/paddr.c
>> @@ -222,6 +222,11 @@ static bool damos_pa_filter_match(struct damos_filter *filter,
>>           if (matched)
>>               damon_folio_mkold(folio);
>>           break;
>> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
>> +    case DAMOS_FILTER_TYPE_HUGEPAGE:
>> +        matched = folio_size(folio) == HPAGE_PMD_SIZE;
> 
> 
> Can we directly embed in the name and the comments/docs that we are only talking about PMD size (both, THP and hugetlb)?
> 
> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
> 
> 

I always think of gigantic page as PUD size, hugepage as PMD size (and not anything smaller), mTHP as smaller than PMD :)
But I don't think thats the official term or standardized across the kernel.  

I can send a v4, or maybe Andrew could apply the diff below?

diff --git a/include/linux/damon.h b/include/linux/damon.h
index 1d94d7d88b36..261c0741dd0f 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -326,7 +326,7 @@ struct damos_stat {
  * @DAMOS_FILTER_TYPE_ANON:    Anonymous pages.
  * @DAMOS_FILTER_TYPE_MEMCG:   Specific memcg's pages.
  * @DAMOS_FILTER_TYPE_YOUNG:   Recently accessed pages.
- * @DAMOS_FILTER_TYPE_HUGEPAGE:        Page is part of a hugepage.
+ * @DAMOS_FILTER_TYPE_PMD_HUGEPAGE:    Page is part of a hugepage (THP/hugetlb).
  * @DAMOS_FILTER_TYPE_ADDR:    Address range.
  * @DAMOS_FILTER_TYPE_TARGET:  Data Access Monitoring target.
  * @NR_DAMOS_FILTER_TYPES:     Number of filter types.
@@ -346,7 +346,7 @@ enum damos_filter_type {
        DAMOS_FILTER_TYPE_ANON,
        DAMOS_FILTER_TYPE_MEMCG,
        DAMOS_FILTER_TYPE_YOUNG,
-       DAMOS_FILTER_TYPE_HUGEPAGE,
+       DAMOS_FILTER_TYPE_PMD_HUGEPAGE,
        DAMOS_FILTER_TYPE_ADDR,
        DAMOS_FILTER_TYPE_TARGET,
        NR_DAMOS_FILTER_TYPES,
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 224308140441..e374ea952308 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -223,7 +223,7 @@ static bool damos_pa_filter_match(struct damos_filter *filter,
                        damon_folio_mkold(folio);
                break;
 #if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
-       case DAMOS_FILTER_TYPE_HUGEPAGE:
+       case DAMOS_FILTER_TYPE_PMD_HUGEPAGE:
                matched = folio_size(folio) == HPAGE_PMD_SIZE;
                break;
 #endif
David Hildenbrand Jan. 20, 2025, 7:23 p.m. UTC | #5
On 20.01.25 20:16, SeongJae Park wrote:
> On Mon, 20 Jan 2025 19:57:10 +0100 David Hildenbrand <david@redhat.com> wrote:
> 
>> On 20.01.25 19:19, Usama Arif wrote:
>>> This is to gather statistics to check if memory regions of specific
>>> access tempratures are backed by hugepages. This includes both THPs
>>> and hugetlbfs.
>>> This filter can help to observe and prove the effectivenes of
>>> different schemes for shrinking/collapsing hugepages.
>>>
>>> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
>>> ---
>>> v2 -> v3:
>>> - expose hugepage via sysfs even if the kernel is
>>>     built without hugepage support. DAMON will just
>>>     just return 0. (SJ Park)
>>>
>>> v1 -> v2:
>>> - Wrap DAMOS_FILTER_TYPE_HUGEPAGE case with
>>>     CONFIG_PGTABLE_HAS_HUGE_LEAVES (SJ Park)
>>> ---
>>>    include/linux/damon.h    | 2 ++
>>>    mm/damon/paddr.c         | 5 +++++
>>>    mm/damon/sysfs-schemes.c | 1 +
>>>    3 files changed, 8 insertions(+)
>>>
>>> diff --git a/include/linux/damon.h b/include/linux/damon.h
>>> index af525252b853..1d94d7d88b36 100644
>>> --- a/include/linux/damon.h
>>> +++ b/include/linux/damon.h
>>> @@ -326,6 +326,7 @@ struct damos_stat {
>>>     * @DAMOS_FILTER_TYPE_ANON:	Anonymous pages.
>>>     * @DAMOS_FILTER_TYPE_MEMCG:	Specific memcg's pages.
>>>     * @DAMOS_FILTER_TYPE_YOUNG:	Recently accessed pages.
>>> + * @DAMOS_FILTER_TYPE_HUGEPAGE:	Page is part of a hugepage.
>>>     * @DAMOS_FILTER_TYPE_ADDR:	Address range.
>>>     * @DAMOS_FILTER_TYPE_TARGET:	Data Access Monitoring target.
>>>     * @NR_DAMOS_FILTER_TYPES:	Number of filter types.
>>> @@ -345,6 +346,7 @@ enum damos_filter_type {
>>>    	DAMOS_FILTER_TYPE_ANON,
>>>    	DAMOS_FILTER_TYPE_MEMCG,
>>>    	DAMOS_FILTER_TYPE_YOUNG,
>>> +	DAMOS_FILTER_TYPE_HUGEPAGE,
>>>    	DAMOS_FILTER_TYPE_ADDR,
>>>    	DAMOS_FILTER_TYPE_TARGET,
>>>    	NR_DAMOS_FILTER_TYPES,
>>> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
>>> index c0ccf4fade24..224308140441 100644
>>> --- a/mm/damon/paddr.c
>>> +++ b/mm/damon/paddr.c
>>> @@ -222,6 +222,11 @@ static bool damos_pa_filter_match(struct damos_filter *filter,
>>>    		if (matched)
>>>    			damon_folio_mkold(folio);
>>>    		break;
>>> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
>>> +	case DAMOS_FILTER_TYPE_HUGEPAGE:
>>> +		matched = folio_size(folio) == HPAGE_PMD_SIZE;
>>
>>
>> Can we directly embed in the name and the comments/docs that we are only
>> talking about PMD size (both, THP and hugetlb)?
>>
>> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
> 
> Nice suggestion, thank you!  And we might later add more filter types for
> different size huge pages.  What about extending this to handle more general
> case, though?  That is, we can let the filter receives a range of the folio
> size to match, like DAMOS_FILTER_TYPE_ADDR does.  Then, the filter could be
> used for any size of interest.

That would probably be future proof: either a range or explicitly 
specified sizes (ranges?).
David Hildenbrand Jan. 20, 2025, 7:25 p.m. UTC | #6
On 20.01.25 20:18, Usama Arif wrote:
> 
> 
> On 20/01/2025 18:57, David Hildenbrand wrote:
>> On 20.01.25 19:19, Usama Arif wrote:
>>> This is to gather statistics to check if memory regions of specific
>>> access tempratures are backed by hugepages. This includes both THPs
>>> and hugetlbfs.
>>> This filter can help to observe and prove the effectivenes of
>>> different schemes for shrinking/collapsing hugepages.
>>>
>>> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
>>> ---
>>> v2 -> v3:
>>> - expose hugepage via sysfs even if the kernel is
>>>     built without hugepage support. DAMON will just
>>>     just return 0. (SJ Park)
>>>
>>> v1 -> v2:
>>> - Wrap DAMOS_FILTER_TYPE_HUGEPAGE case with
>>>     CONFIG_PGTABLE_HAS_HUGE_LEAVES (SJ Park)
>>> ---
>>>    include/linux/damon.h    | 2 ++
>>>    mm/damon/paddr.c         | 5 +++++
>>>    mm/damon/sysfs-schemes.c | 1 +
>>>    3 files changed, 8 insertions(+)
>>>
>>> diff --git a/include/linux/damon.h b/include/linux/damon.h
>>> index af525252b853..1d94d7d88b36 100644
>>> --- a/include/linux/damon.h
>>> +++ b/include/linux/damon.h
>>> @@ -326,6 +326,7 @@ struct damos_stat {
>>>     * @DAMOS_FILTER_TYPE_ANON:    Anonymous pages.
>>>     * @DAMOS_FILTER_TYPE_MEMCG:    Specific memcg's pages.
>>>     * @DAMOS_FILTER_TYPE_YOUNG:    Recently accessed pages.
>>> + * @DAMOS_FILTER_TYPE_HUGEPAGE:    Page is part of a hugepage.
>>>     * @DAMOS_FILTER_TYPE_ADDR:    Address range.
>>>     * @DAMOS_FILTER_TYPE_TARGET:    Data Access Monitoring target.
>>>     * @NR_DAMOS_FILTER_TYPES:    Number of filter types.
>>> @@ -345,6 +346,7 @@ enum damos_filter_type {
>>>        DAMOS_FILTER_TYPE_ANON,
>>>        DAMOS_FILTER_TYPE_MEMCG,
>>>        DAMOS_FILTER_TYPE_YOUNG,
>>> +    DAMOS_FILTER_TYPE_HUGEPAGE,
>>>        DAMOS_FILTER_TYPE_ADDR,
>>>        DAMOS_FILTER_TYPE_TARGET,
>>>        NR_DAMOS_FILTER_TYPES,
>>> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
>>> index c0ccf4fade24..224308140441 100644
>>> --- a/mm/damon/paddr.c
>>> +++ b/mm/damon/paddr.c
>>> @@ -222,6 +222,11 @@ static bool damos_pa_filter_match(struct damos_filter *filter,
>>>            if (matched)
>>>                damon_folio_mkold(folio);
>>>            break;
>>> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
>>> +    case DAMOS_FILTER_TYPE_HUGEPAGE:
>>> +        matched = folio_size(folio) == HPAGE_PMD_SIZE;
>>
>>
>> Can we directly embed in the name and the comments/docs that we are only talking about PMD size (both, THP and hugetlb)?
>>
>> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
>>
>>
> 
> I always think of gigantic page as PUD size, hugepage as PMD size (and not anything smaller), mTHP as smaller than PMD :)

And cont-PMD ... hugetlb, cont-PTE hugetlb ... are ? :)

> But I don't think thats the official term or standardized across the kernel.
> 

We didn't know better when we designed some of the old interfaces, 
that's why I am hoping that we can do better with new interfaces. Either 
spell out the PMD size, or have filters for size lists / size ranges.

> I can send a v4, or maybe Andrew could apply the diff below?
> 
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index 1d94d7d88b36..261c0741dd0f 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
> @@ -326,7 +326,7 @@ struct damos_stat {
>    * @DAMOS_FILTER_TYPE_ANON:    Anonymous pages.
>    * @DAMOS_FILTER_TYPE_MEMCG:   Specific memcg's pages.
>    * @DAMOS_FILTER_TYPE_YOUNG:   Recently accessed pages.
> - * @DAMOS_FILTER_TYPE_HUGEPAGE:        Page is part of a hugepage.
> + * @DAMOS_FILTER_TYPE_PMD_HUGEPAGE:    Page is part of a hugepage (THP/hugetlb).
>    * @DAMOS_FILTER_TYPE_ADDR:    Address range.
>    * @DAMOS_FILTER_TYPE_TARGET:  Data Access Monitoring target.
>    * @NR_DAMOS_FILTER_TYPES:     Number of filter types.
> @@ -346,7 +346,7 @@ enum damos_filter_type {
>          DAMOS_FILTER_TYPE_ANON,
>          DAMOS_FILTER_TYPE_MEMCG,
>          DAMOS_FILTER_TYPE_YOUNG,
> -       DAMOS_FILTER_TYPE_HUGEPAGE,
> +       DAMOS_FILTER_TYPE_PMD_HUGEPAGE,
>          DAMOS_FILTER_TYPE_ADDR,
>          DAMOS_FILTER_TYPE_TARGET,
>          NR_DAMOS_FILTER_TYPES,
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index 224308140441..e374ea952308 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -223,7 +223,7 @@ static bool damos_pa_filter_match(struct damos_filter *filter,
>                          damon_folio_mkold(folio);
>                  break;
>   #if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
> -       case DAMOS_FILTER_TYPE_HUGEPAGE:
> +       case DAMOS_FILTER_TYPE_PMD_HUGEPAGE:
>                  matched = folio_size(folio) == HPAGE_PMD_SIZE;
>                  break;
>   #endif
>
SeongJae Park Jan. 20, 2025, 7:30 p.m. UTC | #7
On Mon, 20 Jan 2025 20:23:20 +0100 David Hildenbrand <david@redhat.com> wrote:

> On 20.01.25 20:16, SeongJae Park wrote:
> > On Mon, 20 Jan 2025 19:57:10 +0100 David Hildenbrand <david@redhat.com> wrote:
> > 
> >> On 20.01.25 19:19, Usama Arif wrote:
[...]
> >>> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
> >>> +	case DAMOS_FILTER_TYPE_HUGEPAGE:
> >>> +		matched = folio_size(folio) == HPAGE_PMD_SIZE;
> >>
> >>
> >> Can we directly embed in the name and the comments/docs that we are only
> >> talking about PMD size (both, THP and hugetlb)?
> >>
> >> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
> > 
> > Nice suggestion, thank you!  And we might later add more filter types for
> > different size huge pages.  What about extending this to handle more general
> > case, though?  That is, we can let the filter receives a range of the folio
> > size to match, like DAMOS_FILTER_TYPE_ADDR does.  Then, the filter could be
> > used for any size of interest.
> 
> That would probably be future proof: either a range or explicitly 
> specified sizes (ranges?).

DAMON supports installing multiple DAMOS filters.  So multiple DAMOS filters
that each matching single range can be used for the multiple sizes or ranges
use case.


Thanks,
SJ

> 
> -- 
> Cheers,
> 
> David / dhildenb
Usama Arif Jan. 20, 2025, 7:58 p.m. UTC | #8
On 20/01/2025 19:30, SeongJae Park wrote:
> On Mon, 20 Jan 2025 20:23:20 +0100 David Hildenbrand <david@redhat.com> wrote:
> 
>> On 20.01.25 20:16, SeongJae Park wrote:
>>> On Mon, 20 Jan 2025 19:57:10 +0100 David Hildenbrand <david@redhat.com> wrote:
>>>
>>>> On 20.01.25 19:19, Usama Arif wrote:
> [...]
>>>>> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
>>>>> +	case DAMOS_FILTER_TYPE_HUGEPAGE:
>>>>> +		matched = folio_size(folio) == HPAGE_PMD_SIZE;
>>>>
>>>>
>>>> Can we directly embed in the name and the comments/docs that we are only
>>>> talking about PMD size (both, THP and hugetlb)?
>>>>
>>>> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
>>>
>>> Nice suggestion, thank you!  And we might later add more filter types for
>>> different size huge pages.  What about extending this to handle more general
>>> case, though?  That is, we can let the filter receives a range of the folio
>>> size to match, like DAMOS_FILTER_TYPE_ADDR does.  Then, the filter could be
>>> used for any size of interest.
>>
>> That would probably be future proof: either a range or explicitly 
>> specified sizes (ranges?).
> 
> DAMON supports installing multiple DAMOS filters.  So multiple DAMOS filters
> that each matching single range can be used for the multiple sizes or ranges
> use case.
> 
> 

Does creating something like schemes/<N>/access_pattern/page_size/{min,max}
sound good? with the default value being pmd size?
David Hildenbrand Jan. 20, 2025, 8:03 p.m. UTC | #9
On 20.01.25 20:58, Usama Arif wrote:
> 
> 
> On 20/01/2025 19:30, SeongJae Park wrote:
>> On Mon, 20 Jan 2025 20:23:20 +0100 David Hildenbrand <david@redhat.com> wrote:
>>
>>> On 20.01.25 20:16, SeongJae Park wrote:
>>>> On Mon, 20 Jan 2025 19:57:10 +0100 David Hildenbrand <david@redhat.com> wrote:
>>>>
>>>>> On 20.01.25 19:19, Usama Arif wrote:
>> [...]
>>>>>> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
>>>>>> +	case DAMOS_FILTER_TYPE_HUGEPAGE:
>>>>>> +		matched = folio_size(folio) == HPAGE_PMD_SIZE;
>>>>>
>>>>>
>>>>> Can we directly embed in the name and the comments/docs that we are only
>>>>> talking about PMD size (both, THP and hugetlb)?
>>>>>
>>>>> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
>>>>
>>>> Nice suggestion, thank you!  And we might later add more filter types for
>>>> different size huge pages.  What about extending this to handle more general
>>>> case, though?  That is, we can let the filter receives a range of the folio
>>>> size to match, like DAMOS_FILTER_TYPE_ADDR does.  Then, the filter could be
>>>> used for any size of interest.
>>>
>>> That would probably be future proof: either a range or explicitly
>>> specified sizes (ranges?).
>>
>> DAMON supports installing multiple DAMOS filters.  So multiple DAMOS filters
>> that each matching single range can be used for the multiple sizes or ranges
>> use case.
>>
>>
> 
> Does creating something like schemes/<N>/access_pattern/page_size/{min,max}
> sound good? with the default value being pmd size?

"page_size" might be misleading. Not sure if we want to use the word 
"folio_size" here, so far it's more an internal detail that evolved from 
compound pages.

"hugepage_size" would at least match /sys/kernel/mm/hugepages/ and 
/sys/kernel/mm/transparent_hugepage/.

But if you would also support "single page" == e.g., 4K, "hugepage" 
would be wrong.
SeongJae Park Jan. 20, 2025, 8:12 p.m. UTC | #10
On Mon, 20 Jan 2025 19:58:24 +0000 Usama Arif <usamaarif642@gmail.com> wrote:

> 
> 
> On 20/01/2025 19:30, SeongJae Park wrote:
> > On Mon, 20 Jan 2025 20:23:20 +0100 David Hildenbrand <david@redhat.com> wrote:
> > 
> >> On 20.01.25 20:16, SeongJae Park wrote:
> >>> On Mon, 20 Jan 2025 19:57:10 +0100 David Hildenbrand <david@redhat.com> wrote:
> >>>
> >>>> On 20.01.25 19:19, Usama Arif wrote:
> > [...]
> >>>>> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
> >>>>> +	case DAMOS_FILTER_TYPE_HUGEPAGE:
> >>>>> +		matched = folio_size(folio) == HPAGE_PMD_SIZE;
> >>>>
> >>>>
> >>>> Can we directly embed in the name and the comments/docs that we are only
> >>>> talking about PMD size (both, THP and hugetlb)?
> >>>>
> >>>> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
> >>>
> >>> Nice suggestion, thank you!  And we might later add more filter types for
> >>> different size huge pages.  What about extending this to handle more general
> >>> case, though?  That is, we can let the filter receives a range of the folio
> >>> size to match, like DAMOS_FILTER_TYPE_ADDR does.  Then, the filter could be
> >>> used for any size of interest.
> >>
> >> That would probably be future proof: either a range or explicitly 
> >> specified sizes (ranges?).
> > 
> > DAMON supports installing multiple DAMOS filters.  So multiple DAMOS filters
> > that each matching single range can be used for the multiple sizes or ranges
> > use case.
> > 
> > 
> 
> Does creating something like schemes/<N>/access_pattern/page_size/{min,max}
> sound good? with the default value being pmd size?

For user-space ABI, like DAMOS_FILTER_TYPE_ADDR, let's use
'schemes/<N>/filters/<F>/' directory.  File names 'min' and 'max' look good to
me.

For kernel-space API, again, like DAMOS_FILTER_TYPE_ADDR, let's use the union
in 'struct damos_filter'.

If you will do the extension together with this patch, I think the default
value is not really needed.  It will only add a bit of complexity.  So if you
will do so, I'd recommend not having the default value.

Also, if you will revise this patch series for the extension, could you please
split and post the first patch of this series as a separate one?  I think the
fix is important and has no reason to be tied with this patch.


Thanks,
SJ
Usama Arif Jan. 20, 2025, 8:26 p.m. UTC | #11
On 20/01/2025 20:12, SeongJae Park wrote:
> On Mon, 20 Jan 2025 19:58:24 +0000 Usama Arif <usamaarif642@gmail.com> wrote:
> 
>>
>>
>> On 20/01/2025 19:30, SeongJae Park wrote:
>>> On Mon, 20 Jan 2025 20:23:20 +0100 David Hildenbrand <david@redhat.com> wrote:
>>>
>>>> On 20.01.25 20:16, SeongJae Park wrote:
>>>>> On Mon, 20 Jan 2025 19:57:10 +0100 David Hildenbrand <david@redhat.com> wrote:
>>>>>
>>>>>> On 20.01.25 19:19, Usama Arif wrote:
>>> [...]
>>>>>>> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
>>>>>>> +	case DAMOS_FILTER_TYPE_HUGEPAGE:
>>>>>>> +		matched = folio_size(folio) == HPAGE_PMD_SIZE;
>>>>>>
>>>>>>
>>>>>> Can we directly embed in the name and the comments/docs that we are only
>>>>>> talking about PMD size (both, THP and hugetlb)?
>>>>>>
>>>>>> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
>>>>>
>>>>> Nice suggestion, thank you!  And we might later add more filter types for
>>>>> different size huge pages.  What about extending this to handle more general
>>>>> case, though?  That is, we can let the filter receives a range of the folio
>>>>> size to match, like DAMOS_FILTER_TYPE_ADDR does.  Then, the filter could be
>>>>> used for any size of interest.
>>>>
>>>> That would probably be future proof: either a range or explicitly 
>>>> specified sizes (ranges?).
>>>
>>> DAMON supports installing multiple DAMOS filters.  So multiple DAMOS filters
>>> that each matching single range can be used for the multiple sizes or ranges
>>> use case.
>>>
>>>
>>
>> Does creating something like schemes/<N>/access_pattern/page_size/{min,max}
>> sound good? with the default value being pmd size?
> 
> For user-space ABI, like DAMOS_FILTER_TYPE_ADDR, let's use
> 'schemes/<N>/filters/<F>/' directory.  File names 'min' and 'max' look good to
> me.
> 
> For kernel-space API, again, like DAMOS_FILTER_TYPE_ADDR, let's use the union
> in 'struct damos_filter'.
> 
> If you will do the extension together with this patch, I think the default
> value is not really needed.  It will only add a bit of complexity.  So if you
> will do so, I'd recommend not having the default value.
> 
> Also, if you will revise this patch series for the extension, could you please
> split and post the first patch of this series as a separate one?  I think the
> fix is important and has no reason to be tied with this patch.
> 

Yeah I think it might be best if we get a version with flexible folio sizes merged
from the start, especially as it involves creating user ABI. I will try and send
something tomorrow.

For the first patch, do I need to resend? Or maybe Andrew could merge whats in
this v3 for patch 1, we discard patch 2 and I just send the hugepage
filter implementation separately as a new series..
SeongJae Park Jan. 20, 2025, 8:48 p.m. UTC | #12
On Mon, 20 Jan 2025 20:26:02 +0000 Usama Arif <usamaarif642@gmail.com> wrote:

> 
> 
> On 20/01/2025 20:12, SeongJae Park wrote:
> > On Mon, 20 Jan 2025 19:58:24 +0000 Usama Arif <usamaarif642@gmail.com> wrote:
> > 
> >>
> >>
> >> On 20/01/2025 19:30, SeongJae Park wrote:
> >>> On Mon, 20 Jan 2025 20:23:20 +0100 David Hildenbrand <david@redhat.com> wrote:
> >>>
> >>>> On 20.01.25 20:16, SeongJae Park wrote:
> >>>>> On Mon, 20 Jan 2025 19:57:10 +0100 David Hildenbrand <david@redhat.com> wrote:
> >>>>>
> >>>>>> On 20.01.25 19:19, Usama Arif wrote:
> >>> [...]
> >>>>>>> +#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
> >>>>>>> +	case DAMOS_FILTER_TYPE_HUGEPAGE:
> >>>>>>> +		matched = folio_size(folio) == HPAGE_PMD_SIZE;
> >>>>>>
> >>>>>>
> >>>>>> Can we directly embed in the name and the comments/docs that we are only
> >>>>>> talking about PMD size (both, THP and hugetlb)?
> >>>>>>
> >>>>>> DAMOS_FILTER_TYPE_PMD_HUGEPAGE or sth. like that.
> >>>>>
> >>>>> Nice suggestion, thank you!  And we might later add more filter types for
> >>>>> different size huge pages.  What about extending this to handle more general
> >>>>> case, though?  That is, we can let the filter receives a range of the folio
> >>>>> size to match, like DAMOS_FILTER_TYPE_ADDR does.  Then, the filter could be
> >>>>> used for any size of interest.
> >>>>
> >>>> That would probably be future proof: either a range or explicitly 
> >>>> specified sizes (ranges?).
> >>>
> >>> DAMON supports installing multiple DAMOS filters.  So multiple DAMOS filters
> >>> that each matching single range can be used for the multiple sizes or ranges
> >>> use case.
> >>>
> >>>
> >>
> >> Does creating something like schemes/<N>/access_pattern/page_size/{min,max}
> >> sound good? with the default value being pmd size?
> > 
> > For user-space ABI, like DAMOS_FILTER_TYPE_ADDR, let's use
> > 'schemes/<N>/filters/<F>/' directory.  File names 'min' and 'max' look good to
> > me.
> > 
> > For kernel-space API, again, like DAMOS_FILTER_TYPE_ADDR, let's use the union
> > in 'struct damos_filter'.
> > 
> > If you will do the extension together with this patch, I think the default
> > value is not really needed.  It will only add a bit of complexity.  So if you
> > will do so, I'd recommend not having the default value.
> > 
> > Also, if you will revise this patch series for the extension, could you please
> > split and post the first patch of this series as a separate one?  I think the
> > fix is important and has no reason to be tied with this patch.
> > 
> 
> Yeah I think it might be best if we get a version with flexible folio sizes merged
> from the start, especially as it involves creating user ABI. I will try and send
> something tomorrow.

Makes sense, looking forward to the next spin!

> 
> For the first patch, do I need to resend? Or maybe Andrew could merge whats in
> this v3 for patch 1, we discard patch 2 and I just send the hugepage
> filter implementation separately as a new series..

I think the first patch is important but not urgent.  I'd suggest to drop it
from the next revision of the filters extension series, and resend it if Andrew
neither pick it nor ask some action by a few days or weeks.


Thanks,
SJ
diff mbox series

Patch

diff --git a/include/linux/damon.h b/include/linux/damon.h
index af525252b853..1d94d7d88b36 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -326,6 +326,7 @@  struct damos_stat {
  * @DAMOS_FILTER_TYPE_ANON:	Anonymous pages.
  * @DAMOS_FILTER_TYPE_MEMCG:	Specific memcg's pages.
  * @DAMOS_FILTER_TYPE_YOUNG:	Recently accessed pages.
+ * @DAMOS_FILTER_TYPE_HUGEPAGE:	Page is part of a hugepage.
  * @DAMOS_FILTER_TYPE_ADDR:	Address range.
  * @DAMOS_FILTER_TYPE_TARGET:	Data Access Monitoring target.
  * @NR_DAMOS_FILTER_TYPES:	Number of filter types.
@@ -345,6 +346,7 @@  enum damos_filter_type {
 	DAMOS_FILTER_TYPE_ANON,
 	DAMOS_FILTER_TYPE_MEMCG,
 	DAMOS_FILTER_TYPE_YOUNG,
+	DAMOS_FILTER_TYPE_HUGEPAGE,
 	DAMOS_FILTER_TYPE_ADDR,
 	DAMOS_FILTER_TYPE_TARGET,
 	NR_DAMOS_FILTER_TYPES,
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index c0ccf4fade24..224308140441 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -222,6 +222,11 @@  static bool damos_pa_filter_match(struct damos_filter *filter,
 		if (matched)
 			damon_folio_mkold(folio);
 		break;
+#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
+	case DAMOS_FILTER_TYPE_HUGEPAGE:
+		matched = folio_size(folio) == HPAGE_PMD_SIZE;
+		break;
+#endif
 	default:
 		break;
 	}
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 98f93ae9f59e..de9265f7ccde 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -329,6 +329,7 @@  static const char * const damon_sysfs_scheme_filter_type_strs[] = {
 	"anon",
 	"memcg",
 	"young",
+	"hugepage",
 	"addr",
 	"target",
 };