Commit 8eaedede authored by Kirill A. Shutemov's avatar Kirill A. Shutemov Committed by Linus Torvalds

mm: fix handling PTE-mapped THPs in page_referenced()

For PTE-mapped THP page_check_address_transhuge() is not adequate: it
cannot find all relevant PTEs, only the first one.  It means we can miss
some references of the page and it can result in suboptimal decisions by
vmscan.

Let's switch it to page_vma_mapped_walk().

I don't think it's subject for stable@: it's not fatal.  The only side
effect is that THP can be swapped out when it shouldn't.

Link: http://lkml.kernel.org/r/20170129173858.45174-4-kirill.shutemov@linux.intel.comSigned-off-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hillf Danton <hillf.zj@alibaba-inc.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ace71a19
...@@ -886,45 +886,48 @@ struct page_referenced_arg { ...@@ -886,45 +886,48 @@ struct page_referenced_arg {
static int page_referenced_one(struct page *page, struct vm_area_struct *vma, static int page_referenced_one(struct page *page, struct vm_area_struct *vma,
unsigned long address, void *arg) unsigned long address, void *arg)
{ {
struct mm_struct *mm = vma->vm_mm;
struct page_referenced_arg *pra = arg; struct page_referenced_arg *pra = arg;
pmd_t *pmd; struct page_vma_mapped_walk pvmw = {
pte_t *pte; .page = page,
spinlock_t *ptl; .vma = vma,
.address = address,
};
int referenced = 0; int referenced = 0;
if (!page_check_address_transhuge(page, mm, address, &pmd, &pte, &ptl)) while (page_vma_mapped_walk(&pvmw)) {
return SWAP_AGAIN; address = pvmw.address;
if (vma->vm_flags & VM_LOCKED) { if (vma->vm_flags & VM_LOCKED) {
if (pte) page_vma_mapped_walk_done(&pvmw);
pte_unmap(pte); pra->vm_flags |= VM_LOCKED;
spin_unlock(ptl); return SWAP_FAIL; /* To break the loop */
pra->vm_flags |= VM_LOCKED; }
return SWAP_FAIL; /* To break the loop */
}
if (pte) { if (pvmw.pte) {
if (ptep_clear_flush_young_notify(vma, address, pte)) { if (ptep_clear_flush_young_notify(vma, address,
/* pvmw.pte)) {
* Don't treat a reference through a sequentially read /*
* mapping as such. If the page has been used in * Don't treat a reference through
* another mapping, we will catch it; if this other * a sequentially read mapping as such.
* mapping is already gone, the unmap path will have * If the page has been used in another mapping,
* set PG_referenced or activated the page. * we will catch it; if this other mapping is
*/ * already gone, the unmap path will have set
if (likely(!(vma->vm_flags & VM_SEQ_READ))) * PG_referenced or activated the page.
*/
if (likely(!(vma->vm_flags & VM_SEQ_READ)))
referenced++;
}
} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
if (pmdp_clear_flush_young_notify(vma, address,
pvmw.pmd))
referenced++; referenced++;
} else {
/* unexpected pmd-mapped page? */
WARN_ON_ONCE(1);
} }
pte_unmap(pte);
} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { pra->mapcount--;
if (pmdp_clear_flush_young_notify(vma, address, pmd))
referenced++;
} else {
/* unexpected pmd-mapped page? */
WARN_ON_ONCE(1);
} }
spin_unlock(ptl);
if (referenced) if (referenced)
clear_page_idle(page); clear_page_idle(page);
...@@ -936,7 +939,6 @@ static int page_referenced_one(struct page *page, struct vm_area_struct *vma, ...@@ -936,7 +939,6 @@ static int page_referenced_one(struct page *page, struct vm_area_struct *vma,
pra->vm_flags |= vma->vm_flags; pra->vm_flags |= vma->vm_flags;
} }
pra->mapcount--;
if (!pra->mapcount) if (!pra->mapcount)
return SWAP_SUCCESS; /* To break the loop */ return SWAP_SUCCESS; /* To break the loop */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment