All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: remove redundant check in handle_mm_fault
@ 2023-03-06  2:49 Haifeng Xu
  2023-03-06 13:49 ` David Hildenbrand
  0 siblings, 1 reply; 12+ messages in thread
From: Haifeng Xu @ 2023-03-06  2:49 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Haifeng Xu

mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
set or not, so remove the check in handle_mm_fault().

Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memory.c b/mm/memory.c
index f456f3b5049c..e066d974c27b 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5206,7 +5206,7 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address,
 		 * VM_FAULT_OOM), there is no need to kill anything.
 		 * Just clean up the OOM state peacefully.
 		 */
-		if (task_in_memcg_oom(current) && !(ret & VM_FAULT_OOM))
+		if (!(ret & VM_FAULT_OOM))
 			mem_cgroup_oom_synchronize(false);
 	}
 
-- 
2.25.1


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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-06  2:49 [PATCH] mm: remove redundant check in handle_mm_fault Haifeng Xu
@ 2023-03-06 13:49 ` David Hildenbrand
  2023-03-07  2:36   ` Haifeng Xu
  0 siblings, 1 reply; 12+ messages in thread
From: David Hildenbrand @ 2023-03-06 13:49 UTC (permalink / raw)
  To: Haifeng Xu, akpm; +Cc: linux-mm, linux-kernel

On 06.03.23 03:49, Haifeng Xu wrote:
> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
> set or not, so remove the check in handle_mm_fault().

"mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom 
is not set, so remove the check from handle_mm_fault()".

However, that requires now always an indirect function call -- do we 
care about dropping that optimization?


-- 
Thanks,

David / dhildenb


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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-06 13:49 ` David Hildenbrand
@ 2023-03-07  2:36   ` Haifeng Xu
  2023-03-07  2:48     ` Matthew Wilcox
  0 siblings, 1 reply; 12+ messages in thread
From: Haifeng Xu @ 2023-03-07  2:36 UTC (permalink / raw)
  To: David Hildenbrand, akpm; +Cc: linux-mm, linux-kernel



On 2023/3/6 21:49, David Hildenbrand wrote:
> On 06.03.23 03:49, Haifeng Xu wrote:
>> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
>> set or not, so remove the check in handle_mm_fault().
> 
> "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
> 
> However, that requires now always an indirect function call -- do we care about dropping that optimization?
> 
> 

If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.

if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible 
compare to the whole mm user falut preocess. And that won't cause stack overflow error.

Thanks.

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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-07  2:36   ` Haifeng Xu
@ 2023-03-07  2:48     ` Matthew Wilcox
  2023-03-07  3:20       ` Haifeng Xu
  2023-03-08  9:03       ` Haifeng Xu
  0 siblings, 2 replies; 12+ messages in thread
From: Matthew Wilcox @ 2023-03-07  2:48 UTC (permalink / raw)
  To: Haifeng Xu; +Cc: David Hildenbrand, akpm, linux-mm, linux-kernel

On Tue, Mar 07, 2023 at 10:36:55AM +0800, Haifeng Xu wrote:
> On 2023/3/6 21:49, David Hildenbrand wrote:
> > On 06.03.23 03:49, Haifeng Xu wrote:
> >> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
> >> set or not, so remove the check in handle_mm_fault().
> > 
> > "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
> > 
> > However, that requires now always an indirect function call -- do we care about dropping that optimization?
> > 
> > 
> 
> If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.
> 
> if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible 
> compare to the whole mm user falut preocess. And that won't cause stack overflow error.

