All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/rmap: vm_flags including VM_EXEC can exit timely
@ 2023-10-24 14:49 Zhiguo Jiang
  2023-10-24 15:51 ` David Hildenbrand
  0 siblings, 1 reply; 6+ messages in thread
From: Zhiguo Jiang @ 2023-10-24 14:49 UTC (permalink / raw)
  To: Andrew Morton, linux-mm, linux-kernel; +Cc: opensource.kernel, Zhiguo Jiang

When pra->vm_flags include VM_EXEC flag and folio is file detected in
folio_referenced_one(), the folio referenced traversal process can be
exited timely to reduce the detecting folio referenced time.

Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>
---
 mm/rmap.c | 2 ++
 1 file changed, 2 insertions(+)
 mode change 100644 => 100755 mm/rmap.c

diff --git a/mm/rmap.c b/mm/rmap.c
index 7a27a2b41802..932f3b7e8521
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -884,6 +884,8 @@ static bool folio_referenced_one(struct folio *folio,
 	if (referenced) {
 		pra->referenced++;
 		pra->vm_flags |= vma->vm_flags & ~VM_LOCKED;
+		if ((pra->vm_flags | VM_EXEC) && folio_is_file_lru(folio))
+			return false;
 	}
 
 	if (!pra->mapcount)
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm/rmap: vm_flags including VM_EXEC can exit timely
  2023-10-24 14:49 [PATCH] mm/rmap: vm_flags including VM_EXEC can exit timely Zhiguo Jiang
@ 2023-10-24 15:51 ` David Hildenbrand
  2023-10-25  1:17   ` zhiguojiang
  0 siblings, 1 reply; 6+ messages in thread
From: David Hildenbrand @ 2023-10-24 15:51 UTC (permalink / raw)
  To: Zhiguo Jiang, Andrew Morton, linux-mm, linux-kernel; +Cc: opensource.kernel

On 24.10.23 16:49, Zhiguo Jiang wrote:
> When pra->vm_flags include VM_EXEC flag and folio is file detected in
> folio_referenced_one(), the folio referenced traversal process can be
> exited timely to reduce the detecting folio referenced time.
> 

Can you further elaborate what the logic behind that is?

Why can we stop here if we're dealing with a pagecache folio in an 
executable VMA?

> Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>
> ---
>   mm/rmap.c | 2 ++
>   1 file changed, 2 insertions(+)
>   mode change 100644 => 100755 mm/rmap.c
> 
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 7a27a2b41802..932f3b7e8521
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -884,6 +884,8 @@ static bool folio_referenced_one(struct folio *folio,
>   	if (referenced) {
>   		pra->referenced++;
>   		pra->vm_flags |= vma->vm_flags & ~VM_LOCKED;
> +		if ((pra->vm_flags | VM_EXEC) && folio_is_file_lru(folio))
> +			return false;
>   	}
>   
>   	if (!pra->mapcount)

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm/rmap: vm_flags including VM_EXEC can exit timely
  2023-10-24 15:51 ` David Hildenbrand
@ 2023-10-25  1:17   ` zhiguojiang
  2023-10-25  3:04     ` zhiguojiang
  0 siblings, 1 reply; 6+ messages in thread
From: zhiguojiang @ 2023-10-25  1:17 UTC (permalink / raw)
  To: David Hildenbrand, Andrew Morton, linux-mm, linux-kernel
  Cc: opensource.kernel



在 2023/10/24 23:51, David Hildenbrand 写道:
> On 24.10.23 16:49, Zhiguo Jiang wrote:
>> When pra->vm_flags include VM_EXEC flag and folio is file detected in
>> folio_referenced_one(), the folio referenced traversal process can be
>> exited timely to reduce the detecting folio referenced time.
>>
>
> Can you further elaborate what the logic behind that is?
>
> Why can we stop here if we're dealing with a pagecache folio in an 
> executable VMA?
>
Functions call flow:folio_referenced() --> rmap_walk() --> 
rmap_walk_ksm()/rmap_walk_anon()/rmap_walk_file() --> rwc->rmap_one() 
--> folio_referenced_one(). And folio_referenced() is called by two 
interfaces: folio_check_references() and shrink_active_list().

