Re: [PATCH 5/7] khugepaged: Allow to collapse PTE-mapped compound pages

From: Kirill A. Shutemov
Date: Sat Mar 28 2020 - 08:27:35 EST


On Fri, Mar 27, 2020 at 06:09:38PM -0700, Yang Shi wrote:
> On Fri, Mar 27, 2020 at 5:34 PM Kirill A. Shutemov <kirill@xxxxxxxxxxxxx> wrote:
> >
> > On Fri, Mar 27, 2020 at 11:53:57AM -0700, Yang Shi wrote:
> > > On Fri, Mar 27, 2020 at 10:06 AM Kirill A. Shutemov
> > > <kirill@xxxxxxxxxxxxx> wrote:
> > > >
> > > > We can collapse PTE-mapped compound pages. We only need to avoid
> > > > handling them more than once: lock/unlock page only once if it's present
> > > > in the PMD range multiple times as it handled on compound level. The
> > > > same goes for LRU isolation and putpack.
> > > >
> > > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
> > > > ---
> > > > mm/khugepaged.c | 41 +++++++++++++++++++++++++++++++----------
> > > > 1 file changed, 31 insertions(+), 10 deletions(-)
> > > >
> > > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> > > > index b47edfe57f7b..c8c2c463095c 100644
> > > > --- a/mm/khugepaged.c
> > > > +++ b/mm/khugepaged.c
> > > > @@ -515,6 +515,17 @@ void __khugepaged_exit(struct mm_struct *mm)
> > > >
> > > > static void release_pte_page(struct page *page)
> > > > {
> > > > + /*
> > > > + * We need to unlock and put compound page on LRU only once.
> > > > + * The rest of the pages have to be locked and not on LRU here.
> > > > + */
> > > > + VM_BUG_ON_PAGE(!PageCompound(page) &&
> > > > + (!PageLocked(page) && PageLRU(page)), page);
> > > > +
> > > > + if (!PageLocked(page))
> > > > + return;
> > > > +
> > > > + page = compound_head(page);
> > > > dec_node_page_state(page, NR_ISOLATED_ANON + page_is_file_cache(page));
> > >
> > > We need count in the number of base pages. The same counter is
> > > modified by vmscan in base page unit.
> >
> > Is it though? Where?
>
> __mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, nr_taken) in
> vmscan.c, here nr_taken is nr_compound(page), so if it is THP the
> number would be 512.

Could you point a particular codepath?

> So in both inc and dec path of collapse PTE mapped THP, we should mod
> nr_compound(page) too.

I disagree. Compound page is represented by single entry on LRU, so it has
to be counted once.

--
Kirill A. Shutemov