From patchwork Sat Jul 10 00:36:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12368197 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=-27.0 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, 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,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 557FDC07E9B for ; Sat, 10 Jul 2021 00:36:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F39E2613C2 for ; Sat, 10 Jul 2021 00:36:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F39E2613C2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F38186B007B; Fri, 9 Jul 2021 20:36:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE9856B007D; Fri, 9 Jul 2021 20:36:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB12E8D0001; Fri, 9 Jul 2021 20:36:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id B9B326B007B for ; Fri, 9 Jul 2021 20:36:36 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EDA30184793E9 for ; Sat, 10 Jul 2021 00:36:35 +0000 (UTC) X-FDA: 78344812350.23.E13B186 Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf05.hostedemail.com (Postfix) with ESMTP id 9CD77500B72D for ; Sat, 10 Jul 2021 00:36:35 +0000 (UTC) Received: by mail-qv1-f73.google.com with SMTP id l4-20020a0ce8440000b02902d89f797d08so3679515qvo.17 for ; Fri, 09 Jul 2021 17:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=opU13ZvqFbTIG3+3YPtm0KlTLmzXrEdtRDIHVvzw01I=; b=B3gFAAegNZq5hS0hJtoWZL9U6vmEBhkZxndT53wJ6PDDklVJOLme2gmDWRYbOFu2+9 o3yn9IacVVmn+JEjdy2K8fwIOZOOKvXXjoo+JjcOtquzqA0BDiFocJlp5c57Lte2LuM4 PvtegrcSPsKjuWE6h148+opRC/Yis1IzzjmO6UYJIDq7Pev3SO6Xme3ts0jNB4d4c4mM KxiK7AXRuJY4SBplJbEV3EFZ9/+a2Gf+XDxKFiazinpHbjyWlf6CcBuPozRj641pPKcS VNMJ05R1ndOBDLVv02UCRVNENDl8RNCFbEwCpmEVXGypqJNslqiE0HADW6C0mAcRRjkH z2tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=opU13ZvqFbTIG3+3YPtm0KlTLmzXrEdtRDIHVvzw01I=; b=QQPjV9XvKTU481a7xl5jx2IWju1baBx5ZzGRXdA3vO26aDYvDgbmbMTeaQlw9E5FM0 iqFoaDEfPnKnR5yYR4q0ynl1lrWtBt+Q3Ptiy4WiJXQNPGDgCNoS3PGZhgG8SrYXgLQo QzuhWuRBCe4NcH698PDs1xSRD5PrKQEIJOlbgV6W633LL3yikTCYcvsWKV7S/UITdIvs Om+yuDIUTUSSUXEvXMoxa6YZDtsG1HEZV4/GKMiRqMi8M0n9CYvxn4X/R3PlOhjZPbq5 psSueyj7lj/0Is2Y2dyQ+Hc3GlrZdtuiOJIssiIi7rW1BRzWcdqXUljzLrkhHtVjpC2k +U6g== X-Gm-Message-State: AOAM533DtKjKJ+mCPEAvD6mzO629F0kKnmQmxbJ5cqn5f57Ehy2aHOI4 Nu0u7AapTlvYljTZu64R6RLvN+zJ+xo= X-Google-Smtp-Source: ABdhPJyVBm5z1WMOwGpSlEi9aG7dUs47ZDqEc0D2JeL1EI46btts7VM/LuH6Y+Ds97z+s+YNP27LfmafiHw= X-Received: from surenb1.mtv.corp.google.com ([2620:15c:211:200:9f62:e8e9:4de2:f00a]) (user=surenb job=sendgmr) by 2002:a05:6214:1631:: with SMTP id e17mr15837096qvw.16.1625877394878; Fri, 09 Jul 2021 17:36:34 -0700 (PDT) Date: Fri, 9 Jul 2021 17:36:26 -0700 In-Reply-To: <20210710003626.3549282-1-surenb@google.com> Message-Id: <20210710003626.3549282-3-surenb@google.com> Mime-Version: 1.0 References: <20210710003626.3549282-1-surenb@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v3 3/3] mm, memcg: inline swap-related functions to improve disabled memcg config From: Suren Baghdasaryan To: tj@kernel.org Cc: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, shakeelb@google.com, guro@fb.com, songmuchun@bytedance.com, shy828301@gmail.com, alexs@kernel.org, richard.weiyang@gmail.com, vbabka@suse.cz, axboe@kernel.dk, iamjoonsoo.kim@lge.com, david@redhat.com, willy@infradead.org, apopple@nvidia.com, minchan@kernel.org, linmiaohe@huawei.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, surenb@google.com Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=B3gFAAeg; spf=pass (imf05.hostedemail.com: domain of 3kuvoYAYKCBsJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com designates 209.85.219.73 as permitted sender) smtp.mailfrom=3kuvoYAYKCBsJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: dpjjpzy871mf1hhgsd59twmhawjhpzta X-Rspamd-Queue-Id: 9CD77500B72D X-Rspamd-Server: rspam01 X-HE-Tag: 1625877395-818139 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: Inline mem_cgroup_try_charge_swap, mem_cgroup_uncharge_swap and cgroup_throttle_swaprate functions to perform mem_cgroup_disabled static key check inline before calling the main body of the function. This minimizes the memcg overhead in the pagefault and exit_mmap paths when memcgs are disabled using cgroup_disable=memory command-line option. This change results in ~1% overhead reduction when running PFT test comparing {CONFIG_MEMCG=n} against {CONFIG_MEMCG=y, cgroup_disable=memory} configuration on an 8-core ARM64 Android device. Signed-off-by: Suren Baghdasaryan Reviewed-by: Shakeel Butt Acked-by: Johannes Weiner Reviewed-by: Muchun Song Acked-by: Michal Hocko --- include/linux/swap.h | 26 +++++++++++++++++++++++--- mm/memcontrol.c | 14 ++++---------- mm/swapfile.c | 5 +---- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 6f5a43251593..f30d26b0f71d 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -721,7 +721,13 @@ static inline int mem_cgroup_swappiness(struct mem_cgroup *mem) #endif #if defined(CONFIG_SWAP) && defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP) -extern void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask); +extern void __cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask); +static inline void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) +{ + if (mem_cgroup_disabled()) + return; + __cgroup_throttle_swaprate(page, gfp_mask); +} #else static inline void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) { @@ -730,8 +736,22 @@ static inline void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) #ifdef CONFIG_MEMCG_SWAP extern void mem_cgroup_swapout(struct page *page, swp_entry_t entry); -extern int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry); -extern void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages); +extern int __mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry); +static inline int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) +{ + if (mem_cgroup_disabled()) + return 0; + return __mem_cgroup_try_charge_swap(page, entry); +} + +extern void __mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages); +static inline void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages) +{ + if (mem_cgroup_disabled()) + return; + __mem_cgroup_uncharge_swap(entry, nr_pages); +} + extern long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg); extern bool mem_cgroup_swap_full(struct page *page); #else diff --git a/mm/memcontrol.c b/mm/memcontrol.c index cdaf7003b43d..0b05322836ec 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7234,7 +7234,7 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry) } /** - * mem_cgroup_try_charge_swap - try charging swap space for a page + * __mem_cgroup_try_charge_swap - try charging swap space for a page * @page: page being added to swap * @entry: swap entry to charge * @@ -7242,16 +7242,13 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry) * * Returns 0 on success, -ENOMEM on failure. */ -int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) +int __mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) { unsigned int nr_pages = thp_nr_pages(page); struct page_counter *counter; struct mem_cgroup *memcg; unsigned short oldid; - if (mem_cgroup_disabled()) - return 0; - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) return 0; @@ -7287,18 +7284,15 @@ int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) } /** - * mem_cgroup_uncharge_swap - uncharge swap space + * __mem_cgroup_uncharge_swap - uncharge swap space * @entry: swap entry to uncharge * @nr_pages: the amount of swap space to uncharge */ -void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages) +void __mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages) { struct mem_cgroup *memcg; unsigned short id; - if (mem_cgroup_disabled()) - return; - id = swap_cgroup_record(entry, 0, nr_pages); rcu_read_lock(); memcg = mem_cgroup_from_id(id); diff --git a/mm/swapfile.c b/mm/swapfile.c index 707fa0481bb4..04a0c83f1313 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3773,14 +3773,11 @@ static void free_swap_count_continuations(struct swap_info_struct *si) } #if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP) -void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) +void __cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) { struct swap_info_struct *si, *next; int nid = page_to_nid(page); - if (mem_cgroup_disabled()) - return; - if (!(gfp_mask & __GFP_IO)) return;