I suggest you measure it.

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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-07  2:48     ` Matthew Wilcox
@ 2023-03-07  3:20       ` Haifeng Xu
  2023-03-08  9:03       ` Haifeng Xu
  1 sibling, 0 replies; 12+ messages in thread
From: Haifeng Xu @ 2023-03-07  3:20 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: David Hildenbrand, akpm, linux-mm, linux-kernel



On 2023/3/7 10:48, Matthew Wilcox wrote:
> On Tue, Mar 07, 2023 at 10:36:55AM +0800, Haifeng Xu wrote:
>> On 2023/3/6 21:49, David Hildenbrand wrote:
>>> On 06.03.23 03:49, Haifeng Xu wrote:
>>>> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
>>>> set or not, so remove the check in handle_mm_fault().
>>>
>>> "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
>>>
>>> However, that requires now always an indirect function call -- do we care about dropping that optimization?
>>>
>>>
>>
>> If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.
>>
>> if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible 
>> compare to the whole mm user falut preocess. And that won't cause stack overflow error.
> 
> I suggest you measure it.

Ok, I'll make a simple test.

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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-07  2:48     ` Matthew Wilcox
  2023-03-07  3:20       ` Haifeng Xu
@ 2023-03-08  9:03       ` Haifeng Xu
  2023-03-08  9:13         ` David Hildenbrand
  1 sibling, 1 reply; 12+ messages in thread
From: Haifeng Xu @ 2023-03-08  9:03 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: David Hildenbrand, akpm, linux-mm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1359 bytes --]



On 2023/3/7 10:48, Matthew Wilcox wrote:
> On Tue, Mar 07, 2023 at 10:36:55AM +0800, Haifeng Xu wrote:
>> On 2023/3/6 21:49, David Hildenbrand wrote:
>>> On 06.03.23 03:49, Haifeng Xu wrote:
>>>> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
>>>> set or not, so remove the check in handle_mm_fault().
>>>
>>> "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
>>>
>>> However, that requires now always an indirect function call -- do we care about dropping that optimization?
>>>
>>>
>>
>> If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.
>>
>> if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible 
>> compare to the whole mm user falut preocess. And that won't cause stack overflow error.
> 
> I suggest you measure it.

test steps:
1) Run command: ./mmap_anon_test(global alloc, so the memcg_in_oom is not set)
2) Calculate the quotient of cost time and page-fault counts, run 10 rounds and average the results.

The test result shows that whether using indirect function call or not, the time spent in user fault
is almost the same, about 2.3ms.

[-- Attachment #2: mmap_anon_test.c --]
[-- Type: text/plain, Size: 946 bytes --]

#include <sys/mman.h>
#include <sys/types.h>
#include <sys/time.h>
#include <inttypes.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>

#define SIZE (1 * 1024 * 1024 * 1024)
#define PAGE_SIZE 4096

int64_t current_time_ms() {
	struct timeval time;
	gettimeofday(&time, NULL);
	int64_t s1 = (int64_t)(time.tv_sec) * 1000;
	int64_t s2 = (time.tv_usec / 1000);
	return s1 + s2;
}

int main(int argc, char* argv[])
{
	void * buf;
	char * ptr;
	size_t size = SIZE, step = PAGE_SIZE;
	int64_t start, cost;

	buf = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	if (buf ==  MAP_FAILED) {
		printf("mmap failed\n");
	}

	start = current_time_ms();

	for(size_t i = 0; i < size; i += step ) {
		ptr = (char *)(buf + i);
		*ptr = 'a';
	}

	cost = current_time_ms() - start;
	printf("cost:%" PRId64 " ms\n", cost);

	munmap(buf, size);

        return 0;
}

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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-08  9:03       ` Haifeng Xu
@ 2023-03-08  9:13         ` David Hildenbrand
  2023-03-09  2:33           ` Haifeng Xu
  2023-03-14  8:05           ` Haifeng Xu
  0 siblings, 2 replies; 12+ messages in thread
From: David Hildenbrand @ 2023-03-08  9:13 UTC (permalink / raw)
  To: Haifeng Xu, Matthew Wilcox; +Cc: akpm, linux-mm, linux-kernel

On 08.03.23 10:03, Haifeng Xu wrote:
> 
> 
> On 2023/3/7 10:48, Matthew Wilcox wrote:
>> On Tue, Mar 07, 2023 at 10:36:55AM +0800, Haifeng Xu wrote:
>>> On 2023/3/6 21:49, David Hildenbrand wrote:
>>>> On 06.03.23 03:49, Haifeng Xu wrote:
>>>>> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
>>>>> set or not, so remove the check in handle_mm_fault().
>>>>
>>>> "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
>>>>
>>>> However, that requires now always an indirect function call -- do we care about dropping that optimization?
>>>>
>>>>
>>>
>>> If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.
>>>
>>> if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible
>>> compare to the whole mm user falut preocess. And that won't cause stack overflow error.
>>
>> I suggest you measure it.
> 
> test steps:
> 1) Run command: ./mmap_anon_test(global alloc, so the memcg_in_oom is not set)
> 2) Calculate the quotient of cost time and page-fault counts, run 10 rounds and average the results.
> 
> The test result shows that whether using indirect function call or not, the time spent in user fault
> is almost the same, about 2.3ms.

I guess most of the benchmark time is consumed by allocating fresh pages 
in your test (also, why exactly do you use MAP_SHARED?).

Is 2.3ms the total time for writing to that 1GiB of memory or how did 
you derive that number? Posting both results would be cleaner (with more 
digits ;) ).

-- 
Thanks,

David / dhildenb


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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-08  9:13         ` David Hildenbrand
@ 2023-03-09  2:33           ` Haifeng Xu
  2023-03-14  8:05           ` Haifeng Xu
  1 sibling, 0 replies; 12+ messages in thread
From: Haifeng Xu @ 2023-03-09  2:33 UTC (permalink / raw)
  To: David Hildenbrand, Matthew Wilcox; +Cc: akpm, linux-mm, linux-kernel



On 2023/3/8 17:13, David Hildenbrand wrote:
> On 08.03.23 10:03, Haifeng Xu wrote:
>>
>>
>> On 2023/3/7 10:48, Matthew Wilcox wrote:
>>> On Tue, Mar 07, 2023 at 10:36:55AM +0800, Haifeng Xu wrote:
>>>> On 2023/3/6 21:49, David Hildenbrand wrote:
>>>>> On 06.03.23 03:49, Haifeng Xu wrote:
>>>>>> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
>>>>>> set or not, so remove the check in handle_mm_fault().
>>>>>
>>>>> "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
>>>>>
>>>>> However, that requires now always an indirect function call -- do we care about dropping that optimization?
>>>>>
>>>>>
>>>>
>>>> If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.
>>>>
>>>> if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible
>>>> compare to the whole mm user falut preocess. And that won't cause stack overflow error.
>>>
>>> I suggest you measure it.
>>
>> test steps:
>> 1) Run command: ./mmap_anon_test(global alloc, so the memcg_in_oom is not set)
>> 2) Calculate the quotient of cost time and page-fault counts, run 10 rounds and average the results.
>>
>> The test result shows that whether using indirect function call or not, the time spent in user fault
>> is almost the same, about 2.3ms.
> 
> I guess most of the benchmark time is consumed by allocating fresh pages in your test (also, why exactly do you use MAP_SHARED?).

Yes, most of the time consumption is page allocation. MAP_SHARED or MAP_PRIVATE doesn't affect the result,so I just use one of them at will,
although no process share memory with it.

> 
> Is 2.3ms the total time for writing to that 1GiB of memory or how did you derive that number? Posting both results would be cleaner (with more digits ;) ).
> 

I'm sorry I got the measuring unit wrong,actually it is 2.3us for every page fault. The details are as follows.

without change
-------------------------------------------------------------------------------------------------
cost time(ms)			number of page fault			time of page faults(ns)
599				262144					2285
590				262144					2251
595				262144					2270
595				262144					2270
594				262144					2266
597				262144					2277
596				262144					2274
598				262144					2281
594				262144					2266
598				262144					2281
-------------------------------------------------------------------------------------------------
									average: 2272

with change
-------------------------------------------------------------------------------------------------
cost time(ms)			number of page fault			time of page faults(ns)
600				262144					2289
597				262144					2277
596				262144					2274
596				262144					2274
597				262144					2277
595				262144					2270
598				262144					2281
588				262144					2243
596				262144					2274
598				262144					2281
-------------------------------------------------------------------------------------------------
									average: 2274


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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-08  9:13         ` David Hildenbrand
  2023-03-09  2:33           ` Haifeng Xu
