From patchwork Sat Jul 10 00:36:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12368193 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 DFB35C07E99 for ; Sat, 10 Jul 2021 00:36:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5D3D2613BF for ; Sat, 10 Jul 2021 00:36:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D3D2613BF 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 3EE096B0073; Fri, 9 Jul 2021 20:36:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39DB66B0078; Fri, 9 Jul 2021 20:36:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23EE98D0001; Fri, 9 Jul 2021 20:36:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id F376A6B0073 for ; Fri, 9 Jul 2021 20:36:31 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 37F202C6A1 for ; Sat, 10 Jul 2021 00:36:31 +0000 (UTC) X-FDA: 78344812182.10.0E59817 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf16.hostedemail.com (Postfix) with ESMTP id E3D89F000090 for ; Sat, 10 Jul 2021 00:36:30 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id j9-20020a05620a0009b02903b770762a3cso6049929qki.17 for ; Fri, 09 Jul 2021 17:36:30 -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=ZSFxQqEllnhgQqgVGWhX1TPVzgfo+pOEQxzVXUrGXrk=; b=sAc/7ecFZP5kXA30C5YZ8xkXOBRQdtm2F5t0/CXgWYYABwvtTUr/VKqm/I/gky0Rq8 WveSgzFU18PV2ZevoAP+ectWUbltAEfoTlMnhaj/RjMSDDPfpZ4P36rsnHFI1zv7oHT5 AuepZM6oeCMBUm0kxEG65nYNsEVn3AIOnXyEHJ7TlLkF0Z2Vb6FULt+zS/JoVFNTjHhe 1ArC5OTnPtacdAyffJBWyYYjx3lrCgZGjp9uK/zuiR0Kc7YDoaBa1Pp5MdKA040qqPX/ 7N0i9ZQTB556jwAN+CJxb8G/iCx2WwlA9F25zL7moMckGy85MVe2PxoqJBl/9kj8Oe47 2Qng== 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=ZSFxQqEllnhgQqgVGWhX1TPVzgfo+pOEQxzVXUrGXrk=; b=KTRAhf++zhzdNCGzPhQ7O0S3rXh+2WncxY5vHCt4U8EJDu2jiHgELPCsiM9MfMke60 XswrFbpoSF0xll5HAODNGKbdQWYJA0Dtdkqmk1vpXuTQq0Mhv+KD//jxxAYi3kfJOPo4 bBpqgfKt7uUyKZRi2W1lU9uYljwi04ovgNy7FMH8TDomHTz0Yvu6k1lkPcqgjRYzjtq8 c07nTBxMlmlDq8TmY8FC7OwAulz6tDhC8O/4nV+wXG2g278XLH5tQwE3N/TXc4y9qZUO L2xopgiGFR9Gl4pz4S3hvb++rhPtKwDd4R8fUEuPf7Z2RSy6mudyrMiRBBo27rcxrbyb xr9A== X-Gm-Message-State: AOAM532Mof7uJMcKQ7OkfriORO6MIHHLved0TFT5DNykV4BvKSw0KOv/ Moz/GgOCLC7ohpteDhfxkw7oTZWnJVE= X-Google-Smtp-Source: ABdhPJxkP75WgV21IZcNxlRS6TAmzQqF7mR5/9LIYDXJQsk1G4XmdLL2D1kY+MbFVZVjIcVqYIoBzqaGKgs= X-Received: from surenb1.mtv.corp.google.com ([2620:15c:211:200:9f62:e8e9:4de2:f00a]) (user=surenb job=sendgmr) by 2002:ad4:5386:: with SMTP id i6mr39090484qvv.2.1625877390205; Fri, 09 Jul 2021 17:36:30 -0700 (PDT) Date: Fri, 9 Jul 2021 17:36:24 -0700 Message-Id: <20210710003626.3549282-1-surenb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v3 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, 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: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b="sAc/7ecF"; spf=pass (imf16.hostedemail.com: domain of 3juvoYAYKCBcFHE1Ay3BB381.zB985AHK-997Ixz7.BE3@flex--surenb.bounces.google.com designates 209.85.222.201 as permitted sender) smtp.mailfrom=3juvoYAYKCBcFHE1Ay3BB381.zB985AHK-997Ixz7.BE3@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E3D89F000090 X-Stat-Signature: h41zngteagx1dsmup7jhsmmygbuz9xp3 X-HE-Tag: 1625877390-336792 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 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. Signed-off-by: Suren Baghdasaryan Reviewed-by: Shakeel Butt Acked-by: Johannes Weiner Reviewed-by: Muchun Song 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