[PATCH v1 23/29] mm/page-alloc: remove PageMappingFlags()

David Hildenbrand posted 29 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH v1 23/29] mm/page-alloc: remove PageMappingFlags()
Posted by David Hildenbrand 3 months, 1 week ago
We can now simply check for PageAnon() and remove PageMappingFlags().

... and while at it, use the folio instead and operate on
folio->mapping.

Reviewed-by: Zi Yan <ziy@nvidia.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 include/linux/page-flags.h | 5 -----
 mm/page_alloc.c            | 7 +++----
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index abed972e902e1..f539bd5e14200 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -723,11 +723,6 @@ static __always_inline bool folio_mapping_flags(const struct folio *folio)
 	return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) != 0;
 }
 
-static __always_inline bool PageMappingFlags(const struct page *page)
-{
-	return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) != 0;
-}
-
 static __always_inline bool folio_test_anon(const struct folio *folio)
 {
 	return ((unsigned long)folio->mapping & PAGE_MAPPING_ANON) != 0;
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index a134b9fa9520e..a0ebcc5f54bb2 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1375,10 +1375,9 @@ __always_inline bool free_pages_prepare(struct page *page,
 			(page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
 		}
 	}
-	if (PageMappingFlags(page)) {
-		if (PageAnon(page))
-			mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1);
-		page->mapping = NULL;
+	if (folio_test_anon(folio)) {
+		mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1);
+		folio->mapping = NULL;
 	}
 	if (unlikely(page_has_type(page)))
 		page->page_type = UINT_MAX;
-- 
2.49.0
Re: [PATCH v1 23/29] mm/page-alloc: remove PageMappingFlags()
Posted by Harry Yoo 3 months, 1 week ago
On Mon, Jun 30, 2025 at 03:00:04PM +0200, David Hildenbrand wrote:
> We can now simply check for PageAnon() and remove PageMappingFlags().
> 
> ... and while at it, use the folio instead and operate on
> folio->mapping.
> 
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---

LGTM,

Reviewed-by: Harry Yoo <harry.yoo@oracle.com>

-- 
Cheers,
Harry / Hyeonggon
Re: [PATCH v1 23/29] mm/page-alloc: remove PageMappingFlags()
Posted by Lorenzo Stoakes 3 months, 1 week ago
On Mon, Jun 30, 2025 at 03:00:04PM +0200, David Hildenbrand wrote:
> We can now simply check for PageAnon() and remove PageMappingFlags().
>
> ... and while at it, use the folio instead and operate on
> folio->mapping.

Probably worth mentioning to be super crystal clear that this is because
now it's either an anon folio or a KSM folio, both of which set the
FOLIO_MAPPING_ANON flag.

I wonder if there's other places that could be fixed up similarly that do
folio_test_anon() || folio_test_ksm() or equivalent?

>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>

LGTM, so:

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>


> ---
>  include/linux/page-flags.h | 5 -----
>  mm/page_alloc.c            | 7 +++----
>  2 files changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index abed972e902e1..f539bd5e14200 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -723,11 +723,6 @@ static __always_inline bool folio_mapping_flags(const struct folio *folio)
>  	return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) != 0;
>  }
>
> -static __always_inline bool PageMappingFlags(const struct page *page)
> -{
> -	return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) != 0;
> -}
> -
>  static __always_inline bool folio_test_anon(const struct folio *folio)
>  {
>  	return ((unsigned long)folio->mapping & PAGE_MAPPING_ANON) != 0;
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index a134b9fa9520e..a0ebcc5f54bb2 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1375,10 +1375,9 @@ __always_inline bool free_pages_prepare(struct page *page,
>  			(page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
>  		}
>  	}
> -	if (PageMappingFlags(page)) {
> -		if (PageAnon(page))
> -			mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1);
> -		page->mapping = NULL;
> +	if (folio_test_anon(folio)) {
> +		mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1);
> +		folio->mapping = NULL;
>  	}
>  	if (unlikely(page_has_type(page)))
>  		page->page_type = UINT_MAX;
> --
> 2.49.0
>
Re: [PATCH v1 23/29] mm/page-alloc: remove PageMappingFlags()
Posted by David Hildenbrand 3 months, 1 week ago
On 01.07.25 15:02, Lorenzo Stoakes wrote:
> On Mon, Jun 30, 2025 at 03:00:04PM +0200, David Hildenbrand wrote:
>> We can now simply check for PageAnon() and remove PageMappingFlags().
>>
>> ... and while at it, use the folio instead and operate on
>> folio->mapping.
> 
> Probably worth mentioning to be super crystal clear that this is because
> now it's either an anon folio or a KSM folio, both of which set the
> FOLIO_MAPPING_ANON flag.

