oom-reaper: use madvise_dontneed() logic to decide if unmap the VMA
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Wed, 22 Feb 2017 23:46:39 +0000 (15:46 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 23 Feb 2017 00:41:30 +0000 (16:41 -0800)
Logic on whether we can reap pages from the VMA should match what we
have in madvise_dontneed().  In particular, we should skip, VM_PFNMAP
VMAs, but we don't now.

Let's just extract condition on which we can shoot down pagesi from a
VMA with MADV_DONTNEED into separate function and use it in both places.

Link: http://lkml.kernel.org/r/20170118122429.43661-4-kirill.shutemov@linux.intel.com
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/internal.h
mm/madvise.c
mm/oom_kill.c

index 9ad04fc6eefebf15838da349830305ca58caaeb8..8ab72f4374e046e604cc7c5f15049f960f1b864e 100644 (file)
@@ -43,6 +43,11 @@ int do_swap_page(struct vm_fault *vmf);
 void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
                unsigned long floor, unsigned long ceiling);
 
+static inline bool can_madv_dontneed_vma(struct vm_area_struct *vma)
+{
+       return !(vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP));
+}
+
 void unmap_page_range(struct mmu_gather *tlb,
                             struct vm_area_struct *vma,
                             unsigned long addr, unsigned long end,
index 7f1490f0d3a677aea8d9ea07a9f35808cb91a363..b530a4986035bac08c12c996600f19fddb597acb 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <asm/tlb.h>
 
+#include "internal.h"
+
 /*
  * Any behaviour which results in changes to the vma->vm_flags needs to
  * take mmap_sem for writing. Others, which simply traverse vmas, need
@@ -474,7 +476,7 @@ static long madvise_dontneed(struct vm_area_struct *vma,
                             unsigned long start, unsigned long end)
 {
        *prev = vma;
-       if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
+       if (!can_madv_dontneed_vma(vma))
                return -EINVAL;
 
        madvise_userfault_dontneed(vma, prev, start, end);
index a1977247c7ea5276c82e7fcd7bc55f6e633cda78..8256788ac119679cb66d3b5b63c6797ba384d506 100644 (file)
@@ -508,14 +508,7 @@ static bool __oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm)
 
        tlb_gather_mmu(&tlb, mm, 0, -1);
        for (vma = mm->mmap ; vma; vma = vma->vm_next) {
-               if (is_vm_hugetlb_page(vma))
-                       continue;
-
-               /*
-                * mlocked VMAs require explicit munlocking before unmap.
-                * Let's keep it simple here and skip such VMAs.
-                */
-               if (vma->vm_flags & VM_LOCKED)
+               if (!can_madv_dontneed_vma(vma))
                        continue;
 
                /*