@ 2023-03-14  8:05           ` Haifeng Xu
  2023-03-14  9:09             ` David Hildenbrand
  1 sibling, 1 reply; 12+ messages in thread
From: Haifeng Xu @ 2023-03-14  8:05 UTC (permalink / raw)
  To: David Hildenbrand, Matthew Wilcox; +Cc: akpm, linux-mm, linux-kernel



On 2023/3/8 17:13, David Hildenbrand wrote:
> On 08.03.23 10:03, Haifeng Xu wrote:
>>
>>
>> On 2023/3/7 10:48, Matthew Wilcox wrote:
>>> On Tue, Mar 07, 2023 at 10:36:55AM +0800, Haifeng Xu wrote:
>>>> On 2023/3/6 21:49, David Hildenbrand wrote:
>>>>> On 06.03.23 03:49, Haifeng Xu wrote:
>>>>>> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
>>>>>> set or not, so remove the check in handle_mm_fault().
>>>>>
>>>>> "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
>>>>>
>>>>> However, that requires now always an indirect function call -- do we care about dropping that optimization?
>>>>>
>>>>>
>>>>
>>>> If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.
>>>>
>>>> if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible
>>>> compare to the whole mm user falut preocess. And that won't cause stack overflow error.
>>>
>>> I suggest you measure it.
>>
>> test steps:
>> 1) Run command: ./mmap_anon_test(global alloc, so the memcg_in_oom is not set)
>> 2) Calculate the quotient of cost time and page-fault counts, run 10 rounds and average the results.
>>
>> The test result shows that whether using indirect function call or not, the time spent in user fault
>> is almost the same, about 2.3ms.
> 
> I guess most of the benchmark time is consumed by allocating fresh pages in your test (also, why exactly do you use MAP_SHARED?).
> 
> Is 2.3ms the total time for writing to that 1GiB of memory or how did you derive that number? Posting both results would be cleaner (with more digits ;) ).
> 

Hi Daivd, the details of test result were posted last week. Do you have any suggestions or more concerns about this change?

Thanks.

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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-14  8:05           ` Haifeng Xu
@ 2023-03-14  9:09             ` David Hildenbrand
  2023-03-14 10:29               ` Haifeng Xu
  0 siblings, 1 reply; 12+ messages in thread
From: David Hildenbrand @ 2023-03-14  9:09 UTC (permalink / raw)
  To: Haifeng Xu, Matthew Wilcox; +Cc: akpm, linux-mm, linux-kernel

On 14.03.23 09:05, Haifeng Xu wrote:
> 
> 
> On 2023/3/8 17:13, David Hildenbrand wrote:
>> On 08.03.23 10:03, Haifeng Xu wrote:
>>>
>>>
>>> On 2023/3/7 10:48, Matthew Wilcox wrote:
>>>> On Tue, Mar 07, 2023 at 10:36:55AM +0800, Haifeng Xu wrote:
>>>>> On 2023/3/6 21:49, David Hildenbrand wrote:
>>>>>> On 06.03.23 03:49, Haifeng Xu wrote:
>>>>>>> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
>>>>>>> set or not, so remove the check in handle_mm_fault().
>>>>>>
>>>>>> "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
>>>>>>
>>>>>> However, that requires now always an indirect function call -- do we care about dropping that optimization?
>>>>>>
>>>>>>
>>>>>
>>>>> If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.
>>>>>
>>>>> if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible
>>>>> compare to the whole mm user falut preocess. And that won't cause stack overflow error.
>>>>
>>>> I suggest you measure it.
>>>
>>> test steps:
>>> 1) Run command: ./mmap_anon_test(global alloc, so the memcg_in_oom is not set)
>>> 2) Calculate the quotient of cost time and page-fault counts, run 10 rounds and average the results.
>>>
>>> The test result shows that whether using indirect function call or not, the time spent in user fault
>>> is almost the same, about 2.3ms.
>>
>> I guess most of the benchmark time is consumed by allocating fresh pages in your test (also, why exactly do you use MAP_SHARED?).
>>
>> Is 2.3ms the total time for writing to that 1GiB of memory or how did you derive that number? Posting both results would be cleaner (with more digits ;) ).
>>
> 
> Hi Daivd, the details of test result were posted last week. Do you have any suggestions or more concerns about this change?

No, I guess it really doesn't matter performance wise.

One valid question would be: why perform this change at all? The 
redundancy doesn't seem to harm performance either.

If the change would obviously improve code readability it would be easy 
to justify. I'm not convinced, that is the case, but maybe for others.

So FWIW, the change looks good to me and should not affect performance 
in one way or the other. So no objections from my side ...

-- 
Thanks,

David / dhildenb


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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-14  9:09             ` David Hildenbrand
@ 2023-03-14 10:29               ` Haifeng Xu
  2023-03-14 12:40                 ` Matthew Wilcox
  0 siblings, 1 reply; 12+ messages in thread
