Skip to contentSkip to conversation

mm/vma: next is already retrieved

PATCH In review Wei Yang 2 participants 8 messages Nov 27, 2024 – Jan 23, 2025

Subsystems (2)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm/vma: next is already retrieved

vma_iter_next_rewind() here gets next vma and rewind iterator.

Actually the next vma is already been retrieved to new_vma. Since the iterator is initialized to addr, we don't need to adjust it.

CC Liam R. Howlett <[email protected]>
CC Lorenzo Stoakes <[email protected]>
CC Vlastimil Babka <[email protected]>
CC Jann Horn <[email protected]>
---
 mm/vma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vma.c +1 -1
index 8a454a7bbc80..d419e3700fa7 100644
@@ -1727,7 +1727,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
 
 	vmg.vma = NULL; /* New VMA range. */
 	vmg.pgoff = pgoff;
-	vmg.next = vma_iter_next_rewind(&vmi, NULL);
+	vmg.next = new_vma;
 	new_vma = vma_merge_new_range(&vmg);
 
 	if (new_vma) {
Signature · 1 line
2.34.1
#1 lore raw

Hi Wei,

Thanks for the patch, though I would again ask if you could please stop fiddling around with the VMA stuff until things are a _little_ more settled, perhaps best to leave until the new year?

I'm talking about small refactorings and optimisations here - for bugs or major issues - please do, of course, submit immediately.

Quoted 19 lines · Wei Yang

vma_iter_next_rewind() here gets next vma and rewind iterator.

Actually the next vma is already been retrieved to new_vma. Since the iterator is initialized to addr, we don't need to adjust it.

CC Liam R. Howlett <[email protected]>
CC Lorenzo Stoakes <[email protected]>
CC Vlastimil Babka <[email protected]>
CC Jann Horn <[email protected]>
---
 mm/vma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vma.c +0 -0
index 8a454a7bbc80..d419e3700fa7 100644

mm/vma.c struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, · line 1730

Quoted 5 lines
mm/vma.c +1 -1
@@ -1727,7 +1727,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
 
 	vmg.vma = NULL; /* New VMA range. */
 	vmg.pgoff = pgoff;
-	vmg.next = vma_iter_next_rewind(&vmi, NULL);
+	vmg.next = new_vma;

HOWEVER, this is a good spot and you're right (I mean we explicitly _check_ that the found VMA is after the point at which we intend to insert the new one).

But while we're here, can we fix this HORRIBLE variable naming? We reuse 'new_vma' to refer to the _next_ VMA and newly merged one/one we have to create.

So could you update your code to do something like:

	vmg.next = find_vma_prev(mm, addr, &vmg.prev);
	if (vmg.next && ...

This self-documents your fix, avoids the need for the vma_iter_next_rewind(), fixes the inefficiency you've found, and avoids stupidly overloading what new_vma refers to.

Also update the commit message to refer to this.

And can you update the test_copy_vma() test in tools/testing/vma/vma.c to explicitly test for VMAs that come afterwards both merge and non-merge cases?

It's time to really start taking advantage of this huge power we have to userland test things! :)

Quoted 7 lines
mm/vma.c +0 -1
 	new_vma = vma_merge_new_range(&vmg);
 
 	if (new_vma) {
--

2.34.1

Thanks, Lorenzo

author
#2 lore raw
Quoted 6 lines · Lorenzo Stoakes

Hi Wei,

Thanks for the patch, though I would again ask if you could please stop fiddling around with the VMA stuff until things are a _little_ more settled, perhaps best to leave until the new year?

Sure.

Quoted 33 lines

I'm talking about small refactorings and optimisations here - for bugs or major issues - please do, of course, submit immediately.

Quoted 19 lines · Wei Yang

vma_iter_next_rewind() here gets next vma and rewind iterator.

Actually the next vma is already been retrieved to new_vma. Since the iterator is initialized to addr, we don't need to adjust it.

CC Liam R. Howlett <[email protected]>
CC Lorenzo Stoakes <[email protected]>
CC Vlastimil Babka <[email protected]>
CC Jann Horn <[email protected]>
---
 mm/vma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vma.c +0 -0
index 8a454a7bbc80..d419e3700fa7 100644

mm/vma.c struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, · line 1730

Quoted 5 lines
mm/vma.c +1 -1
@@ -1727,7 +1727,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
 
 	vmg.vma = NULL; /* New VMA range. */
 	vmg.pgoff = pgoff;
-	vmg.next = vma_iter_next_rewind(&vmi, NULL);
+	vmg.next = new_vma;

HOWEVER, this is a good spot and you're right (I mean we explicitly _check_ that the found VMA is after the point at which we intend to insert the new one).

Quoted 9 lines

But while we're here, can we fix this HORRIBLE variable naming? We reuse 'new_vma' to refer to the _next_ VMA and newly merged one/one we have to create.

So could you update your code to do something like:

	vmg.next = find_vma_prev(mm, addr, &vmg.prev);
	if (vmg.next && ...

Sure. I thought you may prefer a small footprint, so I did current version.

Will update it in next version next year.

Quoted 10 lines

This self-documents your fix, avoids the need for the vma_iter_next_rewind(), fixes the inefficiency you've found, and avoids stupidly overloading what new_vma refers to.

Also update the commit message to refer to this.

And can you update the test_copy_vma() test in tools/testing/vma/vma.c to explicitly test for VMAs that come afterwards both merge and non-merge cases?

Currently we have two scenario with merge/non-merge after copy_vma().

I am not sure what exact case you want to have. Would you mind giving more detail?

Quoted 12 lines

It's time to really start taking advantage of this huge power we have to userland test things! :)

Quoted 7 lines
mm/vma.c +0 -1
 	new_vma = vma_merge_new_range(&vmg);
 
 	if (new_vma) {
--

2.34.1

Thanks, Lorenzo

Signature · 2 lines
Wei Yang
Help you, Help me
#3 lore raw
Quoted 9 lines · Wei Yang
Quoted 6 lines · Lorenzo Stoakes

Hi Wei,

Thanks for the patch, though I would again ask if you could please stop fiddling around with the VMA stuff until things are a _little_ more settled, perhaps best to leave until the new year?

Sure.

Thanks.

Quoted 3 lines
Quoted 3 lines

I'm talking about small refactorings and optimisations here - for bugs or major issues - please do, of course, submit immediately.

Though if you find any bugs or serious problems, please do report them right away!

Quoted 37 lines
Quoted 37 lines · Wei Yang
Quoted 19 lines

vma_iter_next_rewind() here gets next vma and rewind iterator.

Actually the next vma is already been retrieved to new_vma. Since the iterator is initialized to addr, we don't need to adjust it.

CC Liam R. Howlett <[email protected]>
CC Lorenzo Stoakes <[email protected]>
CC Vlastimil Babka <[email protected]>
CC Jann Horn <[email protected]>
---
 mm/vma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vma.c +0 -0
index 8a454a7bbc80..d419e3700fa7 100644

mm/vma.c struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, · line 1730

Quoted 5 lines
mm/vma.c +1 -1
@@ -1727,7 +1727,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
 
 	vmg.vma = NULL; /* New VMA range. */
 	vmg.pgoff = pgoff;
-	vmg.next = vma_iter_next_rewind(&vmi, NULL);
+	vmg.next = new_vma;

HOWEVER, this is a good spot and you're right (I mean we explicitly _check_ that the found VMA is after the point at which we intend to insert the new one).

But while we're here, can we fix this HORRIBLE variable naming? We reuse 'new_vma' to refer to the _next_ VMA and newly merged one/one we have to create.

So could you update your code to do something like:

Quoted 7 lines
Quoted 3 lines
	vmg.next = find_vma_prev(mm, addr, &vmg.prev);
	if (vmg.next && ...

Sure. I thought you may prefer a small footprint, so I did current version.

Will update it in next version next year.

Thanks!

Quoted 12 lines
Quoted 11 lines

This self-documents your fix, avoids the need for the vma_iter_next_rewind(), fixes the inefficiency you've found, and avoids stupidly overloading what new_vma refers to.

Also update the commit message to refer to this.

And can you update the test_copy_vma() test in tools/testing/vma/vma.c to explicitly test for VMAs that come afterwards both merge and non-merge cases?

Quoted 4 lines

Currently we have two scenario with merge/non-merge after copy_vma().

I am not sure what exact case you want to have. Would you mind giving more detail?

Both please, I don't believe this is curently tested.

It may also be worth testing the 'should never get here' error case.

Quoted 18 lines
Quoted 6 lines

It's time to really start taking advantage of this huge power we have to userland test things! :)

Quoted 2 lines
mm/vma.c +0 -0
 	new_vma = vma_merge_new_range(&vmg);
 
Quoted 7 lines
Quoted 5 lines
mm/vma.c +0 -1
 	if (new_vma) {
--

2.34.1

Thanks, Lorenzo

--
Wei Yang
Help you, Help me

author
#4 lore raw
Quoted 4 lines · Lorenzo Stoakes
Quoted 3 lines · Wei Yang
Quoted 2 lines · Lorenzo Stoakes

Hi Wei,

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Thanks for the patch, though I would again ask if you could please stop fiddling around with the VMA stuff until things are a _little_ more settled, perhaps best to leave until the new year?

Sure.

Thanks.

Hi, Lorenzo

Is it proper to resend it now?

Signature · 2 lines
Wei Yang
Help you, Help me
#5 lore raw
Quoted 10 lines · Wei Yang
Quoted 9 lines · Lorenzo Stoakes
Quoted 8 lines · Wei Yang
Quoted 6 lines · Lorenzo Stoakes

Hi Wei,

Thanks for the patch, though I would again ask if you could please stop fiddling around with the VMA stuff until things are a _little_ more settled, perhaps best to leave until the new year?

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Sure.

Thanks.

Hi, Lorenzo

Is it proper to resend it now?

Hi Wei,

Would you mind waiting a little longer? Sorry to be a pain but I have a refactoring that I'm going to push through shortly! Otherwise we will clash :)

Cheers, Lorenzo

Quoted 5 lines

--
Wei Yang
Help you, Help me

author
#6 lore raw
Quoted 18 lines · Lorenzo Stoakes
Quoted 17 lines · Wei Yang
Quoted 4 lines · Lorenzo Stoakes
Quoted 3 lines · Wei Yang
Quoted 2 lines · Lorenzo Stoakes

Hi Wei,

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Thanks for the patch, though I would again ask if you could please stop fiddling around with the VMA stuff until things are a _little_ more settled, perhaps best to leave until the new year?

Sure.

Thanks.

Hi, Lorenzo

Quoted 7 lines
Quoted 1 line

Is it proper to resend it now?

Hi Wei,

Would you mind waiting a little longer? Sorry to be a pain but I have a refactoring that I'm going to push through shortly! Otherwise we will clash :)

No problem. Would you mind letting me know when it is ready?

Quoted 8 lines

Cheers, Lorenzo

Quoted 5 lines

--
Wei Yang
Help you, Help me

Signature · 2 lines
Wei Yang
Help you, Help me
#7 lore raw
Quoted 21 lines · Wei Yang
Quoted 20 lines · Lorenzo Stoakes
Quoted 18 lines · Wei Yang
Quoted 4 lines · Lorenzo Stoakes
Quoted 3 lines · Wei Yang
Quoted 2 lines · Lorenzo Stoakes

Hi Wei,

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Thanks for the patch, though I would again ask if you could please stop fiddling around with the VMA stuff until things are a _little_ more settled, perhaps best to leave until the new year?

Sure.

Thanks.

Hi, Lorenzo

Is it proper to resend it now?

Quoted 7 lines
Quoted 5 lines

Hi Wei,

Would you mind waiting a little longer? Sorry to be a pain but I have a refactoring that I'm going to push through shortly! Otherwise we will clash :)

No problem. Would you mind letting me know when it is ready?

Sure will do, once it's taken to unstable then we should be good to revisit. Sorry to be a pain and thank you very much for your understanding!

I am working on this now so shouldn't be long.

Cheers, Lorenzo

Quoted 14 lines
Quoted 9 lines

Cheers, Lorenzo

Quoted 5 lines

--
Wei Yang
Help you, Help me

--
Wei Yang
Help you, Help me