From patchwork Fri Jul 9 00:05:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12366353 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, 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 A3134C07E9E for ; Fri, 9 Jul 2021 00:05:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 57F8261466 for ; Fri, 9 Jul 2021 00:05:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 57F8261466 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 4C9786B0072; Thu, 8 Jul 2021 20:05:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A1346B0073; Thu, 8 Jul 2021 20:05:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 341196B0074; Thu, 8 Jul 2021 20:05:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id 117136B0072 for ; Thu, 8 Jul 2021 20:05:22 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6009D27764 for ; Fri, 9 Jul 2021 00:05:21 +0000 (UTC) X-FDA: 78341104842.37.9F2ACC2 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf19.hostedemail.com (Postfix) with ESMTP id 1CB0EB0000B1 for ; Fri, 9 Jul 2021 00:05:21 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id b6-20020a05620a1186b02903b429a7ee4bso5023912qkk.4 for ; Thu, 08 Jul 2021 17:05:20 -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=jhuZ3xbmwvygLf83CLhmdeU2lS+ILnD+96Bl12UNwwQ=; b=v6/1TR9Jp9q8MB8LmdT7od76ysRCArOyT9FO2mXwU1jNjU7hqKQM0aKLiOhZn9sRsb pyVKA5YohGGjVAtswwGrlI7xo/9PENSs/7IfiwKmwEUJxYioxTKvavlDDqjdfJ9QIJBZ rJYJm+jb8ylIi0IGjFWnzXYuF/3tyLL16UxipfYvOtFR3FVWfZ5eZ3quPLTXhYWPEh73 Ye8DNpWqNb7yfL4uEGqljolcxoU7cTEb6cmiqrgLx0xLqqD/ay4gcAkPvvF8c5ELWrI2 y/DfYPUrgKqhMNY/sWN+VhCbsLMnzZMsF7HyxX66apExhzA23EXaCisNBfuqEtRK214X DJRw== 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=jhuZ3xbmwvygLf83CLhmdeU2lS+ILnD+96Bl12UNwwQ=; b=UbmylQZaut5+EBQLuKVefuRy+YqnA1j73hB9rzp/mrecKOF48UjS4JO2V+OOx6z/1Q xmxHmMWVbm46sT8WyU2mD7rM18gm0QRDCwCtXVeEGkSj/fhefpEeBGN6J32sHYDwIw8i Lh21hzrwqdpQnn6FoB+Y8dzpdmz0gF4Ryime6HG+WOBmerDYtWn6OwpegO31Do5cH9kO aMH+uOZ4P+Y4vu4G6kHa7n45eVc+kMap9uhSKcAMDs+hAUADL1gMHFDrHb728bbryjzJ TZdioeZlzoubyUoiZ0x57kzhPYbi/lCZjPhqGeKcLWHf/zr15X1S/GYv9VdzijBYCObO FrHg== X-Gm-Message-State: AOAM532BF8/g9GkXob04TKUq0ivyh722AdibAW6HmOWDf+hGaRG3Lp5N aOc29M6ofTEKusNsrSWlq3+aeBwnPdU= X-Google-Smtp-Source: ABdhPJy1s7QKwgir5ZIETa39TTPGxDdQUJBb1YRH/9if3Ew7PVLazjhBLabI4NL9su//Dnh1qSZzEAZn12Q= X-Received: from surenb1.mtv.corp.google.com ([2620:15c:211:200:7a7f:fa1f:71a4:365b]) (user=surenb job=sendgmr) by 2002:ad4:5426:: with SMTP id g6mr32824500qvt.47.1625789120378; Thu, 08 Jul 2021 17:05:20 -0700 (PDT) Date: Thu, 8 Jul 2021 17:05:09 -0700 In-Reply-To: <20210709000509.2618345-1-surenb@google.com> Message-Id: <20210709000509.2618345-4-surenb@google.com> Mime-Version: 1.0 References: <20210709000509.2618345-1-surenb@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH 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, alexander.h.duyck@linux.intel.com, 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 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1CB0EB0000B1 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b="v6/1TR9J"; spf=pass (imf19.hostedemail.com: domain of 3wJLnYAYKCJEDFCz8w19916z.x97638FI-775Gvx5.9C1@flex--surenb.bounces.google.com designates 209.85.222.201 as permitted sender) smtp.mailfrom=3wJLnYAYKCJEDFCz8w19916z.x97638FI-775Gvx5.9C1@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: johdoi3ct9zbyuucs9di4nrjdmcir9rq X-HE-Tag: 1625789121-515813 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 Acked-by: Johannes Weiner Reviewed-by: Shakeel Butt --- include/linux/swap.h | 26 +++++++++++++++++++++++--- mm/memcontrol.c | 12 +++--------- mm/swapfile.c | 5 +---- 3 files changed, 27 insertions(+), 16 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 da677b55b2fe..43f3f50a4751 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7208,7 +7208,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 * @@ -7216,16 +7216,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; @@ -7265,14 +7262,11 @@ int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) * @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;