"As PageMappingFlags() now only indicates anon (incl. ksm) folios, we 
can now simply check for PageAnon() and remove PageMappingFlags()."


> 
> I wonder if there's other places that could be fixed up similarly that do
> folio_test_anon() || folio_test_ksm() or equivalent?

I think you spotted the one in patch #25 :)

I looked for others while crafting this patch, but there might be more 
hiding that I didn't catch.

> 
>>
>> Reviewed-by: Zi Yan <ziy@nvidia.com>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
> 
> LGTM, so:
> 
> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> 

Thanks!

-- 
Cheers,

David / dhildenb
Re: [PATCH v1 23/29] mm/page-alloc: remove PageMappingFlags()
Posted by Lorenzo Stoakes 3 months, 1 week ago
On Tue, Jul 01, 2025 at 09:34:41PM +0200, David Hildenbrand wrote:
> On 01.07.25 15:02, Lorenzo Stoakes wrote:
> > On Mon, Jun 30, 2025 at 03:00:04PM +0200, David Hildenbrand wrote:
> > > We can now simply check for PageAnon() and remove PageMappingFlags().
> > >
> > > ... and while at it, use the folio instead and operate on
> > > folio->mapping.
> >
> > Probably worth mentioning to be super crystal clear that this is because
> > now it's either an anon folio or a KSM folio, both of which set the
> > FOLIO_MAPPING_ANON flag.
>
> "As PageMappingFlags() now only indicates anon (incl. ksm) folios, we can
> now simply check for PageAnon() and remove PageMappingFlags()."

Sounds good! Though the extremely nitty part of me says 'capitalise KSM' :P

>
>
> >
> > I wonder if there's other places that could be fixed up similarly that do
> > folio_test_anon() || folio_test_ksm() or equivalent?
>
> I think you spotted the one in patch #25 :)

:)

>
> I looked for others while crafting this patch, but there might be more
> hiding that I didn't catch.

Yeah, one we can keep an eye out for.

>
> >
> > >
> > > Reviewed-by: Zi Yan <ziy@nvidia.com>
> > > Signed-off-by: David Hildenbrand <david@redhat.com>
> >
> > LGTM, so:
> >
> > Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> >
>
> Thanks!
>
> --
> Cheers,
>
> David / dhildenb
>
Re: [PATCH v1 23/29] mm/page-alloc: remove PageMappingFlags()
Posted by David Hildenbrand 3 months, 1 week ago
On 02.07.25 10:49, Lorenzo Stoakes wrote:
> On Tue, Jul 01, 2025 at 09:34:41PM +0200, David Hildenbrand wrote:
>> On 01.07.25 15:02, Lorenzo Stoakes wrote:
>>> On Mon, Jun 30, 2025 at 03:00:04PM +0200, David Hildenbrand wrote:
>>>> We can now simply check for PageAnon() and remove PageMappingFlags().
>>>>
>>>> ... and while at it, use the folio instead and operate on
>>>> folio->mapping.
>>>
>>> Probably worth mentioning to be super crystal clear that this is because
>>> now it's either an anon folio or a KSM folio, both of which set the
>>> FOLIO_MAPPING_ANON flag.
>>
>> "As PageMappingFlags() now only indicates anon (incl. ksm) folios, we can
>> now simply check for PageAnon() and remove PageMappingFlags()."
> 
> Sounds good! Though the extremely nitty part of me says 'capitalise KSM' :P

