Skip to contentSkip to conversation

mm/mmap: convert all mas except mas_detach to vma iterator

PATCH RESEND Applied Yajun Deng 4 participants 4 messages Mar 25, 2024

Subsystems (3)
lore
Share & tools
lore

Yajun Deng

author
#0 lore raw

PATCH RESEND 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 structure, 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 structure.

Remove as many uses of mas as possible, 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 the 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
index 6c8d3844b6a3..5dbfa1c12e89 100644
@@ -1254,6 +1254,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
maintainer
#1 lore raw
Quoted 7 lines · On Mon, 25 Mar 2024 14:32:58 +0800 Yajun Deng <[email protected]> wrote:

There are two types of iterators mas and vmi in the current code. If the maple tree comes from the mm structure, 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 structure.

Quoted 7 lines

Remove as many uses of mas as possible, 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 the vma interator.

I assume Liam's earlier request still applies?

: Helge,
:
: Yajun has changed code that affects parisc with this patch, which hasn't : been tested.
:
: ...
:
: Can you make sure that the expand_upwards() still functions on parisc?

Tested-by
#2 lore raw
Quoted 17 lines · Andrew Morton
Quoted 7 lines · On Mon, 25 Mar 2024 14:32:58 +0800 Yajun Deng <[email protected]> wrote:

There are two types of iterators mas and vmi in the current code. If the maple tree comes from the mm structure, 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 structure.

Quoted 7 lines

Remove as many uses of mas as possible, 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 the vma interator.

Quoted 8 lines

I assume Liam's earlier request still applies?

: Helge,
:
: Yajun has changed code that affects parisc with this patch, which hasn't : been tested.
: ...
: Can you make sure that the expand_upwards() still functions on parisc?

Oh, I didn't noticed that request earlier.
Anyway, I now tested this patch on top of 6.9-rc1, and the kernel still boots up nicely on parisc and as such expand_upwards() seem to work as before. So, you may add:

Thanks!
Helge

Reviewed-by
#3 lore raw
Quoted 27 lines · Helge Deller
Quoted 17 lines · Andrew Morton
Quoted 7 lines · On Mon, 25 Mar 2024 14:32:58 +0800 Yajun Deng <[email protected]> wrote:

There are two types of iterators mas and vmi in the current code. If the maple tree comes from the mm structure, 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 structure.

Quoted 7 lines

Remove as many uses of mas as possible, 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 the vma interator.

Quoted 8 lines

I assume Liam's earlier request still applies?

: Helge,
:
: Yajun has changed code that affects parisc with this patch, which hasn't : been tested.
: ...
: Can you make sure that the expand_upwards() still functions on parisc?

Quoted 6 lines

Oh, I didn't noticed that request earlier.
Anyway, I now tested this patch on top of 6.9-rc1, and the kernel still boots up nicely on parisc and as such expand_upwards() seem to work as before. So, you may add:

Thanks Helge!