1. folio_check_references():
When (referenced_ptes > 0 && (vm_flags & VM_EXEC) && 
folio_is_file_lru(folio)) is detected in folio_check_references(), 
FOLIOREF_ACTIVATE will be returned and the folio will be added to the 
active file lru. So when VM_EXEC is detected in folio_referenced_one(), 
we can stop continuing to detect the reference relationship between this 
folio and other vmas, and exit directly to avoid unnecessary traversal.

2. shrink_active_list():
The shrink_active_list() is the same as the folio_check_references().

>> Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>
>> ---
>>   mm/rmap.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>   mode change 100644 => 100755 mm/rmap.c
>>
>> diff --git a/mm/rmap.c b/mm/rmap.c
>> index 7a27a2b41802..932f3b7e8521
>> --- a/mm/rmap.c
>> +++ b/mm/rmap.c
>> @@ -884,6 +884,8 @@ static bool folio_referenced_one(struct folio 
>> *folio,
>>       if (referenced) {
>>           pra->referenced++;
>>           pra->vm_flags |= vma->vm_flags & ~VM_LOCKED;
>> +        if ((pra->vm_flags | VM_EXEC) && folio_is_file_lru(folio))
>> +            return false;
>>       }
>>         if (!pra->mapcount)
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm/rmap: vm_flags including VM_EXEC can exit timely
  2023-10-25  1:17   ` zhiguojiang
@ 2023-10-25  3:04     ` zhiguojiang
  2023-10-25 15:04       ` David Hildenbrand
  0 siblings, 1 reply; 6+ messages in thread
From: zhiguojiang @ 2023-10-25  3:04 UTC (permalink / raw)
  To: David Hildenbrand, Andrew Morton, linux-mm, linux-kernel
  Cc: opensource.kernel



在 2023/10/25 9:17, zhiguojiang 写道:
>
>
> 在 2023/10/24 23:51, David Hildenbrand 写道:
>> On 24.10.23 16:49, Zhiguo Jiang wrote:
>>> When pra->vm_flags include VM_EXEC flag and folio is file detected in
>>> folio_referenced_one(), the folio referenced traversal process can be
>>> exited timely to reduce the detecting folio referenced time.
>>>
>>
>> Can you further elaborate what the logic behind that is?
>>
>> Why can we stop here if we're dealing with a pagecache folio in an 
>> executable VMA?
>>
> Functions call flow:folio_referenced() --> rmap_walk() --> 
> rmap_walk_ksm()/rmap_walk_anon()/rmap_walk_file() --> rwc->rmap_one() 
> --> folio_referenced_one(). And folio_referenced() is called by two 
> interfaces: folio_check_references() and shrink_active_list().
>
> 1. folio_check_references():
> When (referenced_ptes > 0 && (vm_flags & VM_EXEC) && 
> folio_is_file_lru(folio)) is detected in folio_check_references(), 
> FOLIOREF_ACTIVATE will be returned and the folio will be added to the 
> active file lru. So when VM_EXEC is detected in 
> folio_referenced_one(), we can stop continuing to detect the reference 
> relationship between this folio and other vmas, and exit directly to 
> avoid unnecessary traversal.
>
> 2. shrink_active_list():
> The shrink_active_list() is the same as the folio_check_references().
>
>>> Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>
>>> ---
>>>   mm/rmap.c | 2 ++
>>>   1 file changed, 2 insertions(+)
>>>   mode change 100644 => 100755 mm/rmap.c
>>>
>>> diff --git a/mm/rmap.c b/mm/rmap.c
>>> index 7a27a2b41802..932f3b7e8521
>>> --- a/mm/rmap.c
>>> +++ b/mm/rmap.c
>>> @@ -884,6 +884,8 @@ static bool folio_referenced_one(struct folio 
>>> *folio,
>>>       if (referenced) {
>>>           pra->referenced++;
>>>           pra->vm_flags |= vma->vm_flags & ~VM_LOCKED;
>>> +        if ((pra->vm_flags | VM_EXEC) && folio_is_file_lru(folio))
>>> +            return false;
>>>       }
>>>         if (!pra->mapcount)
Sorry, Patch mistake in writing, patch should be:
+        if ((pra->vm_flags & VM_EXEC) && folio_is_file_lru(folio))
+            return false;
>>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm/rmap: vm_flags including VM_EXEC can exit timely
  2023-10-25  3:04     ` zhiguojiang
@ 2023-10-25 15:04       ` David Hildenbrand
  2023-10-26  2:04         ` zhiguojiang
  0 siblings, 1 reply; 6+ messages in thread
From: David Hildenbrand @ 2023-10-25 15:04 UTC (permalink / raw)
  To: zhiguojiang, Andrew Morton, linux-mm, linux-kernel; +Cc: opensource.kernel

On 25.10.23 05:04, zhiguojiang wrote:
> 
> 
> 在 2023/10/25 9:17, zhiguojiang 写道:
>>
>>
>> 在 2023/10/24 23:51, David Hildenbrand 写道:
>>> On 24.10.23 16:49, Zhiguo Jiang wrote:
>>>> When pra->vm_flags include VM_EXEC flag and folio is file detected in
>>>> folio_referenced_one(), the folio referenced traversal process can be
>>>> exited timely to reduce the detecting folio referenced time.
>>>>
>>>
>>> Can you further elaborate what the logic behind that is?
>>>
>>> Why can we stop here if we're dealing with a pagecache folio in an
>>> executable VMA?
>>>
>> Functions call flow:folio_referenced() --> rmap_walk() -->
>> rmap_walk_ksm()/rmap_walk_anon()/rmap_walk_file() --> rwc->rmap_one()
>> --> folio_referenced_one(). And folio_referenced() is called by two
>> interfaces: folio_check_references() and shrink_active_list().
>>
>> 1. folio_check_references():
>> When (referenced_ptes > 0 && (vm_flags & VM_EXEC) &&
>> folio_is_file_lru(folio)) is detected in folio_check_references(),
>> FOLIOREF_ACTIVATE will be returned and the folio will be added to the
>> active file lru. So when VM_EXEC is detected in
>> folio_referenced_one(), we can stop continuing to detect the reference
>> relationship between this folio and other vmas, and exit directly to
>> avoid unnecessary traversal.
>>
>> 2. shrink_active_list():
>> The shrink_active_list() is the same as the folio_check_references().
>>

Thanks, that all belongs into the patch description in some condensed form.

Should that "(vm_flags & VM_EXEC) && folio_is_file_lru(folio)" in all 
three places somehow be factored out in a function with a suitable name, 
so all these cases can be identified easily? Just a thought.

Then, add a comment to the code you're adding. There are plenty of 
comments for the other two cases you mentioned.


folio_referenced() documents:

	"Quick test_and_clear_referenced for all mappings of a folio"

IIUC, you're code will stop doing that, as you break in the middle
of processing some mappings, but not all.

Please describe why that is okay and add it to the patch description and 
update the function description.

>>>> Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>
>>>> ---
>>>>    mm/rmap.c | 2 ++
>>>>    1 file changed, 2 insertions(+)
>>>>    mode change 100644 => 100755 mm/rmap.c
>>>>
>>>> diff --git a/mm/rmap.c b/mm/rmap.c
>>>> index 7a27a2b41802..932f3b7e8521
>>>> --- a/mm/rmap.c
>>>> +++ b/mm/rmap.c
>>>> @@ -884,6 +884,8 @@ static bool folio_referenced_one(struct folio
>>>> *folio,
>>>>        if (referenced) {
>>>>            pra->referenced++;
>>>>            pra->vm_flags |= vma->vm_flags & ~VM_LOCKED;
>>>> +        if ((pra->vm_flags | VM_EXEC) && folio_is_file_lru(folio))
>>>> +            return false;
>>>>        }
>>>>          if (!pra->mapcount)
> Sorry, Patch mistake in writing, patch should be:
> +        if ((pra->vm_flags & VM_EXEC) && folio_is_file_lru(folio))
> +            return false;

So this was not even properly tested? :/

Of course I have to ask: what's the net (performance) benefit of this 
change?

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm/rmap: vm_flags including VM_EXEC can exit timely
  2023-10-25 15:04       ` David Hildenbrand
@ 2023-10-26  2:04         ` zhiguojiang
  0 siblings, 0 replies; 6+ messages in thread
From: zhiguojiang @ 2023-10-26  2:04 UTC (permalink / raw)
  To: David Hildenbrand, Andrew Morton, linux-mm, linux-kernel
  Cc: opensource.kernel



在 2023/10/25 23:04, David Hildenbrand 写道:
> On 25.10.23 05:04, zhiguojiang wrote:
>>
>>
>> 在 2023/10/25 9:17, zhiguojiang 写道:
>>>
>>>
>>> 在 2023/10/24 23:51, David Hildenbrand 写道:
>>>> On 24.10.23 16:49, Zhiguo Jiang wrote:
>>>>> When pra->vm_flags include VM_EXEC flag and folio is file detected in
>>>>> folio_referenced_one(), the folio referenced traversal process can be
>>>>> exited timely to reduce the detecting folio referenced time.
>>>>>
>>>>
>>>> Can you further elaborate what the logic behind that is?
>>>>
>>>> Why can we stop here if we're dealing with a pagecache folio in an
>>>> executable VMA?
>>>>
>>> Functions call flow:folio_referenced() --> rmap_walk() -->
>>> rmap_walk_ksm()/rmap_walk_anon()/rmap_walk_file() --> rwc->rmap_one()
>>> --> folio_referenced_one(). And folio_referenced() is called by two
>>> interfaces: folio_check_references() and shrink_active_list().
>>>
>>> 1. folio_check_references():
>>> When (referenced_ptes > 0 && (vm_flags & VM_EXEC) &&
>>> folio_is_file_lru(folio)) is detected in folio_check_references(),
>>> FOLIOREF_ACTIVATE will be returned and the folio will be added to the
>>> active file lru. So when VM_EXEC is detected in
>>> folio_referenced_one(), we can stop continuing to detect the reference
>>> relationship between this folio and other vmas, and exit directly to
>>> avoid unnecessary traversal.
>>>
>>> 2. shrink_active_list():
>>> The shrink_active_list() is the same as the folio_check_references().
>>>
>
> Thanks, that all belongs into the patch description in some condensed 
> form.
>
> Should that "(vm_flags & VM_EXEC) && folio_is_file_lru(folio)" in all 
> three places somehow be factored out in a function with a suitable 
> name, so all these cases can be identified easily? Just a thought.
>
> Then, add a comment to the code you're adding. There are plenty of 
> comments for the other two cases you mentioned.
>
>
> folio_referenced() documents:
>
>     "Quick test_and_clear_referenced for all mappings of a folio"
>
> IIUC, you're code will stop doing that, as you break in the middle
> of processing some mappings, but not all.
>
Thank you for review, this patch will indeed interrupt 
test_and_clear_referenced for all mappings of a folio. This patch can be 
ignore.
> Please describe why that is okay and add it to the patch description 
> and update the function description.
>
>>>>> Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>
>>>>> ---
>>>>>    mm/rmap.c | 2 ++
>>>>>    1 file changed, 2 insertions(+)
>>>>>    mode change 100644 => 100755 mm/rmap.c
>>>>>
>>>>> diff --git a/mm/rmap.c b/mm/rmap.c
>>>>> index 7a27a2b41802..932f3b7e8521
>>>>> --- a/mm/rmap.c
>>>>> +++ b/mm/rmap.c
>>>>> @@ -884,6 +884,8 @@ static bool folio_referenced_one(struct folio
>>>>> *folio,
>>>>>        if (referenced) {
>>>>>            pra->referenced++;
>>>>>            pra->vm_flags |= vma->vm_flags & ~VM_LOCKED;
>>>>> +        if ((pra->vm_flags | VM_EXEC) && folio_is_file_lru(folio))
>>>>> +            return false;
>>>>>        }
>>>>>          if (!pra->mapcount)
>> Sorry, Patch mistake in writing, patch should be:
>> +        if ((pra->vm_flags & VM_EXEC) && folio_is_file_lru(folio))
>> +            return false;
>
> So this was not even properly tested? :/
>
> Of course I have to ask: what's the net (performance) benefit of this 
> change?
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-26  2:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 14:49 [PATCH] mm/rmap: vm_flags including VM_EXEC can exit timely Zhiguo Jiang
2023-10-24 15:51 ` David Hildenbrand
2023-10-25  1:17   ` zhiguojiang
2023-10-25  3:04     ` zhiguojiang
2023-10-25 15:04       ` David Hildenbrand
2023-10-26  2:04         ` zhiguojiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.