From patchwork Mon Sep 13 15:54:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yong w X-Patchwork-Id: 12489823 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,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 41232C433EF for ; Mon, 13 Sep 2021 15:54:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D589460F9B for ; Mon, 13 Sep 2021 15:54:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D589460F9B 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 59F6C6B006C; Mon, 13 Sep 2021 11:54:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 528196B0071; Mon, 13 Sep 2021 11:54:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F08D6B0072; Mon, 13 Sep 2021 11:54:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 2FD396B006C for ; Mon, 13 Sep 2021 11:54:27 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CD9D32BC0F for ; Mon, 13 Sep 2021 15:54:26 +0000 (UTC) X-FDA: 78582997332.24.F5DD98A Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf18.hostedemail.com (Postfix) with ESMTP id 8A8FF4002087 for ; Mon, 13 Sep 2021 15:54:26 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id 18so9249336pfh.9 for ; Mon, 13 Sep 2021 08:54:26 -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=y/l6pZsY0+2abPXmYytXZzrEUxa84oSBx60olTgQf5E=; b=mySNaluwtOtRo928O2znR/NiPO5G6dqZfvoJdPmgWCMzUgffI575v5P84+CHHB0Vfl DdzelrBd3luKHRw23f4nlwsau96M4VKeCeePlQ381ozCkE2Q93w+7C8hHj9CjM3PJcpR tWXVkRQzMnbron3nqCIfSDXucVPzZbtf3/TzXvE5dKu4fJ0IpmRfYgXO5HS7iTeEY3Xj Pm2AYeBFlsxuceo0EjeJBuTL8OOsgePonPmKHpvzZhro/p9GixF6BZBcXiK8Mzs7Dwtg lob1qjaliO8X4iXY3XGpzpTvPx9X70z8BJeQCYPBZv2/Tt+HCnwbBdQUVDTQz050SALw 1Bzg== 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=y/l6pZsY0+2abPXmYytXZzrEUxa84oSBx60olTgQf5E=; b=DEwWwGmQIZ146SAPHCqv0oQ96joU4b8JD3GsC2GA3542hNNic6VD8/5Z64YAjjzPpj /M9SCdb/3Ju+YetiWokgmnWuaLWg4s2Z/lwpubE7pFzqI6ReR5FgJHn5grmYqWRgzI2K qe6R8eCT+LLyoAKc15TnOvKEd3jRU21EmWAzNc+oJsFWKLrqLifGy9euqFVf8Yni2cgd i3g3EXhsHUu1u73crEOifI1MaIVT9HkqH1+YIZ1fa4tmd9pT8jRGv6AzNk5KX4diePr3 xkwiMX89UjyJzlomPRkoP3EuuFFGPJkJ2sMSzP5B77+o8tt7xQRl2ldIXSCRg71984aQ cwAA== X-Gm-Message-State: AOAM532vZlUd6K8SqmIhece9rrkabKzHejB5tkh03gUaKKfFyMfz+OuV 4Cy0Na8befbdbsZlN7kJHIA= X-Google-Smtp-Source: ABdhPJzNqMuMRGdOROVmqd5AOofZXa1krgAO8dHxeUSI78J488MNadogQthymGUprBZCE86rFeIkYw== X-Received: by 2002:a62:403:0:b0:433:9582:d449 with SMTP id 3-20020a620403000000b004339582d449mr119417pfe.15.1631548465383; Mon, 13 Sep 2021 08:54:25 -0700 (PDT) Received: from localhost.localdomain (vps-e35ab625.vps.ovh.us. [51.81.186.255]) by smtp.gmail.com with ESMTPSA id gp11sm7239662pjb.2.2021.09.13.08.54.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Sep 2021 08:54:24 -0700 (PDT) From: yongw.pur@gmail.com X-Google-Original-From: wang.yong12@zte.com.cn To: tj@kernel.org, mhocko@suse.com, mhocko@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: [PATCH v1] vmpressure: wake up work only when there is registration event Date: Mon, 13 Sep 2021 08:54:01 -0700 Message-Id: <1631548441-2784-1-git-send-email-wang.yong12@zte.com.cn> X-Mailer: git-send-email 2.7.4 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8A8FF4002087 X-Stat-Signature: wdzdimia7shttgb3fyq491oeww14gtxq Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mySNaluw; spf=pass (imf18.hostedemail.com: domain of yongw.pur@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=yongw.pur@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1631548466-204735 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. Refer to Michal Hocko's suggestion: https://lore.kernel.org/linux-mm/YR%2FNRJEhPKRQ1r22@dhcp22.suse.cz/ 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 { @@ -407,6 +412,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); + atomic_add(1, &num_events); ret = 0; out: kfree(spec_orig); @@ -435,6 +441,7 @@ void vmpressure_unregister_event(struct mem_cgroup *memcg, if (ev->efd != eventfd) continue; list_del(&ev->node); + atomic_sub(1, &num_events); kfree(ev); break; }