linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Haifeng Xu <haifeng.xu@shopee.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: David Hildenbrand <david@redhat.com>,
	akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: remove redundant check in handle_mm_fault
Date: Wed, 8 Mar 2023 17:03:46 +0800	[thread overview]
Message-ID: <6df72872-2829-47ab-552c-7ef8a6470e6f@shopee.com> (raw)
In-Reply-To: <ZAamFX/hq6Y/iNJb@casper.infradead.org>

[-- 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;
}

  parent reply	other threads:[~2023-03-08  9:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-06  2:49 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6df72872-2829-47ab-552c-7ef8a6470e6f@shopee.com \
    --to=haifeng.xu@shopee.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox