Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp842231pxb; Tue, 14 Sep 2021 09:51:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqit1pH3sFiRo2BSSkWltSIk3D13IAZ40br/HpyhS/knpLMeS460RJPwi1Afc56DdUeffP X-Received: by 2002:a05:6638:d43:: with SMTP id d3mr15275106jak.138.1631638279138; Tue, 14 Sep 2021 09:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631638279; cv=none; d=google.com; s=arc-20160816; b=Pid11N0vziaVZVPMIfy86423M4Yj7+VNMJT+8puFpulS0s88zJqUu1BE8oMfqmxb7c lc1e1Ez4e6noyM8RC2lHFkG4VCBRFaCKCB9GVAk8greVRGTE9NB1RPZQDEYugTr3wpmS p7YRMXfg8auhoO5ky/lbi1edHAP6ZmfQTx+ZMm5RDn3p6LQa+EAlVeW0Ny0EyfnxoiB0 PJeog5txUL06+/vHMw4qiHr8hIzXiWgf/0WQsJC6+aH8LQj+r7dsL5nqEJ+BkTBPqi8Q NZxikTyywGZoM7cEPqXilLjVZ3MdddDimf8jMKvwou8NhEXRdq6GUV0LgXLiGpAgSYqa NoUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8cZjnBfKQ98RvNo+t8dXEqCfexHSNrNgQFLczr/dzUw=; b=UY5SAu59ngzLusuiLAMKEIwu/S6GiMTlpJDgHDg3iaYjwkunad1QGFJrkzjYUsQeeN 3SGdzny1ylpC9OH8rvZbYQf5inkEaAvj8aKx54nN0qlvePOXxAvYpqJ9VzDp8wpwQSbX unTZa8sPuqUqcKnXj6zi7ySYjnG3LLrmK3Eb1/cgWiHKGZ3O7GXaHX8vflKhpBPe+8aq MSFnnsr+LbT7Zjuq3gl+dCpwRfNhU0+Vi60XqOwqXI/z2n1QDzTLko+plOb2HnOUTspe tTL+W67hNQE40xkMHxeD6sPDb2aub2PEfMFhhWjaM3NqK5eSQ3GGAIr469HC/CGoq55d 02yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=ZIQJC39P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r19si10141290ioa.68.2021.09.14.09.51.06; Tue, 14 Sep 2021 09:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=ZIQJC39P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229557AbhINQud (ORCPT + 99 others); Tue, 14 Sep 2021 12:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229627AbhINQu1 (ORCPT ); Tue, 14 Sep 2021 12:50:27 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5095C061762 for ; Tue, 14 Sep 2021 09:49:09 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id l18-20020a05600c4f1200b002f8cf606262so2673757wmq.1 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=e3qk5dtGkzqmX8CzkcFFIPm/q/XXW/ILkFn7Qy+FCDFzakMy3JJ0s8IcKj0zYA6m60 HT1ikNj7JCDsWzm54Pzs/KJxSy34EfJJ/FsjONE5PJ0qNpwbPHLsj6lX0sDjJR6q91jC lRd6iaITq6n7GNeqOzm/1KCMt+Y/BUP26DVL1QZ1C+/3Jx38M6Q/FtGkasmCsTkqeAdI NOzLUBE7a/4dK4Bu3CyngUa5YxcLIaayANcLwkAa00tb5vOdJBmDX8ueNH7H6Y/VirJx nvK235mLPPgFuL72CkSCX8WzlndSf6UOBn2xCqBTWxOIkAE0t1L/EWEP/2WxXWpeycV7 gNlA== X-Gm-Message-State: AOAM533YFUVCEhmfvWt9i+27/vvkjKnImeO7qlORf1c3d80up7WUTPis pBuoE8cdX1pVzl7wIvzWwPBTgQ== 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > >