Re: [PATCHv4 4/8] khugepaged: Drain LRU add pagevec after swapin

From: Kirill A. Shutemov
Date: Fri Apr 17 2020 - 10:59:14 EST


On Thu, Apr 16, 2020 at 09:41:45PM -0700, Andrew Morton wrote:
> On Thu, 16 Apr 2020 19:00:22 +0300 "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx> wrote:
>
> > __collapse_huge_page_isolate() may fail due to extra pin in the LRU add
> > pagevec. It's pretty common for swapin case: we swap in pages just to
> > fail due to the extra pin.
> >
> > Drain LRU add pagevec on successful swapin.
>
> I don't see how this patch can do anything to prevent
> __collapse_huge_page_isolate() from failing, which is what the
> changelog implies.
>
> Can we have a more detailed changelog, please?

What about something like this:

khugepaged: Drain LRU add pagevec after swapin

collapse_huge_page() tries to swap in pages that are part of the PMD
range. Just swapped in page goes though LRU add cache. The cache gets
extra reference on the page.

The extra reference can lead to the collapse fail: the following
__collapse_huge_page_isolate() would check refcount and abort collapse
seeing unexpected refcount.

The fix is to drain local LRU add cache in __collapse_huge_page_swapin()
if we successfully swapped in any pages.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
Reviewed-by: William Kucharski <william.kucharski@xxxxxxxxxx>
Reviewed-and-Tested-by: Zi Yan <ziy@xxxxxxxxxx>
Acked-by: Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx>


--
Kirill A. Shutemov