From patchwork Fri Sep 24 13:44:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yong w X-Patchwork-Id: 12515593 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 E9631C433EF for ; Fri, 24 Sep 2021 13:44:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 71B356103D for ; Fri, 24 Sep 2021 13:44:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 71B356103D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 9A97E6B0071; Fri, 24 Sep 2021 09:44:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9594C6B0072; Fri, 24 Sep 2021 09:44:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 821686B0073; Fri, 24 Sep 2021 09:44:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0107.hostedemail.com [216.40.44.107]) by kanga.kvack.org (Postfix) with ESMTP id 74E9F6B0071 for ; Fri, 24 Sep 2021 09:44:41 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3467432605 for ; Fri, 24 Sep 2021 13:44:41 +0000 (UTC) X-FDA: 78622587162.02.800D8BC Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf13.hostedemail.com (Postfix) with ESMTP id E9E9A101BC21 for ; Fri, 24 Sep 2021 13:44:40 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id 17so9911848pgp.4 for ; Fri, 24 Sep 2021 06:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id; bh=C1qOcUv37x/aaV73V8Kv4uQFgD37HZdVWZKX5cd1Pnk=; b=nfd9Owc88HKGgehebXgCJr67ojOZM1yqCQzTr98bMufXc/0LgwVS7BnbHzNNhEJpBt 3qbdd5XKWGxa4nYrhDO+Z/uHKASWxlzW8I0r6jitV/he2yVkhwwGEgb21kbP93X/PrTc PTsSb62GSsi4elOHlMxnSnSLmSVWgi9WEu59a2L79Bf9SZXlxgu3ACMfFL5KSXpux915 XaDGo484m6SXrBYzy5YJ9kAnSk2gKuI1/QMjC+A5bpooa9Ro3oRB12RRNGzTK7xTZLc1 pmxhmGWd07S/CXMnG3bjoTyzR8c2UGLwYhPB8h8xX+ejtFUUmJwfC+WTUd4hVow0CprV gYzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id; bh=C1qOcUv37x/aaV73V8Kv4uQFgD37HZdVWZKX5cd1Pnk=; b=YrKRT3au5Hm7wbQRvsON6zEZ+mV0QOC5xkvwSu1cFbbymtaL1U/4qaIwy1rNKzD0+q 4OES1U1pm2O1qF54STYzjKSRXl1WbZRpLGCbYqQ5b9WjiOFHp6FuvX7tU+ggEjmf/I0t 6ngiGck+iYqDf/u+C14eoYS5jWC7nQ76bZS/npDtiZzj6Pr0WzzTCiA+AgqXNjZIZsB3 LJQvVGiQGqMcnjESHixXLiFe+F6r0RT8S9EG1iAmGAW3ENqtTbgYI4EGDPlnf/X2KAJ8 OkPY92hj3eEau2Rq0u2Hn3HPgeIOO1PXOj90aIWayA2JwroFqJtyeXAwYWxUIAnNVKNM ESKQ== X-Gm-Message-State: AOAM532yPZKbEu7K20lBWSRbUbJW3Tjtx2lAnFKZB6A80OtGdUAPnCEC kg6VXkJf2Wv7HTNT2Pnc5h4= X-Google-Smtp-Source: ABdhPJzQumP3YVWkVIm0f8wxVRflW+gOVlCHImrqp1o9AjGWTi4Ls/KGC0BGlSBKwAN8rAV2kqvGMA== X-Received: by 2002:a63:ef57:: with SMTP id c23mr3891486pgk.60.1632491079845; Fri, 24 Sep 2021 06:44:39 -0700 (PDT) Received: from localhost.localdomain ([171.221.148.237]) by smtp.gmail.com with ESMTPSA id t13sm12299968pjj.31.2021.09.24.06.44.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Sep 2021 06:44:39 -0700 (PDT) From: yongw.pur@gmail.com X-Google-Original-From: wang.yong12@zte.com.cn To: 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: [PATCH v3] vmpressure: wake up work only when there is registration event Date: Fri, 24 Sep 2021 06:44:25 -0700 Message-Id: <1632491065-10785-1-git-send-email-wang.yong12@zte.com.cn> X-Mailer: git-send-email 2.7.4 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E9E9A101BC21 X-Stat-Signature: 9tby5txo8b77wb76gmkxgt4xi3pokcm5 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=nfd9Owc8; spf=pass (imf13.hostedemail.com: domain of yongw.pur@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=yongw.pur@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1632491080-918355 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: 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 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 1360280911 instructions 290519434.9 branches 3378378.2 branch-misses Signed-off-by: wangyong --- Changlogs in v3: -Use static inline helper to know whether there is registration event. -Add necessary description. -The location of the helper is based on that the else branch will modify the socket_pressure and will not wake up the work, and it is necessary to judge the tree parameters at the same time. Changlogs in v2: -Use static_key type data as global variable. -Make event registration judgment earlier. mm/vmpressure.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mm/vmpressure.c b/mm/vmpressure.c index 76518e4..1f53ced 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c @@ -67,6 +67,16 @@ 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 __always_inline bool vmpressure_unregistered(void) +{ + return !static_branch_unlikely(&num_events); +} + static struct vmpressure *work_to_vmpressure(struct work_struct *work) { return container_of(work, struct vmpressure, work); @@ -272,6 +282,12 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree, return; if (tree) { + /* If there is no registered event, return directly. + * We wake up work only when there is registration event. + */ + if (vmpressure_unregistered()) + return; + spin_lock(&vmpr->sr_lock); scanned = vmpr->tree_scanned += scanned; vmpr->tree_reclaimed += reclaimed; @@ -407,6 +423,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 +452,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; }