]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm/ksm: use vma iterators instead of vma linked list
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 6 Sep 2022 19:49:01 +0000 (19:49 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 27 Sep 2022 02:46:23 +0000 (19:46 -0700)
Remove the use of the linked list for eventual removal.

Link: https://lkml.kernel.org/r/20220906194824.2110408-54-Liam.Howlett@oracle.com
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Tested-by: Yu Zhao <yuzhao@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: SeongJae Park <sj@kernel.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/ksm.c

index fd6d03cb04638e8320d56e48d142c676f51d9953..533ede86b4b9f45f6471dfeaca478b9a5dfd19d8 100644 (file)
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -981,11 +981,13 @@ static int unmerge_and_remove_all_rmap_items(void)
                                                struct mm_slot, mm_list);
        spin_unlock(&ksm_mmlist_lock);
 
-       for (mm_slot = ksm_scan.mm_slot;
-                       mm_slot != &ksm_mm_head; mm_slot = ksm_scan.mm_slot) {
+       for (mm_slot = ksm_scan.mm_slot; mm_slot != &ksm_mm_head;
+            mm_slot = ksm_scan.mm_slot) {
+               VMA_ITERATOR(vmi, mm_slot->mm, 0);
+
                mm = mm_slot->mm;
                mmap_read_lock(mm);
-               for (vma = mm->mmap; vma; vma = vma->vm_next) {
+               for_each_vma(vmi, vma) {
                        if (ksm_test_exit(mm))
                                break;
                        if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
@@ -2243,6 +2245,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
        struct mm_slot *slot;
        struct vm_area_struct *vma;
        struct rmap_item *rmap_item;
+       struct vma_iterator vmi;
        int nid;
 
        if (list_empty(&ksm_mm_head.mm_list))
@@ -2301,13 +2304,13 @@ next_mm:
        }
 
        mm = slot->mm;
+       vma_iter_init(&vmi, mm, ksm_scan.address);
+
        mmap_read_lock(mm);
        if (ksm_test_exit(mm))
-               vma = NULL;
-       else
-               vma = find_vma(mm, ksm_scan.address);
+               goto no_vmas;
 
-       for (; vma; vma = vma->vm_next) {
+       for_each_vma(vmi, vma) {
                if (!(vma->vm_flags & VM_MERGEABLE))
                        continue;
                if (ksm_scan.address < vma->vm_start)
@@ -2345,6 +2348,7 @@ next_mm:
        }
 
        if (ksm_test_exit(mm)) {
+no_vmas:
                ksm_scan.address = 0;
                ksm_scan.rmap_list = &slot->rmap_list;
        }