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=-15.7 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,URIBL_BLOCKED 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 74F1CC433F5 for ; Mon, 13 Sep 2021 16:03:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EF116610FE for ; Mon, 13 Sep 2021 16:03:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EF116610FE Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 60A0E6B006C; Mon, 13 Sep 2021 12:03:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BABB6B0071; Mon, 13 Sep 2021 12:03:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A95C6B0072; Mon, 13 Sep 2021 12:03:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 3C1AE6B006C for ; Mon, 13 Sep 2021 12:03:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C4ACB2BC3C for ; Mon, 13 Sep 2021 16:03:26 +0000 (UTC) X-FDA: 78583020012.18.DF9629D Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf04.hostedemail.com (Postfix) with ESMTP id 6917850000A6 for ; Mon, 13 Sep 2021 16:03:26 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 569D221FBB; Mon, 13 Sep 2021 16:03:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1631549005; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JBqyG3a4suDnnnaA3ac7IWCsPb+90G8GQiU5+rkKCIk=; b=Ar3weKnx1+I8P1sh4HMmXS1uBLW+4wBr79SZPuSNdxNbWyG6TrhJTYLZEnSJgq0NqujFjS UpTXLMx5gTJoyaZ6AmGW3tIHIVRtAHPWclKKhf/RrIpw2jV/W6gPULbm3loP8H8BG8r5ub sLeI775kCQa2bjboI/pOrxkYgvd/jqs= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id BE9EFA3B8E; Mon, 13 Sep 2021 16:03:24 +0000 (UTC) Date: Mon, 13 Sep 2021 18:03:24 +0200 From: Michal Hocko To: yongw.pur@gmail.com Cc: tj@kernel.org, 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 v1] vmpressure: wake up work only when there is registration event Message-ID: References: <1631548441-2784-1-git-send-email-wang.yong12@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1631548441-2784-1-git-send-email-wang.yong12@zte.com.cn> X-Stat-Signature: ma7ezke8tp1j8ke35mxqz3m7icb83dsx Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=Ar3weKnx; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf04.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6917850000A6 X-HE-Tag: 1631549006-524183 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: On Mon 13-09-21 08:54:01, yongw.pur@gmail.com wrote: > 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. How much of an improvement does this bring? > Refer to Michal Hocko's suggestion: > https://lore.kernel.org/linux-mm/YR%2FNRJEhPKRQ1r22@dhcp22.suse.cz/ let me also point out that we do have means to implement conditional branches with a zero overhead. Have a look at static branches. > Tested-by: Zeal Robot > Signed-off-by: wangyong > --- > mm/vmpressure.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/mm/vmpressure.c b/mm/vmpressure.c > index 76518e4..dfac76b 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. > + */ > +static atomic_t num_events = ATOMIC_INIT(0); > + > static struct vmpressure *work_to_vmpressure(struct work_struct *work) > { > return container_of(work, struct vmpressure, work); > @@ -277,7 +282,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree, > vmpr->tree_reclaimed += reclaimed; > spin_unlock(&vmpr->sr_lock); > > - if (scanned < vmpressure_win) > + if (scanned < vmpressure_win || atomic_read(&num_events) == 0) > return; > schedule_work(&vmpr->work); > } else { This is a very odd place to put the check on. It is past locks being held and schedule_work on it's own is unlikely to provide a big overhead. I would have expected to implement the check at the very beginning of vmpressure() -- Michal Hocko SUSE Labs