From patchwork Thu May 27 06:21:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12283503 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 ECE5DC4708B for ; Thu, 27 May 2021 06:26:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 925746135F for ; Thu, 27 May 2021 06:26:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 925746135F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 379636B007B; Thu, 27 May 2021 02:26:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3519D6B0087; Thu, 27 May 2021 02:26:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F1DC8D0001; Thu, 27 May 2021 02:26:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0243.hostedemail.com [216.40.44.243]) by kanga.kvack.org (Postfix) with ESMTP id E28806B007B for ; Thu, 27 May 2021 02:26:30 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 34F49815E for ; Thu, 27 May 2021 06:26:30 +0000 (UTC) X-FDA: 78186026940.32.CA6541B Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf09.hostedemail.com (Postfix) with ESMTP id 467FC600024C for ; Thu, 27 May 2021 06:26:25 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id f22so2919386pgb.9 for ; Wed, 26 May 2021 23:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IDeG++/blhLntk2pJHHgm+mSW8cVt7IZBOEblp/zC60=; b=DtpEH0I9Yks3SIBK6zIWD8R8VgT9fGU33bCNhHyJmktNP98gHzu6h5t1RIT/meam5f awAT2WP+76Z51QkQ60dtOvamBUPPUXfM7qdhq15wSMBcEDBXnUhMqIOPyw73jnG2RYBB aCIRzaW/jpP+oXABiXaym8ZbosFDdfpKQwlrOCOJ6OjqFW0pZpufqP59sJuI0dV5/5IU aP3QoANGK74pYhNxTnZNbTKuT9o1FUosMaEJiCF6tg9c1bXjVR+v6bBNZpgvu1qzAIdu WpnQvxRgE6K5THPZVmMwQ04qmWOaphT0yyP6G83/Af5J6y4eGMr/xB7qUiozd2IdKRvV OKug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IDeG++/blhLntk2pJHHgm+mSW8cVt7IZBOEblp/zC60=; b=Pfyuh3WEK7QOheLf6U1GAR2j0I/IUR5U8tyqqTGGqtycLlJ9141mHtnEzSenv+oc75 kaWSF6xZm7AnSeZlpx+Jqc88JNKrUTqjGkcvZhbNm/O7AmXZMEJYovOPke9IliFZyeRB D60v2kWpKfB2QycHm80Q3H1DFVXS1En7Yt/Ph9Vi4n5oJFKwbJ4Re8LyYCqjrs3qjWmO u3wp8oGzwq0uhR88n5B7NYlF/eAKNRbQNtfP/P4fgyuwkdp215ebenmCC+QOUVOflejP +u+w601oobSeZkbdu5l9+LTNoS9+ntbxQbmdL4kkD1BIFwXmARYWOjyXO8nKGJ6+tw16 JkFw== X-Gm-Message-State: AOAM53341zSz4szOjwzpPUs4VkNr1j7lBXVyQmfSvtICQKW52MBQQ++N sxEziVNi2HKZnn3kyoTQ4iuZxQ== X-Google-Smtp-Source: ABdhPJy6LpMfHvxJKRmRoM7o+N0+95VtxvCbt414eASgexHfTHjbHGFW4pU6bsnvfRmroLKxBTlUXg== X-Received: by 2002:a65:64cc:: with SMTP id t12mr2334997pgv.64.1622096789011; Wed, 26 May 2021 23:26:29 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id m5sm882971pgl.75.2021.05.26.23.26.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 May 2021 23:26:28 -0700 (PDT) From: Muchun Song To: willy@infradead.org, akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, shakeelb@google.com, guro@fb.com, shy828301@gmail.com, alexs@kernel.org, richard.weiyang@gmail.com, david@fromorbit.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, zhengqi.arch@bytedance.com, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v2 18/21] mm: memcontrol: reuse memory cgroup ID for kmem ID Date: Thu, 27 May 2021 14:21:45 +0800 Message-Id: <20210527062148.9361-19-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210527062148.9361-1-songmuchun@bytedance.com> References: <20210527062148.9361-1-songmuchun@bytedance.com> MIME-Version: 1.0 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=DtpEH0I9; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 467FC600024C X-Stat-Signature: 46nz3b1h3cdcrxa8cxa38yscug3cuop9 X-HE-Tag: 1622096785-125818 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: There are two idrs being used by memory cgroup, one is for kmem ID, another is for memory cgroup ID. The maximum ID of both is 64Ki. Both of them can limit the total number of memory cgroups. Actually, we can reuse memory cgroup ID for kmem ID to simplify the code. Signed-off-by: Muchun Song --- mm/memcontrol.c | 40 +++------------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 82b147597138..ae3ad1001824 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -342,23 +342,6 @@ static void memcg_reparent_objcgs(struct mem_cgroup *memcg, } /* - * This will be used as a shrinker list's index. - * The main reason for not using cgroup id for this: - * this works better in sparse environments, where we have a lot of memcgs, - * but only a few kmem-limited. - */ -static DEFINE_IDA(memcg_cache_ida); - -/* - * MAX_SIZE should be as large as the number of cgrp_ids. Ideally, we could get - * this constant directly from cgroup, but it is understandable that this is - * better kept as an internal representation in cgroup.c. In any case, the - * cgrp_id space is not getting any smaller, and we don't have to necessarily - * increase ours as well if it increases. - */ -#define MEMCG_CACHES_MAX_SIZE MEM_CGROUP_ID_MAX - -/* * A lot of the calls to the cache allocation functions are expected to be * inlined by the compiler. Since the calls to memcg_slab_pre_alloc_hook() are * conditional to this static branch, we'll have to allow modules that does @@ -3542,7 +3525,6 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css, static int memcg_online_kmem(struct mem_cgroup *memcg) { struct obj_cgroup *objcg; - int memcg_id; if (cgroup_memory_nokmem) return 0; @@ -3550,22 +3532,16 @@ static int memcg_online_kmem(struct mem_cgroup *memcg) if (unlikely(mem_cgroup_is_root(memcg))) return 0; - memcg_id = ida_simple_get(&memcg_cache_ida, 0, MEMCG_CACHES_MAX_SIZE, - GFP_KERNEL); - if (memcg_id < 0) - return memcg_id; - objcg = obj_cgroup_alloc(); - if (!objcg) { - ida_simple_remove(&memcg_cache_ida, memcg_id); + if (!objcg) return -ENOMEM; - } + objcg->memcg = memcg; rcu_assign_pointer(memcg->objcg, objcg); static_branch_enable(&memcg_kmem_enabled_key); - memcg->kmemcg_id = memcg_id; + memcg->kmemcg_id = memcg->id.id; return 0; } @@ -3573,7 +3549,6 @@ static int memcg_online_kmem(struct mem_cgroup *memcg) static void memcg_offline_kmem(struct mem_cgroup *memcg) { struct mem_cgroup *parent; - int kmemcg_id; if (cgroup_memory_nokmem) return; @@ -3586,16 +3561,7 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg) parent = root_mem_cgroup; memcg_reparent_objcgs(memcg, parent); - - /* - * memcg_reparent_list_lrus() can change memcg->kmemcg_id. - * Cache it to @kmemcg_id. - */ - kmemcg_id = memcg->kmemcg_id; - memcg_reparent_list_lrus(memcg, parent); - - ida_simple_remove(&memcg_cache_ida, kmemcg_id); } #else static int memcg_online_kmem(struct mem_cgroup *memcg)