From patchwork Mon Oct 25 12:51:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12581775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CF03C433F5 for ; Mon, 25 Oct 2021 12:51:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E6EE760EFF for ; Mon, 25 Oct 2021 12:51:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E6EE760EFF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 601FC940007; Mon, 25 Oct 2021 08:51:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B25D6B0072; Mon, 25 Oct 2021 08:51:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A078940007; Mon, 25 Oct 2021 08:51:38 -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 3A78A6B006C for ; Mon, 25 Oct 2021 08:51:38 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DBD3E18238CC9 for ; Mon, 25 Oct 2021 12:51:37 +0000 (UTC) X-FDA: 78734946234.19.B1C0D7D Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf06.hostedemail.com (Postfix) with ESMTP id 50E7B801A89B for ; Mon, 25 Oct 2021 12:51:37 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id na16-20020a17090b4c1000b0019f5bb661f9so8390050pjb.0 for ; Mon, 25 Oct 2021 05:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l0gxeYb7CuPuOEYUzEz6CBsyCpJ15hKcmaTNWBN6Ra0=; b=fbyV+ZZ1F6ASV4drvbf1fIgx3k1wRSJ/h4+kf2Yjc6N3kQdd+XApOqXH8rv8psJM82 BC/gmPQON6chy+iMDeA6/JcwfeUG83H/jVNXZBU2FPtadW6t2370uvj7XS4vcpV52Fki VJ2y2LNeAUIGFxirOnH3WP/lKCkwi4HWwr/NeohR0PjpCZXMuQmgaymZI/lNS59wNngI W/qOkMWkf68hRl1xUlyaQvgLL9H46M/+eW5BNoe977YqZRnzLpprefAlr/qU7IxSp2Zx Ne3NbBsD7JSV4mtrAdKA2HpcJQ1kQoomeRIGlcHBNzJePGVfQmayv5/YL/ioyYY+81ia pBYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l0gxeYb7CuPuOEYUzEz6CBsyCpJ15hKcmaTNWBN6Ra0=; b=PppMuDrSotZuTygcRSEgXOpLoZ9hy8St+mgEIHrQmC8zpZ9+K2PsICjCPUmhOs+KeW RhAdYZvpRcBvggMdVQUZNtLZLUnlyyufQUU8Iq7fh8iJgaRYbVhqgZIAnysW/kE8VfWE DT70zGkZ5U1K6bbWxqf2HL7r0VBSRnF57lW5gt3T4baEUdbmZSstZUiXyWA1vrnq5inL /IWXxwLinSkYnrwaIZQK03A66LRRpYn/xCiJ/EdSF5ABIcQutLKnSonSKW+1RvEEstqi gB83KsHtBPTjIK5rXcBfO9tekB4s5L/6sb9UaBPWV0H9KnfgGvk4AM7vju5T1NRBDRAW XbFA== X-Gm-Message-State: AOAM532epgbHbBB4XWE+37YQo8qRSwHeOuETdlPeHjK1Ta4Y7aQgBIpQ LsSyKpxoSF51HQWgf+HFJwBScQ== X-Google-Smtp-Source: ABdhPJzspTiZhhAOdxhF/PoEWNdFL59WC9kQRhjlVlbfM4tk1xVTlSDLJuGpuRoB7Rc/Nx4OolFCRA== X-Received: by 2002:a17:902:728b:b0:13f:c086:bdfe with SMTP id d11-20020a170902728b00b0013fc086bdfemr16422107pll.6.1635166296351; Mon, 25 Oct 2021 05:51:36 -0700 (PDT) Received: from localhost.localdomain ([61.120.150.70]) by smtp.gmail.com with ESMTPSA id y6sm15692823pfi.154.2021.10.25.05.51.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Oct 2021 05:51:36 -0700 (PDT) From: Muchun Song To: akpm@linux-foundation.org, mhocko@kernel.org, shakeelb@google.com, willy@infradead.org, guro@fb.com, hannes@cmpxchg.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH] mm: memcontrol: remove kmemcg_id reparenting Date: Mon, 25 Oct 2021 20:51:02 +0800 Message-Id: <20211025125102.56533-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 50E7B801A89B X-Stat-Signature: rqw35edto9a376rz9fyffpj9uaeicqnx Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=fbyV+ZZ1; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-HE-Tag: 1635166297-824693 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: Since slab objects and kmem pages are charged to object cgroup instead of memory cgroup, memcg_reparent_objcgs() will reparent this cgroup and all its descendants to its parent cgroup. This already makes further list_lru_add()'s add elements to the parent's list. So it is unnecessary to change kmemcg_id of an offline cgroup to its parent's id. It just wastes CPU cycles. Just to remove those redundant code. Signed-off-by: Muchun Song Acked-by: Roman Gushchin --- mm/memcontrol.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6538595994d2..e26f87cd7e4c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3645,8 +3645,7 @@ static int memcg_online_kmem(struct mem_cgroup *memcg) static void memcg_offline_kmem(struct mem_cgroup *memcg) { - struct cgroup_subsys_state *css; - struct mem_cgroup *parent, *child; + struct mem_cgroup *parent; int kmemcg_id; if (memcg->kmem_state != KMEM_ONLINE) @@ -3664,21 +3663,11 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg) BUG_ON(kmemcg_id < 0); /* - * Change kmemcg_id of this cgroup and all its descendants to the - * parent's id, and then move all entries from this cgroup's list_lrus - * to ones of the parent. After we have finished, all list_lrus - * corresponding to this cgroup are guaranteed to remain empty. The - * ordering is imposed by list_lru_node->lock taken by + * After we have finished memcg_reparent_objcgs(), all list_lrus + * corresponding to this cgroup are guaranteed to remain empty. + * The ordering is imposed by list_lru_node->lock taken by * memcg_drain_all_list_lrus(). */ - rcu_read_lock(); /* can be called from css_free w/o cgroup_mutex */ - css_for_each_descendant_pre(css, &memcg->css) { - child = mem_cgroup_from_css(css); - BUG_ON(child->kmemcg_id != kmemcg_id); - child->kmemcg_id = parent->kmemcg_id; - } - rcu_read_unlock(); - memcg_drain_all_list_lrus(kmemcg_id, parent); memcg_free_cache_id(kmemcg_id);