Message ID | 20230306024959.131468-1-haifeng.xu@shopee.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1627784wrd; Sun, 5 Mar 2023 18:54:23 -0800 (PST) X-Google-Smtp-Source: AK7set+6ZeQ3P3X8rUUa/LApc4XE6CLjeyRJOBbuJRXV83cI0nOBc38WFOqtR81MI50uCIsVyepZ X-Received: by 2002:a05:6a20:3b1b:b0:c7:30a5:e473 with SMTP id c27-20020a056a203b1b00b000c730a5e473mr8161253pzh.34.1678071263547; Sun, 05 Mar 2023 18:54:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678071263; cv=none; d=google.com; s=arc-20160816; b=H1WWcrmpG7EL/bOo5/dClV5Hu0atpMVn0QO7P4IbtmNiI8nB2BQoXSa3RUreqRscDr lqDW+iFPV3kivN6UB5CKZWjE+YcwyqLMk1H/nViXEQnJ+TzFUvUiYxOUT/fRGzoccp8Y yblgp46IlLwoV5xE2ZZsHwF/8zCe+g/R501m1EInLeO2CL7zZh7T+R/CxXTkkCgWXT+J ZW4y35GZoOwurKApwyYHgK10M8ncRQDO688lTy2hEzrMsmW1L8M8f4J6PIDObOw6n98e 2tut3nI5cT3zV0enrG58rY80tkuxlhauWoizwW9igJnJk+QZm1RJVbAvvFSQOZp2rgli MtMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=EVGjMrclCEaMIMZKUYlnh2axdze/uTIR/Mv0pCsUOmU=; b=xFKWAOOLqtP4xBv3142CfZt4Hh5LdUregY0yQjdCyd4PbU8jHYrZHYXGWfsDLRZyNW ZOgjvGd/EqBSwAr6+F1uKbdjMlIx6x/QrAtlZssIVCJKLmg7U4gB/gmoJ7BHQN+x49Uu Aon5pwpnVSUaeZOJyQhtHAzhTjnhFwVMEh67nuYF7SwhpCatWzShms1yizYuRKU5MREy 8sKJ6NhLr2GeHAZOAmGM6xI9/GdQNwGrg16NU90DYkiOgkltLj4T0R3y2Mq/YvPh5FES hKn92LAs40XBfABOUY/QDB1lZPi/bwPPZyONMhS2/fzB/rNwKCwgWkIRVh6yok8ikhEQ NidA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shopee.com header.s=shopee.com header.b=DZX7UT6a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=shopee.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p24-20020a63c158000000b00502ea14e6ecsi7748341pgi.712.2023.03.05.18.54.10; Sun, 05 Mar 2023 18:54:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@shopee.com header.s=shopee.com header.b=DZX7UT6a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=shopee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbjCFCus (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Sun, 5 Mar 2023 21:50:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbjCFCur (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 5 Mar 2023 21:50:47 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 764A6F97C for <linux-kernel@vger.kernel.org>; Sun, 5 Mar 2023 18:50:45 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id x34so8416697pjj.0 for <linux-kernel@vger.kernel.org>; Sun, 05 Mar 2023 18:50:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1678071045; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EVGjMrclCEaMIMZKUYlnh2axdze/uTIR/Mv0pCsUOmU=; b=DZX7UT6aDv2BtYbLOycfYuulqo/XjuiHjzkPqawXrF7CBrhYSSHwBkP8oP0itHuZw2 pE8d47n571CFwzX3S5XQFKDPMN5WsSjV34ezRN9uyhq2JD7Rahx69rFI151jcxOLXchm 1Rn91tCQASUfxtMAOS9m1sKLkak64Pc0qI/7hAaN5b8QjCDHgz9GroQboQ5LsB2nyp2n 0PfBYq7uJytXjWjkHq6fbZ4JaVU6PVAQ7y5adi1XAzUiwm2ws/nPSZJ7si5040d/pbCk ziCTixd+4nTd3oKlB89e+0czAORVMdJQxUC82tTP4BIB8rkZs9NArYw1pI9Czi5P1KM7 gErg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678071045; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EVGjMrclCEaMIMZKUYlnh2axdze/uTIR/Mv0pCsUOmU=; b=JGRNRGPxRMVk1wnaZJF/XggCFZZ1H0CAfV0kI7pXVWXQynjQQKF9fvKk4+Sw15XaXD 2Z5ppnEb76ds7EbLlXPFBWiAfXNNX2fkOr1VBX4oITtDM32QuSECl9tFz4i5s88YH1LV JioSV3O42K41sE0WRKSGtSZ2dtpR8oTBLptZlDv2jWccJb7CSnmaeJRpKYVSxJ2ngaJD vDs1IhWifIoHrmzoP51oIFmG+kdgbTpa6TCxsF6tZMdqy/ibH5CG9HtTrZP+EpgsV5DB y+E5511OKbgUJ/PWZ3u+WOCKSKNDDVEX7j1rHyMxPKAnIMMk4xqFq80AN1kJjsVO5Uj7 ZQCg== X-Gm-Message-State: AO0yUKUbZlt24lmjqwk6lAJEujvx/F8NFY9tGuWZx2V6k3mVpnpTqGzn nvERVd4BZLUuTDEjt2BB8q4kGmHjTx7QcPtdivo= X-Received: by 2002:a17:903:1209:b0:19d:1bd6:4b80 with SMTP id l9-20020a170903120900b0019d1bd64b80mr9987196plh.42.1678071044951; Sun, 05 Mar 2023 18:50:44 -0800 (PST) Received: from ubuntu-haifeng.default.svc.cluster.local ([101.127.248.173]) by smtp.gmail.com with ESMTPSA id u3-20020a170902e80300b0019a6e8ceb49sm5348879plg.259.2023.03.05.18.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:50:44 -0800 (PST) From: Haifeng Xu <haifeng.xu@shopee.com> To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Haifeng Xu <haifeng.xu@shopee.com> Subject: [PATCH] mm: remove redundant check in handle_mm_fault Date: Mon, 6 Mar 2023 02:49:59 +0000 Message-Id: <20230306024959.131468-1-haifeng.xu@shopee.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759585253024814898?= X-GMAIL-MSGID: =?utf-8?q?1759585253024814898?= |
Series |
mm: remove redundant check in handle_mm_fault
|
|
Commit Message
Haifeng Xu
March 6, 2023, 2:49 a.m. UTC
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(-)
Comments
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?
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.
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.
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.
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. #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; }
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 ;) ).
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
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.
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 ...
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 ... >
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.
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); }