mm/mmap: convert all mas except mas_detach to vma iterator
Subsystems (3)
PATCH v2 1/1 mm/mmap: convert all mas except mas_detach to vma iterator
There are two types of iterators mas and vmi in the current code. If the maple tree comes from the mm struct, we can use the vma iterator. Avoid using mas directly as possible.
Keep using mas for the mt_detach tree, since it doesn't come from the mm struct.
Remove as many mas uses as feasible, but we will still have a few that must be passed through in unmap_vmas() and free_pgtables().
Also introduce vma_iter_reset, vma_iter_{prev, next}_range_limit and vma_iter_area_{lowest, highest} helper functions for using vma interator.
---
v2: Add vma_iter_reset() and vma_iter_{prev, next}_range_limit() helper functions.
v1: https://lore.kernel.org/all/[email protected]/
--- mm/internal.h | 29 +++++++++++++ mm/mmap.c | 113 +++++++++++++++++++++++++------------------------- 2 files changed, 85 insertions(+), 57 deletions(-)
mm/internal.h +29 -0
@@ -1149,6 +1149,35 @@ static inline void vma_iter_config(struct vma_iterator *vmi,__mas_set_range (&vmi->mas, index, last -1 ); } +static inline void vma_iter_reset (struct vma_iterator *vmi) +{ +mas_reset (&vmi->mas); +} + +static inline +struct vm_area_struct *vma_iter_prev_range_limit (struct vma_iterator *vmi,unsigned long min) +{ +return mas_prev_range (&vmi->mas, min); +} + +static inline +struct vm_area_struct *vma_iter_next_range_limit (struct vma_iterator *vmi,unsigned long max) +{ +return mas_next_range (&vmi->mas, max); +} + +static inline int vma_iter_area_lowest (struct vma_iterator *vmi,unsigned long min, +unsigned long max,unsigned long size) +{ +return mas_empty_area (&vmi->mas, min, max -1 , size); +} + +static inline int vma_iter_area_highest (struct vma_iterator *vmi,unsigned long min, +unsigned long max,unsigned long size) +{ +return mas_empty_area_rev (&vmi->mas, min, max -1 , size); +} +/* * VMA Iterator functions shared between nommu and mmap */
mm/mmap.c +56 -57
325 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 4 lines
There are two types of iterators mas and vmi in the current code. If the maple tree comes from the mm struct, we can use the vma iterator. Avoid using mas directly as possible.
Helge,
Yajun has changed code that affects parisc with this patch, which hasn't been tested.
Quoted 14 lines · Yajun Deng
Keep using mas for the
mt_detachtree, since it doesn't come from the mm struct.Remove as many mas uses as feasible, but we will still have a few that must be passed through in
unmap_vmas()andfree_pgtables().Also introduce
vma_iter_reset, vma_iter_{prev, next}_range_limit and vma_iter_area_{lowest, highest} helper functions for using vma interator.Signed-off-by Yajun Deng <[email protected]>---
v2: Addvma_iter_reset()and vma_iter_{prev, next}_range_limit() helper functions.
v1: https://lore.kernel.org/all/[email protected]/
---
...
Quoted 40 lines
mm/mmap.c +6
-6@@ -1975,7 +1974,7 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address)struct vm_area_struct *next;unsigned long gap_addr;int error =0 ; -MA_STATE (mas, &mm->mm_mt, vma->vm_start, address); +VMA_ITERATOR (vmi, mm, vma->vm_start);if (!(vma->vm_flags &VM_GROWSUP ))return -EFAULT ;@@ -2001,15 +2000,15 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address) }if (next) -mas_prev_range (&mas, address); +vma_iter_prev_range_limit (&vmi, address); -__mas_set_range (&mas, vma->vm_start, address -1 ); -if (mas_preallocate (&mas, vma,GFP_KERNEL )) +vma_iter_config (&vmi, vma->vm_start, address); +if (vma_iter_prealloc (&vmi, vma))return -ENOMEM ;/* We must make sure the anon_vma is allocated. */ if (unlikely (anon_vma_prepare (vma))) { -mas_destroy (&mas); +vma_iter_free (&vmi);return -ENOMEM ; }@@ -2049,7 +2048,7 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address)anon_vma_interval_tree_pre_update_vma (vma); vma->vm_end = address;/* Overwrite old entry in mtree. */ -mas_store_prealloc (&mas, vma); +vma_iter_store (&vmi, vma);anon_vma_interval_tree_post_update_vma (vma);spin_unlock (&mm->page_table_lock);
mm/mmap.c static int expand_upwards(struct vm_area_struct *vma, unsigned long address) · line 2063
Quoted 8 lines
mm/mmap.c +1
-1@@ -2058,7 +2057,7 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address) } }anon_vma_unlock_write (vma->anon_vma); -mas_destroy (&mas); +vma_iter_free (&vmi);validate_mm (mm);return error; }
Can you make sure that the expand_upwards() still functions on parisc?
Thanks,
Liam
...