Skip to content

Commit 5c64f52

Browse files
Naoya Horiguchitorvalds
authored andcommitted
clear_refs: remove clear_refs_private->vma and introduce clear_refs_test_walk()
clear_refs_write() has some prechecks to determine if we really walk over a given vma. Now we have a test_walk() callback to filter vmas, so let's utilize it. Signed-off-by: Naoya Horiguchi <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Cyrill Gorcunov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Pavel Emelyanov <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 14eb6fd commit 5c64f52

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

fs/proc/task_mmu.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,6 @@ enum clear_refs_types {
736736
};
737737

738738
struct clear_refs_private {
739-
struct vm_area_struct *vma;
740739
enum clear_refs_types type;
741740
};
742741

@@ -767,7 +766,7 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
767766
unsigned long end, struct mm_walk *walk)
768767
{
769768
struct clear_refs_private *cp = walk->private;
770-
struct vm_area_struct *vma = cp->vma;
769+
struct vm_area_struct *vma = walk->vma;
771770
pte_t *pte, ptent;
772771
spinlock_t *ptl;
773772
struct page *page;
@@ -801,6 +800,25 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
801800
return 0;
802801
}
803802

803+
static int clear_refs_test_walk(unsigned long start, unsigned long end,
804+
struct mm_walk *walk)
805+
{
806+
struct clear_refs_private *cp = walk->private;
807+
struct vm_area_struct *vma = walk->vma;
808+
809+
/*
810+
* Writing 1 to /proc/pid/clear_refs affects all pages.
811+
* Writing 2 to /proc/pid/clear_refs only affects anonymous pages.
812+
* Writing 3 to /proc/pid/clear_refs only affects file mapped pages.
813+
* Writing 4 to /proc/pid/clear_refs affects all pages.
814+
*/
815+
if (cp->type == CLEAR_REFS_ANON && vma->vm_file)
816+
return 1;
817+
if (cp->type == CLEAR_REFS_MAPPED && !vma->vm_file)
818+
return 1;
819+
return 0;
820+
}
821+
804822
static ssize_t clear_refs_write(struct file *file, const char __user *buf,
805823
size_t count, loff_t *ppos)
806824
{
@@ -841,6 +859,7 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
841859
};
842860
struct mm_walk clear_refs_walk = {
843861
.pmd_entry = clear_refs_pte_range,
862+
.test_walk = clear_refs_test_walk,
844863
.mm = mm,
845864
.private = &cp,
846865
};
@@ -860,28 +879,7 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
860879
}
861880
mmu_notifier_invalidate_range_start(mm, 0, -1);
862881
}
863-
for (vma = mm->mmap; vma; vma = vma->vm_next) {
864-
cp.vma = vma;
865-
if (is_vm_hugetlb_page(vma))
866-
continue;
867-
/*
868-
* Writing 1 to /proc/pid/clear_refs affects all pages.
869-
*
870-
* Writing 2 to /proc/pid/clear_refs only affects
871-
* Anonymous pages.
872-
*
873-
* Writing 3 to /proc/pid/clear_refs only affects file
874-
* mapped pages.
875-
*
876-
* Writing 4 to /proc/pid/clear_refs affects all pages.
877-
*/
878-
if (type == CLEAR_REFS_ANON && vma->vm_file)
879-
continue;
880-
if (type == CLEAR_REFS_MAPPED && !vma->vm_file)
881-
continue;
882-
walk_page_range(vma->vm_start, vma->vm_end,
883-
&clear_refs_walk);
884-
}
882+
walk_page_range(0, ~0UL, &clear_refs_walk);
885883
if (type == CLEAR_REFS_SOFT_DIRTY)
886884
mmu_notifier_invalidate_range_end(mm, 0, -1);
887885
flush_tlb_mm(mm);

0 commit comments

Comments
 (0)