From: Haifeng Xu @ 2023-03-14 10:29 UTC (permalink / raw)
  To: David Hildenbrand, Matthew Wilcox; +Cc: akpm, linux-mm, linux-kernel



On 2023/3/14 17:09, David Hildenbrand wrote:
> On 14.03.23 09:05, Haifeng Xu wrote:
>>
>>
>> On 2023/3/8 17:13, David Hildenbrand wrote:
>>> On 08.03.23 10:03, Haifeng Xu wrote:
>>>>
>>>>
>>>> On 2023/3/7 10:48, Matthew Wilcox wrote:
>>>>> On Tue, Mar 07, 2023 at 10:36:55AM +0800, Haifeng Xu wrote:
>>>>>> On 2023/3/6 21:49, David Hildenbrand wrote:
>>>>>>> On 06.03.23 03:49, Haifeng Xu wrote:
>>>>>>>> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
>>>>>>>> set or not, so remove the check in handle_mm_fault().
>>>>>>>
>>>>>>> "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
>>>>>>>
>>>>>>> However, that requires now always an indirect function call -- do we care about dropping that optimization?
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.
>>>>>>
>>>>>> if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible
>>>>>> compare to the whole mm user falut preocess. And that won't cause stack overflow error.
>>>>>
>>>>> I suggest you measure it.
>>>>
>>>> test steps:
>>>> 1) Run command: ./mmap_anon_test(global alloc, so the memcg_in_oom is not set)
>>>> 2) Calculate the quotient of cost time and page-fault counts, run 10 rounds and average the results.
>>>>
>>>> The test result shows that whether using indirect function call or not, the time spent in user fault
>>>> is almost the same, about 2.3ms.
>>>
>>> I guess most of the benchmark time is consumed by allocating fresh pages in your test (also, why exactly do you use MAP_SHARED?).
>>>
>>> Is 2.3ms the total time for writing to that 1GiB of memory or how did you derive that number? Posting both results would be cleaner (with more digits ;) ).
>>>
>>
>> Hi Daivd, the details of test result were posted last week. Do you have any suggestions or more concerns about this change?
> 
> No, I guess it really doesn't matter performance wise.
> 
> One valid question would be: why perform this change at all? The redundancy doesn't seem to harm performance either.
> 
> If the change would obviously improve code readability it would be easy to justify. I'm not convinced, that is the case, but maybe for others.

Yes, this change doesn't optimize performance, just improve the code readability. 
It seems that nobody ack this change, should I change the commit message and resend this patch?

Thanks.
> 
> So FWIW, the change looks good to me and should not affect performance in one way or the other. So no objections from my side ...
> 

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

* Re: [PATCH] mm: remove redundant check in handle_mm_fault
  2023-03-14 10:29               ` Haifeng Xu
@ 2023-03-14 12:40                 ` Matthew Wilcox
  0 siblings, 0 replies; 12+ messages in thread
