From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93F8AC433F5 for ; Tue, 14 Sep 2021 16:49:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3332060FD7 for ; Tue, 14 Sep 2021 16:49:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3332060FD7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chrisdown.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id AD0236B0071; Tue, 14 Sep 2021 12:49:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A804C6B0072; Tue, 14 Sep 2021 12:49:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 949C1900002; Tue, 14 Sep 2021 12:49:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id 872436B0071 for ; Tue, 14 Sep 2021 12:49:10 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 28C128249980 for ; Tue, 14 Sep 2021 16:49:10 +0000 (UTC) X-FDA: 78586764060.02.699D38B Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf16.hostedemail.com (Postfix) with ESMTP id 99B67F000097 for ; Tue, 14 Sep 2021 16:49:09 +0000 (UTC) Received: by mail-wm1-f48.google.com with SMTP id n7-20020a05600c3b8700b002f8ca941d89so25805wms.2 for ; Tue, 14 Sep 2021 09:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=8cZjnBfKQ98RvNo+t8dXEqCfexHSNrNgQFLczr/dzUw=; b=ZIQJC39PqdNfy6y886PfF/Xyv2QsZ3DqnoJ0S5ozQT5AMmPORdXwJF0cgGxR1S51r3 gipsEbV0W+CTKwig18Aid5zMp4RYSRvdqQYmr6PPuQTB/g14jrFlsq00X+H7aoLp4CvG NSESuAgGbCn+bU1oZspQ0hEyU8eCwIaHXmNCE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=8cZjnBfKQ98RvNo+t8dXEqCfexHSNrNgQFLczr/dzUw=; b=PMva7jyy8wI3HHIOWKkvu4sCDZYdcUC6ot6Swj/eokuQevZKuFadsnPx8qounW7QgO d/59RE7UsWE3GqxY7io15I4tpF37e2dw8IoTraMBdbySjaS/PTOHPf3LxEy+y6JttDWu 73WtFsdrPxbDAigE2Pwr1uKIbuwO+/NjOO6g+IpegQaHgH/2o8+zSrDezZmxkyBFyzm3 QUpWUqseNbdKZgrrY4rmlPmJlOgxUD0ZficsOlb1fDhlVPLqA267BPFswW6zmi3P+D0I J8s6wdCm4SIEiMA7/A2cPL197bsIZpDzet0KD+JJzjMnmw/XzIsfddsdr3GFQt3YnoT9 IyHw== X-Gm-Message-State: AOAM530ekaUTQIoQ4OL20NFGiRqq32SqCSyxMkVg5NRO5g8S7dYmIF7r ZeEyzkKOCdF1S5XmH8VJX1oEJA== X-Google-Smtp-Source: ABdhPJzqeHEMXP/9pTdykDN6ru9xN7OB6P1teNNIhylfS1EyHKmQABixQp5Mj6EOHF/9gkP8sXVegg== X-Received: by 2002:a05:600c:2193:: with SMTP id e19mr54963wme.38.1631638148124; Tue, 14 Sep 2021 09:49:08 -0700 (PDT) Received: from localhost ([194.207.141.245]) by smtp.gmail.com with ESMTPSA id z79sm310798wmc.17.2021.09.14.09.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 09:49:07 -0700 (PDT) Date: Tue, 14 Sep 2021 17:49:06 +0100 From: Chris Down To: yongw.pur@gmail.com Cc: tj@kernel.org, mhocko@suse.com, peterz@infradead.org, wang.yong12@zte.com.cn, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, yang.yang29@zte.com.cn Subject: Re: [PATCH v2] vmpressure: wake up work only when there is registration event Message-ID: References: <1631635551-8583-1-git-send-email-wang.yong12@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <1631635551-8583-1-git-send-email-wang.yong12@zte.com.cn> User-Agent: Mutt/2.1.2 (9a92dba0) (2021-08-24) X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 99B67F000097 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=chrisdown.name header.s=google header.b=ZIQJC39P; dmarc=pass (policy=none) header.from=chrisdown.name; spf=pass (imf16.hostedemail.com: domain of chris@chrisdown.name designates 209.85.128.48 as permitted sender) smtp.mailfrom=chris@chrisdown.name X-Stat-Signature: nh873iq1sstay5cpf6sus1nkmg4xy67y X-HE-Tag: 1631638149-210326 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: yongw.pur@gmail.com writes: >From: wangyong > >Use the global variable num_events to record the number of vmpressure >events registered by the system, and wake up work only when there is >registration event. >Usually, the vmpressure event is not registered in the system, this patch >can avoid waking up work and doing nothing. > >Test with 5.14.0-rc5-next-20210813 on x86_64 4G ram. >Consume cgroup memory until it is about to be reclaimed, then execute >"perf stat -I 2000 malloc.out" command to trigger memory reclamation >and get performance results. >The context-switches is reduced by about 20 times. > >unpatched: >Average of 10 test results >582.4674048 task-clock(msec) >19910.8 context-switches >0 cpu-migrations >1292.9 page-faults >414784733.1 cycles > stalled-cycles-frontend > stalled-cycles-backend >580070698.4 instructions >125572244.7 branches >2073541.2 branch-misses > >patched >Average of 10 test results >973.6174796 task-clock(msec) >988.6 context-switches >0 cpu-migrations >1785.2 page-faults >772883602.4 cycles > stalled-cycles-frontend > stalled-cycles-backend >1360280911 instructions >290519434.9 branches >3378378.2 branch-misses > >Tested-by: Zeal Robot That's not how Tested-by works. Tested-by is for human testers who have actively understand and have validated the effects of the code, not CI: please remove the tag. >Signed-off-by: wangyong >--- > >Changes since v1: >-Use static_key type data as global variable >-Make event registration judgment earlier > > mm/vmpressure.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > >diff --git a/mm/vmpressure.c b/mm/vmpressure.c >index 76518e4..6f4e984 100644 >--- a/mm/vmpressure.c >+++ b/mm/vmpressure.c >@@ -67,6 +67,11 @@ static const unsigned int vmpressure_level_critical = 95; > */ > static const unsigned int vmpressure_level_critical_prio = ilog2(100 / 10); > >+/* >+ * Count the number of vmpressure events registered in the system. >+ */ >+DEFINE_STATIC_KEY_FALSE(num_events); >+ > static struct vmpressure *work_to_vmpressure(struct work_struct *work) > { > return container_of(work, struct vmpressure, work); >@@ -272,6 +277,9 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree, > return; > > if (tree) { >+ if (!static_branch_unlikely(&num_events)) >+ return; >+ > spin_lock(&vmpr->sr_lock); > scanned = vmpr->tree_scanned += scanned; > vmpr->tree_reclaimed += reclaimed; >@@ -407,6 +415,7 @@ int vmpressure_register_event(struct mem_cgroup *memcg, > mutex_lock(&vmpr->events_lock); > list_add(&ev->node, &vmpr->events); > mutex_unlock(&vmpr->events_lock); >+ static_branch_inc(&num_events); > ret = 0; > out: > kfree(spec_orig); >@@ -435,6 +444,7 @@ void vmpressure_unregister_event(struct mem_cgroup *memcg, > if (ev->efd != eventfd) > continue; > list_del(&ev->node); >+ static_branch_dec(&num_events); > kfree(ev); > break; > } >-- >2.7.4 > >