From patchwork Tue Jul 13 01:09:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12372667 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=-26.3 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 E3F85C11F66 for ; Tue, 13 Jul 2021 01:09:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 93A6C6102A for ; Tue, 13 Jul 2021 01:09:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93A6C6102A 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 C602F6B0095; Mon, 12 Jul 2021 21:09:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC20C6B0096; Mon, 12 Jul 2021 21:09:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C4456B0098; Mon, 12 Jul 2021 21:09:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id 765E76B0095 for ; Mon, 12 Jul 2021 21:09:40 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8FAC7184C0528 for ; Tue, 13 Jul 2021 01:09:39 +0000 (UTC) X-FDA: 78355782078.02.1B9CAD7 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf14.hostedemail.com (Postfix) with ESMTP id 447E360019A6 for ; Tue, 13 Jul 2021 01:09:39 +0000 (UTC) Received: by mail-qt1-f201.google.com with SMTP id a12-20020ac8108c0000b029023c90fba3dcso8909502qtj.7 for ; Mon, 12 Jul 2021 18:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=cfXnc9Zc9o3ptZPRnTFsvWMpDY8BWRepBXZRyd5PlI0=; b=LimyZz27wI/KGrLZPTZiNvhL9etIS58Jg/XdTXPk3yRn/TVtwaCz9ycSaaCZCAn+9P ecOlZ7hM5JZhxPntRzEJg/VyzOmlbwUKPLC9aO06yllP5E3C2Th0ozf6YGWocP+khU4y LfWv6uNsrBNqs6aYot1LAuVc0W5dt6mTzRO4uE2ktOlDX0PiSgtHa9LJAQFGgP3dTNfj 769TSyYWXBZHgWDaT40b5MWC0W+Tj6VF6X7bNFW11r/DDnsXrY0zowiYhRiwWpl05jZY 36wKV9FlWI6cDJl+6BPOr5h0YTfYX6IYecWZAMFPOami47wLYBmcdcxetkUa3kEx9fwI qekg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=cfXnc9Zc9o3ptZPRnTFsvWMpDY8BWRepBXZRyd5PlI0=; b=uT5Q8jj1m1VPzqnD4BBjBemdDCIpFoqduipCrE7rkFyFMEW/zlzZC3U+X8x9cSzlNG RpcJTWyolgwN9njRYb/l35JqpyUEA90/gD/ruhw9yoM4ChyuB479X982ZfjB789uaCdX 6jGqnlHjOXuzqAKtxWW0eNZWL9EtXC1Lhu9jOrcSwtMx+uDcgU096SEzWp/skZskBCps lRgMRWLZaitg1pEhKMTSiGFIUBKvJHhpNQsO1M2fonI2T4ilmIWCADbW3ORze3elYvtk eDu4FDZGWhAn5h+VdlGiHohF1nvB3ElUoe4L1hhMvzbWAOXfHu5kicI3eoaIUs3eHstL rxjw== X-Gm-Message-State: AOAM530mN7uz5J30HheBNUZ8CinSkRRuAJrFbKjXq8YV3S95r2aTkaBc ohcrgpbQNY1FGXtfWRWf6CT2VQVIWPU= X-Google-Smtp-Source: ABdhPJzSrZINmqW/6pCJgBY7HBjZ1f77ueR8ZPkCRIRns7EI7lDYTzBjY50uw7j5/MFPmcU5BYqYQz7sHMo= X-Received: from surenb1.mtv.corp.google.com ([2620:15c:211:200:2a5a:e173:9576:794e]) (user=surenb job=sendgmr) by 2002:a05:6214:e4e:: with SMTP id o14mr2249847qvc.46.1626138578201; Mon, 12 Jul 2021 18:09:38 -0700 (PDT) Date: Mon, 12 Jul 2021 18:09:32 -0700 Message-Id: <20210713010934.299876-1-surenb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v4 1/3] mm, memcg: add mem_cgroup_disabled checks in vmpressure and swap-related functions From: Suren Baghdasaryan To: tj@kernel.org Cc: hannes@cmpxchg.org, mhocko@kernel.org, mhocko@suse.com, 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 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 447E360019A6 X-Stat-Signature: 6wzpzm9kb3humzgnk35ap8y5b1qwi7q3 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=LimyZz27; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 30ufsYAYKCGMTVSFOCHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--surenb.bounces.google.com designates 209.85.160.201 as permitted sender) smtp.mailfrom=30ufsYAYKCGMTVSFOCHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--surenb.bounces.google.com X-HE-Tag: 1626138579-971275 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: Add mem_cgroup_disabled check in vmpressure, mem_cgroup_uncharge_swap and cgroup_throttle_swaprate functions. 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 ~2.1% overhead reduction when running PFT test [1] comparing {CONFIG_MEMCG=n, CONFIG_MEMCG_SWAP=n} against {CONFIG_MEMCG=y, CONFIG_MEMCG_SWAP=y, cgroup_disable=memory} configuration on an 8-core ARM64 Android device. [1] https://lkml.org/lkml/2006/8/29/294 also used in mmtests suite Signed-off-by: Suren Baghdasaryan Reviewed-by: Shakeel Butt Reviewed-by: Muchun Song Acked-by: Johannes Weiner Acked-by: Michal Hocko --- mm/memcontrol.c | 3 +++ mm/swapfile.c | 3 +++ mm/vmpressure.c | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ae1f5d0cb581..a228cd51c4bd 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7305,6 +7305,9 @@ 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 1e07d1c776f2..707fa0481bb4 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3778,6 +3778,9 @@ 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; diff --git a/mm/vmpressure.c b/mm/vmpressure.c index d69019fc3789..9b172561fded 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c @@ -240,7 +240,12 @@ static void vmpressure_work_fn(struct work_struct *work) void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree, unsigned long scanned, unsigned long reclaimed) { - struct vmpressure *vmpr = memcg_to_vmpressure(memcg); + struct vmpressure *vmpr; + + if (mem_cgroup_disabled()) + return; + + vmpr = memcg_to_vmpressure(memcg); /* * Here we only want to account pressure that userland is able to