Re: [PATCH] mm: unified folio_test_anon()/folio_anon_vma() and use them
From: Yajun Deng
Date: Thu Jul 11 2024 - 22:30:02 EST
July 11, 2024 at 9:08 PM, "Matthew Wilcox" <willy@xxxxxxxxxxxxx> wrote:
>
> On Thu, Jul 11, 2024 at 09:03:51PM +0800, Yajun Deng wrote:
>
> >
> > +++ b/include/linux/page-flags.h
> >
> > @@ -691,7 +691,8 @@ static __always_inline bool PageMappingFlags(const struct page *page)
> >
> >
> >
> > static __always_inline bool folio_test_anon(const struct folio *folio)
> >
> > {
> >
> > - return ((unsigned long)folio->mapping & PAGE_MAPPING_ANON) != 0;
> >
> > + return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) ==
> >
> > + PAGE_MAPPING_ANON;
> >
> > }
> >
>
> This is wrong. KSM pages are supposed to return true for
>
> folio_test_anon(). I haven't looked any further at this patch, since
>
> the premise appears to wrong and you clearly haven't tested.
>
Thank you for pointing this out. It was my mistake!
I think I need to add a new helper function, like __folio_test_movable. e.g.
static __always_inline bool __folio_test_anon(const struct folio *folio)
{
return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) ==
PAGE_MAPPING_ANON;
}