mm/mmap.c: prev could be retrieved from vma->vm_prev
Subsystems (3)
PATCH v2 1/3 mm/mmap.c: prev could be retrieved from vma->vm_prev
Currently __vma_unlink_common handles two cases:
* has_prev
* or not
When has_prev is false, it is obvious prev is calculated from vma->vm_prev in __vma_unlink_common.
When has_prev is true, the prev is passed through from __vma_unlink_prev in __vma_adjust for non-case 8. And at the beginning next is calculated from vma->vm_next, which implies vma is next->vm_prev.
The above statement sounds a little complicated, while to think in another point of view, no matter whether vma and next is swapped, the mmap link list still preserves its property. It is proper to access vma->vm_prev.
---
v2: rebase on top of 5.4-rc1
--- mm/mmap.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
mm/mmap.c +7 -13
@@ -684,23 +684,17 @@ static void __insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma) static __always_inline void __vma_unlink_common(struct mm_struct *mm,struct vm_area_struct *vma, -struct vm_area_struct *prev, -bool has_prev,struct vm_area_struct *ignore) { -struct vm_area_struct *next; +struct vm_area_struct *prev, *next;vma_rb_erase_ignore (vma, &mm->mm_rb, ignore); next = vma->vm_next; -if (has_prev) + prev = vma->vm_prev; +if (prev) prev->vm_next = next; -else { - prev = vma->vm_prev; -if (prev) - prev->vm_next = next; -else - mm->mmap = next; - } +else + mm->mmap = next;if (next) next->vm_prev = prev;
@@ -712,7 +706,7 @@ static inline void __vma_unlink_prev(struct mm_struct *mm,struct vm_area_struct *vma, struct vm_area_struct *prev) { -__vma_unlink_common (mm ,vma ,prev ,true ,vma ); +__vma_unlink_common (mm ,vma ,vma ); }/*
@@ -900,7 +894,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,* "next" (which is stored in post-swap() * "vma"). */ -__vma_unlink_common (mm, next,NULL , false, vma); +__vma_unlink_common (mm, next, vma);if (file)__remove_shared_vm_struct (next, file, mapping); }else if (insert) {
Signature · 1 line
2.17.1
PATCH v2 2/3 mm/mmap.c: __vma_unlink_prev is not necessary now
The third parameter of __vma_unlink_common could differentiate these two types. __vma_unlink_prev is not necessary now.
---
v2: rebase on top of 5.4-rc1
--- mm/mmap.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
mm/mmap.c +1 -8
@@ -702,13 +702,6 @@ static __always_inline void __vma_unlink_common(struct mm_struct *mm,vmacache_invalidate (mm); } -static inline void __vma_unlink_prev (struct mm_struct *mm, -struct vm_area_struct *vma, -struct vm_area_struct *prev) -{ -__vma_unlink_common (mm, vma, vma); -} -/* * We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that * is already present in an i_mmap tree without adjusting the tree.
@@ -883,7 +876,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,* us to remove next before dropping the locks. */ if (remove_next !=3 ) -__vma_unlink_prev (mm, next, vma); +__vma_unlink_common (mm, next, next);else /* * vma is not before next if they've been
Signature · 1 line
2.17.1
PATCH v2 3/3 mm/mmap.c: extract __vma_unlink_list as counter part for __vma_link_list
In reply to Wei YangJust make the code a little easy to read.
---
Note: For nommu part, the code is not tested.
---
v2: rebase on top of 5.4-rc1
--- mm/internal.h | 1 + mm/mmap.c | 12 +----------- mm/nommu.c | 8 +------- mm/util.c | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 18 deletions(-)
mm/internal.h +1 -0
@@ -291,6 +291,7 @@ static inline bool is_data_mapping(vm_flags_t flags)/* mm/util.c */ void __vma_link_list (struct mm_struct *mm,struct vm_area_struct *vma,struct vm_area_struct *prev); +void __vma_unlink_list (struct mm_struct *mm,struct vm_area_struct *vma);#ifdef CONFIG_MMU extern long populate_vma_page_range(struct vm_area_struct *vma,
mm/mmap.c +1 -11
@@ -686,18 +686,8 @@ static __always_inline void __vma_unlink_common(struct mm_struct *mm,struct vm_area_struct *vma, struct vm_area_struct *ignore) { - struct vm_area_struct *prev, *next; - vma_rb_erase_ignore(vma, &mm->mm_rb, ignore); - next = vma->vm_next; - prev = vma->vm_prev; -if (prev) - prev->vm_next = next; -else - mm->mmap = next; -if (next) - next->vm_prev = prev; - +__vma_unlink_list (mm, vma);/* Kill the cache */ vmacache_invalidate (mm); }
mm/nommu.c +1 -7
@@ -673,13 +673,7 @@ static void delete_vma_from_mm(struct vm_area_struct *vma)/* remove from the MM's tree and list */ rb_erase (&vma->vm_rb, &mm->mm_rb); -if (vma->vm_prev) - vma->vm_prev->vm_next = vma->vm_next; -else - mm->mmap = vma->vm_next; - -if (vma->vm_next) - vma->vm_next->vm_prev = vma->vm_prev; +__vma_unlink_list (mm, vma); }/*
mm/util.c +14 -0
@@ -288,6 +288,20 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma, next->vm_prev = vma; } +void __vma_unlink_list (struct mm_struct *mm,struct vm_area_struct *vma) +{ +struct vm_area_struct *prev, *next; + + next = vma->vm_next; + prev = vma->vm_prev; +if (prev) + prev->vm_next = next; +else + mm->mmap = next; +if (next) + next->vm_prev = prev; +} +/* Check if the vma is being used as a stack by this task */ int vma_is_stack_for_current (struct vm_area_struct *vma) {
Signature · 1 line
2.17.1