Message ID | bf56244f473e6ac9378cfce420b51c4dac7783a7.1722849859.git.lorenzo.stoakes@oracle.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm: remove vma_merge() | expand |
On Mon, 5 Aug 2024 13:13:50 +0100 Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote: > 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. > > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> > --- > mm/mmap.c | 8 +++----- > mm/vma.c | 9 ++++----- > 2 files changed, 7 insertions(+), 10 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index f931000c561f..721ced6e37b0 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1422,8 +1422,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; > @@ -1435,8 +1434,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; > @@ -1798,7 +1796,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) { > struct vma_merge_struct vmg = { > .prev = vma, > .flags = flags, > diff --git a/mm/vma.c b/mm/vma.c > index 20c4ce7712c0..b452b472a085 100644 > --- 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 > @@ -971,17 +973,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; > } > Looks good. Petr T
diff --git a/mm/mmap.c b/mm/mmap.c index f931000c561f..721ced6e37b0 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1422,8 +1422,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; @@ -1435,8 +1434,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; @@ -1798,7 +1796,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) { struct vma_merge_struct vmg = { .prev = vma, .flags = flags, diff --git a/mm/vma.c b/mm/vma.c index 20c4ce7712c0..b452b472a085 100644 --- 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 @@ -971,17 +973,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; }
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. Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> --- mm/mmap.c | 8 +++----- mm/vma.c | 9 ++++----- 2 files changed, 7 insertions(+), 10 deletions(-)