From patchwork Tue Sep 14 16:05:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yong w X-Patchwork-Id: 12494133 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,USER_AGENT_GIT autolearn=unavailable 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 A32ABC433F5 for ; Tue, 14 Sep 2021 16:06:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3D63A61155 for ; Tue, 14 Sep 2021 16:06:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3D63A61155 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 6BB5A6B0071; Tue, 14 Sep 2021 12:06:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 66B7A6B0072; Tue, 14 Sep 2021 12:06:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 533E76B0073; Tue, 14 Sep 2021 12:06:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 422006B0071 for ; Tue, 14 Sep 2021 12:06:04 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id EB55A82499A8 for ; Tue, 14 Sep 2021 16:06:03 +0000 (UTC) X-FDA: 78586655406.12.13F1A74 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf24.hostedemail.com (Postfix) with ESMTP id AC597B0000A2 for ; Tue, 14 Sep 2021 16:06:03 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id q68so13158996pga.9 for ; Tue, 14 Sep 2021 09:06:03 -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=s5oUww/KW0dwIowi5W2rJXOaMiXlxCDKY0oBpmzbqzw=; b=XNrj+vkp8TdMcL+diFidKiPuX7g/Eoa/0pzMB+yNwjiIwQAr4bkGqspPavHrz7GpRQ MziRNMfi0znxPuVdVPxwvv9+v7wo6qHOzG3ogD7u9i/MbRmA7Dj0JVLZ5hUDStlDwrHq 5brNW89diOHl547VwRfBWjP/70q9IiyepW0X2BomJCAKbF1rzhe89iBPKRUfMekhg55G tcw6QgPWuPgC0TieK1r2ltDQrDKxxh5jTFDqKF++7iuTvtWutLm2uhmm892RGj0113Rp 5/RqeZkRQvRokQqqt0YbvIsIbaJRxVfd1ife8WllzJf+Xm8mtTVuSZs/4t6Aq1OEMYMd Lf/g== 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=s5oUww/KW0dwIowi5W2rJXOaMiXlxCDKY0oBpmzbqzw=; b=ECxb2QzNFXLsUoLWHMcO/cPIWGaDypvcCcLe5+q/KrHBMhATCgJR2wdDk5i6GapIWD 1C7/lIbrV76ODsWbvDbzjCBNujL/xQDqx2ODxm9GaSp1y9gpUDY9qTNo8hV1TQ8oANgG Jya+3xql6llGzMrhzilJaGggYfITj8zZ/Vo8R4rH+R71hS68xPKjI4LT70dMpPVPfBKC Awqei27Ws/yqThgpVQS229/k3LbVupO2aJCrGU+Olz5B90SHISruopkps0T6hl6YIdMj Fwo93vk/eQfp/IVL6yPfIvFBLnc9lHrymxQIsz57d1mWj/TP7QuYlcFSmtqnu57SKUaN qpgw== X-Gm-Message-State: AOAM531EKzlzCcawHxCR//N830LShEVN4ECE7wRvKEOFUtVMQatbwccX r7+xcCje5rg5Vj21LcR1qGk= X-Google-Smtp-Source: ABdhPJy1ERBGfrwXU5csdCVVaihFZaGcXMLE2+avw8seOIH5zLLGB8jX0VYdACP47Dxbb36RmKVoXw== X-Received: by 2002:a63:3545:: with SMTP id c66mr16043185pga.377.1631635562572; Tue, 14 Sep 2021 09:06:02 -0700 (PDT) Received: from localhost.localdomain ([192.154.103.190]) by smtp.gmail.com with ESMTPSA id cp17sm2132963pjb.3.2021.09.14.09.05.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Sep 2021 09:06:02 -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 v2] vmpressure: wake up work only when there is registration event Date: Tue, 14 Sep 2021 09:05:51 -0700 Message-Id: <1631635551-8583-1-git-send-email-wang.yong12@zte.com.cn> X-Mailer: git-send-email 2.7.4 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XNrj+vkp; spf=pass (imf24.hostedemail.com: domain of yongw.pur@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=yongw.pur@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AC597B0000A2 X-Stat-Signature: a9ce8wciyc9678rixhuy78ffzgpwzi8k X-HE-Tag: 1631635563-132397 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 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 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; }