From: Hugh Dickins try_to_unmap always fails on a page found in a VM_LOCKED vma (unless migrating), and recycles it back to the active list. But if it's an anonymous page, we've already allocated swap to it: just wasting swap. Spot locked pages in page_referenced_one and treat them as referenced. Signed-off-by: Hugh Dickins Tested-by: KAMEZAWA Hiroyuki Cc: Ethan Solomita Signed-off-by: Andrew Morton --- mm/rmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff -puN mm/rmap.c~mm-dont-waste-swap-on-locked-pages mm/rmap.c --- a/mm/rmap.c~mm-dont-waste-swap-on-locked-pages +++ a/mm/rmap.c @@ -283,7 +283,10 @@ static int page_referenced_one(struct pa if (!pte) goto out; - if (ptep_clear_flush_young(vma, address, pte)) + if (vma->vm_flags & VM_LOCKED) { + referenced++; + *mapcount = 1; /* break early from loop */ + } else if (ptep_clear_flush_young(vma, address, pte)) referenced++; /* Pretend the page is referenced if the task has the _