]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: remove duplicated open-coded VMA policy check
authorLorenzo Stoakes <lorenzo.stoakes@oracle.com>
Fri, 30 Aug 2024 18:10:16 +0000 (19:10 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 4 Sep 2024 04:15:54 +0000 (21:15 -0700)
Both can_vma_merge_before() and can_vma_merge_after() are invoked after
checking for compatible VMA NUMA policy, we can simply move this to
is_mergeable_vma() and abstract this altogether.

In mmap_region() we set vmg->policy to NULL, so the policy comparisons
checked in can_vma_merge_before() and can_vma_merge_after() are exactly
equivalent to !vma_policy(vmg.next) and !vma_policy(vmg.prev).

Equally, in do_brk_flags(), vmg->policy is NULL, so the
can_vma_merge_after() is checking !vma_policy(vma), as we set vmg.prev to
vma.

In vma_merge(), we compare prev and next policies with vmg->policy before
checking can_vma_merge_after() and can_vma_merge_before() respectively,
which this patch causes to be checked in precisely the same way.

This therefore maintains precisely the same logic as before, only now
abstracted into is_mergeable_vma().

Link: https://lkml.kernel.org/r/0dbff286d9c4988333bc6f4ff3734cb95dd5410a.1725040657.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Bert Karwatzki <spasswolf@web.de>
Cc: Jeff Xu <jeffxu@chromium.org>
Cc: Jiri Olsa <olsajiri@gmail.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mmap.c
mm/vma.c

index ca9c6939638b02b91537b255c92ce7fe6f00263a..3af8459e4e885b471882fe72c49433c914737231 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1423,8 +1423,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
 
        /* Attempt to expand an old mapping */
        /* Check next */
-       if (next && next->vm_start == end && !vma_policy(next) &&
-           can_vma_merge_before(&vmg)) {
+       if (next && next->vm_start == end && can_vma_merge_before(&vmg)) {
                merge_end = next->vm_end;
                vma = next;
                vmg.pgoff = next->vm_pgoff - pglen;
@@ -1438,8 +1437,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
        }
 
        /* Check prev */
-       if (prev && prev->vm_end == addr && !vma_policy(prev) &&
-           can_vma_merge_after(&vmg)) {
+       if (prev && prev->vm_end == addr && can_vma_merge_after(&vmg)) {
                merge_start = prev->vm_start;
                vma = prev;
                vmg.pgoff = prev->vm_pgoff;
@@ -1779,7 +1777,7 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma,
         * Expand the existing vma if possible; Note that singular lists do not
         * occur after forking, so the expand will only happen on new VMAs.
         */
-       if (vma && vma->vm_end == addr && !vma_policy(vma)) {
+       if (vma && vma->vm_end == addr) {
                VMG_STATE(vmg, mm, vmi, addr, addr + len, flags, PHYS_PFN(addr));
 
                vmg.prev = vma;
index 6be645240f07208096bac18d1d8fe7d29f7c733e..3284bb778c3dae7326275b54dbdf6f3ae6ead4e8 100644 (file)
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -19,6 +19,8 @@ static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_nex
         */
        bool may_remove_vma = merge_next;
 
+       if (!mpol_equal(vmg->policy, vma_policy(vma)))
+               return false;
        /*
         * VM_SOFTDIRTY should not prevent from VMA merging, if we
         * match the flags but dirty bit -- the caller should mark
@@ -1053,17 +1055,14 @@ static struct vm_area_struct *vma_merge(struct vma_merge_struct *vmg)
                vma_pgoff = prev->vm_pgoff;
 
                /* Can we merge the predecessor? */
-               if (addr == prev->vm_end && mpol_equal(vma_policy(prev), vmg->policy)
-                   && can_vma_merge_after(vmg)) {
-
+               if (addr == prev->vm_end && can_vma_merge_after(vmg)) {
                        merge_prev = true;
                        vma_prev(vmg->vmi);
                }
        }
 
        /* Can we merge the successor? */
-       if (next && mpol_equal(vmg->policy, vma_policy(next)) &&
-           can_vma_merge_before(vmg)) {
+       if (next && can_vma_merge_before(vmg)) {
                merge_next = true;
        }