Skip to contentSkip to conversation

mm/mlock: remove unneeded start >= vma->vm_end check

PATCH In review Miaohe Lin 2 participants 5 messages Mar 14, 2022 – Apr 6, 2022

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 mm/mlock: remove unneeded start >= vma->vm_end check

If find_vma returns a vma, it must satisfies that start < vma->vm_end. Since vma list is sorted in the ascending order, so we will never see start >= vma->vm_end here. Remove this unneeded check.

---
 mm/mlock.c | 2 --
 1 file changed, 2 deletions(-)
mm/mlock.c +0 -2
index fefa9644d0f9..fe278634ebe3 100644
@@ -509,8 +509,6 @@ static unsigned long count_mm_mlocked_page_nr(struct mm_struct *mm,
 		return 0;
 
 	for (; vma ; vma = vma->vm_next) {
-		if (start >= vma->vm_end)
-			continue;
 		if (start + len <=  vma->vm_start)
 			break;
 		if (vma->vm_flags & VM_LOCKED) {
Signature · 1 line
2.23.0
#1 lore raw
Quoted 3 lines · Miaohe Lin

If find_vma returns a vma, it must satisfies that start < vma->vm_end. Since vma list is sorted in the ascending order, so we will never see start >= vma->vm_end here. Remove this unneeded check.

faulty logic; vm_start + len might wrap.

author
#2 lore raw
Quoted 6 lines · Matthew Wilcox
Quoted 3 lines · Miaohe Lin

If find_vma returns a vma, it must satisfies that start < vma->vm_end. Since vma list is sorted in the ascending order, so we will never see start >= vma->vm_end here. Remove this unneeded check.

faulty logic; vm_start + len might wrap.

Many thanks for comment. I agree with you about "vm_start + len" might wrap. But what I mean here is that we will never see "start" >= vma->vm_end here as find_vma guarantees this. And I leave the "start + len <= vma->vm_start" check untouched. So my cleanup should be right. Or am I miss something?

Thanks.

Quoted 3 lines

.

author
#3 lore raw
Quoted 6 lines · Miaohe Lin
Quoted 5 lines · Matthew Wilcox
Quoted 3 lines · Miaohe Lin

If find_vma returns a vma, it must satisfies that start < vma->vm_end. Since vma list is sorted in the ascending order, so we will never see start >= vma->vm_end here. Remove this unneeded check.

Quoted 7 lines
Quoted 1 line

faulty logic; vm_start + len might wrap.

Many thanks for comment. I agree with you about "vm_start + len" might wrap. But what I mean here is that we will never see "start" >= vma->vm_end here as find_vma guarantees this. And I leave the "start + len <= vma->vm_start" check untouched. So my cleanup should be right. Or am I miss something?

friendly ping. :)

Quoted 6 lines

Thanks.

Quoted 3 lines

.

author
#4 lore raw
In reply to Miaohe Lin
Quoted 7 lines · Miaohe Lin
Quoted 6 lines · Matthew Wilcox
Quoted 3 lines · Miaohe Lin

If find_vma returns a vma, it must satisfies that start < vma->vm_end. Since vma list is sorted in the ascending order, so we will never see start >= vma->vm_end here. Remove this unneeded check.

faulty logic; vm_start + len might wrap.

What do you mean is vm_start + len might wrap, so vm_end might be < vm_start ? If so, this could not happen as get_unmapped_area guarantees this.

Quoted 5 lines

Many thanks for comment. I agree with you about "vm_start + len" might wrap. But what I mean here is that we will never see "start" >= vma->vm_end here as find_vma guarantees this. And I leave the "start + len <= vma->vm_start" check untouched. So my cleanup should be right. Or am I miss something?

So I think this "start >= vma->vm_end" check is unneeded and we can remove it. Or am I miss something?

Many thanks!

Quoted 7 lines

Thanks.

Quoted 3 lines

.