Re: [PATCH] mm: Add PageLayzyFree() helper functions for MADV_FREE

From: David Rientjes
Date: Tue Mar 03 2020 - 20:27:09 EST


On Tue, 3 Mar 2020, Andrew Morton wrote:

> On Tue, 3 Mar 2020 11:37:38 +0800 "Huang, Ying" <ying.huang@xxxxxxxxx> wrote:
>
> > From: Huang Ying <ying.huang@xxxxxxxxx>
> >
> > Now PageSwapBacked() is used as the helper function to check whether
> > pages have been freed lazily via MADV_FREE. This isn't very obvious.
> > So Dave suggested to add PageLazyFree() family helper functions to
> > improve the code readability.
> >
> > --- a/include/linux/page-flags.h
> > +++ b/include/linux/page-flags.h
> > @@ -498,6 +498,31 @@ static __always_inline int PageKsm(struct page *page)
> > TESTPAGEFLAG_FALSE(Ksm)
> > #endif
> >
> > +/*
> > + * For pages freed lazily via MADV_FREE. lazyfree pages are clean
> > + * anonymous pages. They have SwapBacked flag cleared to distinguish
> > + * with normal anonymous pages
> > + */
> > +static __always_inline int PageLazyFree(struct page *page)
> > +{
> > + page = compound_head(page);
> > + return PageAnon(page) && !PageSwapBacked(page);
> > +}
> > +
> > +static __always_inline void SetPageLazyFree(struct page *page)
> > +{
> > + VM_BUG_ON_PAGE(PageTail(page), page);
> > + VM_BUG_ON_PAGE(!PageAnon(page), page);
> > + ClearPageSwapBacked(page);
> > +}
> > +
> > +static __always_inline void ClearPageLazyFree(struct page *page)
> > +{
> > + VM_BUG_ON_PAGE(PageTail(page), page);
> > + VM_BUG_ON_PAGE(!PageAnon(page), page);
> > + SetPageSwapBacked(page);
> > +}
>
> These BUG_ONs aren't present in the current code and are
> unchangelogged.
>

Yeah, as well as the implicit conversion to check compound_head().