Skip to content

Commit 2351907

Browse files
kiryltorvalds
authored andcommitted
oom-reaper: use madvise_dontneed() logic to decide if unmap the VMA
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/[email protected] Signed-off-by: Kirill A. Shutemov <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Tetsuo Handa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Rik van Riel <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ecf1385 commit 2351907

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

mm/internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ int do_swap_page(struct vm_fault *vmf);
4343
void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
4444
unsigned long floor, unsigned long ceiling);
4545

46+
static inline bool can_madv_dontneed_vma(struct vm_area_struct *vma)
47+
{
48+
return !(vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP));
49+
}
50+
4651
void unmap_page_range(struct mmu_gather *tlb,
4752
struct vm_area_struct *vma,
4853
unsigned long addr, unsigned long end,

mm/madvise.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <asm/tlb.h>
2727

28+
#include "internal.h"
29+
2830
/*
2931
* Any behaviour which results in changes to the vma->vm_flags needs to
3032
* take mmap_sem for writing. Others, which simply traverse vmas, need
@@ -474,7 +476,7 @@ static long madvise_dontneed(struct vm_area_struct *vma,
474476
unsigned long start, unsigned long end)
475477
{
476478
*prev = vma;
477-
if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
479+
if (!can_madv_dontneed_vma(vma))
478480
return -EINVAL;
479481

480482
madvise_userfault_dontneed(vma, prev, start, end);

mm/oom_kill.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,14 +508,7 @@ static bool __oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm)
508508

509509
tlb_gather_mmu(&tlb, mm, 0, -1);
510510
for (vma = mm->mmap ; vma; vma = vma->vm_next) {
511-
if (is_vm_hugetlb_page(vma))
512-
continue;
513-
514-
/*
515-
* mlocked VMAs require explicit munlocking before unmap.
516-
* Let's keep it simple here and skip such VMAs.
517-
*/
518-
if (vma->vm_flags & VM_LOCKED)
511+
if (!can_madv_dontneed_vma(vma))
519512
continue;
520513

521514
/*

0 commit comments

Comments
 (0)