Re: [PATCH v2] mm: fix long time stall from mm_populate

From: Matthew Wilcox
Date: Mon Mar 02 2020 - 20:22:07 EST


On Mon, Mar 02, 2020 at 04:26:38PM -0800, Minchan Kim wrote:
> @@ -1196,6 +1196,7 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
> struct vm_area_struct *vma = NULL;
> int locked = 0;
> long ret = 0;
> + bool tried = false;

How about ...

int *lockedp = &locked;

>
> end = start + len;
>
> @@ -1226,14 +1227,18 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
> * double checks the vma flags, so that it won't mlock pages
> * if the vma was already munlocked.
> */
> - ret = populate_vma_page_range(vma, nstart, nend, &locked);
> + ret = populate_vma_page_range(vma, nstart, nend,
> + tried ? NULL : &locked);

ret = populate_vma_page_range(vma, nstart, nend, lockedp);

> if (ret < 0) {
> if (ignore_errors) {
> ret = 0;
> continue; /* continue at next VMA */
> }
> break;
> - }
> + } else if (ret == 0)
> + tried = true;
> + else
> + tried = false;

} else if (ret == 0)
lockedp = NULL;

Maybe there's a better name than lockedp.