From: Matthew Wilcox @ 2023-03-14 12:40 UTC (permalink / raw)
  To: Haifeng Xu; +Cc: David Hildenbrand, akpm, linux-mm, linux-kernel

On Tue, Mar 14, 2023 at 06:29:24PM +0800, Haifeng Xu wrote:
> 
> 
> On 2023/3/14 17:09, David Hildenbrand wrote:
> > On 14.03.23 09:05, Haifeng Xu wrote:
> >>
> >>
> >> On 2023/3/8 17:13, David Hildenbrand wrote:
> >>> On 08.03.23 10:03, Haifeng Xu wrote:
> >>>>
> >>>>
> >>>> On 2023/3/7 10:48, Matthew Wilcox wrote:
> >>>>> On Tue, Mar 07, 2023 at 10:36:55AM +0800, Haifeng Xu wrote:
> >>>>>> On 2023/3/6 21:49, David Hildenbrand wrote:
> >>>>>>> On 06.03.23 03:49, Haifeng Xu wrote:
> >>>>>>>> mem_cgroup_oom_synchronize() has checked whether current memcg_in_oom is
> >>>>>>>> set or not, so remove the check in handle_mm_fault().
> >>>>>>>
> >>>>>>> "mem_cgroup_oom_synchronize() will returned immediately if memcg_in_oom is not set, so remove the check from handle_mm_fault()".
> >>>>>>>
> >>>>>>> However, that requires now always an indirect function call -- do we care about dropping that optimization?
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>> If memcg_in_oom is set, we will check it twice, one is from handle_mm_fault(), the other is from mem_cgroup_oom_synchronize(). That seems a bit redundant.
> >>>>>>
> >>>>>> if memcg_in_oom is not set, mem_cgroup_oom_synchronize() returns directly. Though it's an indirect function call, but the time spent can be negligible
> >>>>>> compare to the whole mm user falut preocess. And that won't cause stack overflow error.
> >>>>>
> >>>>> I suggest you measure it.
> >>>>
> >>>> test steps:
> >>>> 1) Run command: ./mmap_anon_test(global alloc, so the memcg_in_oom is not set)
> >>>> 2) Calculate the quotient of cost time and page-fault counts, run 10 rounds and average the results.
> >>>>
> >>>> The test result shows that whether using indirect function call or not, the time spent in user fault
> >>>> is almost the same, about 2.3ms.
> >>>
> >>> I guess most of the benchmark time is consumed by allocating fresh pages in your test (also, why exactly do you use MAP_SHARED?).
> >>>
> >>> Is 2.3ms the total time for writing to that 1GiB of memory or how did you derive that number? Posting both results would be cleaner (with more digits ;) ).
> >>>
> >>
> >> Hi Daivd, the details of test result were posted last week. Do you have any suggestions or more concerns about this change?
> > 
> > No, I guess it really doesn't matter performance wise.
> > 
> > One valid question would be: why perform this change at all? The redundancy doesn't seem to harm performance either.
> > 
> > If the change would obviously improve code readability it would be easy to justify. I'm not convinced, that is the case, but maybe for others.
> 
> Yes, this change doesn't optimize performance, just improve the code readability. 
> It seems that nobody ack this change, should I change the commit message and resend this patch?

I don't see the point of this patch.  Just drop it.

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

end of thread, other threads:[~2023-03-14 13:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06  2:49 [PATCH] mm: remove redundant check in handle_mm_fault Haifeng Xu
2023-03-06 13:49 ` David Hildenbrand
2023-03-07  2:36   ` Haifeng Xu
2023-03-07  2:48     ` Matthew Wilcox
2023-03-07  3:20       ` Haifeng Xu
2023-03-08  9:03       ` Haifeng Xu
2023-03-08  9:13         ` David Hildenbrand
2023-03-09  2:33           ` Haifeng Xu
2023-03-14  8:05           ` Haifeng Xu
2023-03-14  9:09             ` David Hildenbrand
2023-03-14 10:29               ` Haifeng Xu
2023-03-14 12:40                 ` Matthew Wilcox

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.