Like we do so consistently with vma, pte and all the other acronyms ;)

Can do!

-- 
Cheers,

David / dhildenb
Re: [PATCH v1 23/29] mm/page-alloc: remove PageMappingFlags()
Posted by Lorenzo Stoakes 3 months, 1 week ago
On Wed, Jul 02, 2025 at 11:02:21AM +0200, David Hildenbrand wrote:
> On 02.07.25 10:49, Lorenzo Stoakes wrote:
> > On Tue, Jul 01, 2025 at 09:34:41PM +0200, David Hildenbrand wrote:
> > > On 01.07.25 15:02, Lorenzo Stoakes wrote:
> > > > On Mon, Jun 30, 2025 at 03:00:04PM +0200, David Hildenbrand wrote:
> > > > > We can now simply check for PageAnon() and remove PageMappingFlags().
> > > > >
> > > > > ... and while at it, use the folio instead and operate on
> > > > > folio->mapping.
> > > >
> > > > Probably worth mentioning to be super crystal clear that this is because
> > > > now it's either an anon folio or a KSM folio, both of which set the
> > > > FOLIO_MAPPING_ANON flag.
> > >
> > > "As PageMappingFlags() now only indicates anon (incl. ksm) folios, we can
> > > now simply check for PageAnon() and remove PageMappingFlags()."
> >
> > Sounds good! Though the extremely nitty part of me says 'capitalise KSM' :P
>
> Like we do so consistently with vma, pte and all the other acronyms ;)

Don't forget pae which now means something different depending on whether you're
talking about x86-64 page tables or anon exclusive flags... :>)

Yeah, I mean it's throwing teaspoons of water out of a reservoir but might as
well :P

>
> Can do!
>
> --
> Cheers,
>
> David / dhildenb
>
Re: [PATCH v1 23/29] mm/page-alloc: remove PageMappingFlags()
Posted by David Hildenbrand 3 months, 1 week ago
On 02.07.25 11:09, Lorenzo Stoakes wrote:
> On Wed, Jul 02, 2025 at 11:02:21AM +0200, David Hildenbrand wrote:
>> On 02.07.25 10:49, Lorenzo Stoakes wrote:
>>> On Tue, Jul 01, 2025 at 09:34:41PM +0200, David Hildenbrand wrote:
>>>> On 01.07.25 15:02, Lorenzo Stoakes wrote:
>>>>> On Mon, Jun 30, 2025 at 03:00:04PM +0200, David Hildenbrand wrote:
>>>>>> We can now simply check for PageAnon() and remove PageMappingFlags().
>>>>>>
>>>>>> ... and while at it, use the folio instead and operate on
>>>>>> folio->mapping.
>>>>>
>>>>> Probably worth mentioning to be super crystal clear that this is because
>>>>> now it's either an anon folio or a KSM folio, both of which set the
>>>>> FOLIO_MAPPING_ANON flag.
>>>>
>>>> "As PageMappingFlags() now only indicates anon (incl. ksm) folios, we can
>>>> now simply check for PageAnon() and remove PageMappingFlags()."
>>>
>>> Sounds good! Though the extremely nitty part of me says 'capitalise KSM' :P
>>
>> Like we do so consistently with vma, pte and all the other acronyms ;)
> 
> Don't forget pae which now means something different depending on whether you're
> talking about x86-64 page tables or anon exclusive flags... :>)

Heh, I don't think we ever used PAE in the src + git log when talking 
about PageAnonExclusive at least :)

-- 
Cheers,

David / dhildenb