Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2705061pxm; Mon, 28 Feb 2022 04:44:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJytf9A/YhOabcOGbYx/FVImXdxTQE1W2jYDAX1tYppY4WxO7zjfuaZXOaDkXCRKtR/lAc9S X-Received: by 2002:a17:902:d488:b0:151:3829:a910 with SMTP id c8-20020a170902d48800b001513829a910mr14771761plg.58.1646052299688; Mon, 28 Feb 2022 04:44:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646052299; cv=none; d=google.com; s=arc-20160816; b=rDmBbZcUgUcO1c/14wLbUsOVIJklqG9oMtyph1gs+b89BSVvBHOMdL08MwD8Xn7xCX zagvTagfgcAID+Jwfi1YX62nho65hO1ej/mm5nDTj2Cy+Ly3kaIuJWpJ0mtFM6lRjbdN 6e8X/imbGKOvOtx52Xjq8FUrhj2VSBCn/aVaW3HQl/GilUCZKdEHlbh0nAvVw9EaPP9g XXuqqBVtaHWdZKz/f9lj86o2ZKb0ELQg0AuiDBKBr2lHp+RRvFje+mV7Hp5ayNyhW1pS Vi0TsRlkeEgMBZ9Micfy8Bo6vdxO5glKdk8YrsdiiTOJk3sQi9YWnO3uzlLJqdqRI/Y/ d8Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dade4m+tPfltv+YBL5BFr4S8sLSocJ6SVbceY12YVP4=; b=s2BveeMXOJHVo+4EEoWMY041q1hBtKkXFkvDJIrhxc8dbwRim+hk5xf49sTb4dLsl8 USc4EpotpZMaN0/gkniDYG5iDW+1bO/D7yqItZeAFULMSl899mHpqe7eus/anGUvcD62 eRiLnI8QOPFsL/xrB4oeEF3K6QzwDG/BoHpo7zzROC27IAG0YhJZciuGUvkFXHksJq58 KM8/odkJultmrTpz1q3iFzF3npKWMaG/p96ee6vwFHGdco/wVJS8Y8kIZB46osIQmSE+ nulT/7Pw/wlUg8Jwe1y5vLyJle+lgsTSW3mBc63SGICCm1KI/xC2F82MxRmiF+zKhSiI Mh6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="f1g/kvJB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p34-20020a056a000a2200b004f114dbdafcsi10163835pfh.132.2022.02.28.04.44.45; Mon, 28 Feb 2022 04:44:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="f1g/kvJB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236385AbiB1MZe (ORCPT + 99 others); Mon, 28 Feb 2022 07:25:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236273AbiB1MZM (ORCPT ); Mon, 28 Feb 2022 07:25:12 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5CF575E71 for ; Mon, 28 Feb 2022 04:24:09 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id bx5so10981551pjb.3 for ; Mon, 28 Feb 2022 04:24:09 -0800 (PST) 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:in-reply-to:references :mime-version:content-transfer-encoding; bh=dade4m+tPfltv+YBL5BFr4S8sLSocJ6SVbceY12YVP4=; b=f1g/kvJBjfN30xCsylnaAygl8oPPzFBGUC8L8YafA7UAzTnfBH0+sZQQBOK++jomNI Tceo+BhZpE4oUeGWcQO1j530JhBX7s+U0HKG1ZQl1Ld42RMI15jdS7wAbaElmylLb3/s u0ZEqF7T4koLmlohM2LsJTLPYEvtbIFCu8jH9LMz7VdecFs0W1qDuzPAxiZnurzDfJ0y lVwxikx3PqhBzItEXWc3X8ZejterQIMtsBIOy/5tLh+ZbdoB9trsE+k62QIRsKeXqvS8 B+ycUjdT4PdUlLqy0fas3es6mEtLdxZTbF6GKz8nDt4WOMqSDPGfzzHihHOx2vsOHvuW Hpng== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=dade4m+tPfltv+YBL5BFr4S8sLSocJ6SVbceY12YVP4=; b=ouWtNFaVpezFCzcl3AwNP4jDkTJcThvndq0NuZvAMAInE/2meQBAKPy/GlJ3cyxaaV YFo9aGvWI4NEgpdM/qohZN12Ny8lmxe1W7gEVQ9EEpPJnZJm+VS9DmRav8SFF720cRee Z/+TKaP4L+unP8QSaHW7hd+Wcfv1Zo2VpuWWsC3r0LpmYDNVHul0pyWj5w4Kau1EFC60 XitaQspoB51uf4xt75TtSGdZej8f3N/b7K2knHXRkO2sbIYcUxChifnxDXtewuU7NEdB hB7gHkUF32ygDWbmr0OXklen5EQCljujDQCjBzW6h3eZY5dKNzZxvh2aU76nE86NTuQw TFIg== X-Gm-Message-State: AOAM530lKUQw8MnzpdEHNX6s+13QGqVX04/i4ijWxY2Jm7PHDSg9Wi2M Geyj4fkU91QDpOC4h1ydEFB4ZA== X-Received: by 2002:a17:90a:a385:b0:1b9:cfb8:de07 with SMTP id x5-20020a17090aa38500b001b9cfb8de07mr16121962pjp.162.1646051049016; Mon, 28 Feb 2022 04:24:09 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id ep22-20020a17090ae65600b001b92477db10sm10466753pjb.29.2022.02.28.04.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:24:08 -0800 (PST) From: Muchun Song To: willy@infradead.org, akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, shakeelb@google.com, roman.gushchin@linux.dev, shy828301@gmail.com, alexs@kernel.org, richard.weiyang@gmail.com, david@fromorbit.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, jaegeuk@kernel.org, chao@kernel.org, kari.argillander@gmail.com, vbabka@suse.cz 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, smuchun@gmail.com, Muchun Song Subject: [PATCH v6 13/16] mm: memcontrol: reuse memory cgroup ID for kmem ID Date: Mon, 28 Feb 2022 20:21:23 +0800 Message-Id: <20220228122126.37293-14-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220228122126.37293-1-songmuchun@bytedance.com> References: <20220228122126.37293-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 361ac289d8e9..809dfa4b2abc 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -348,23 +348,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 @@ -3543,7 +3526,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; @@ -3551,22 +3533,16 @@ static int memcg_online_kmem(struct mem_cgroup *memcg) if (unlikely(mem_cgroup_is_root(memcg))) return 0; - memcg_id = ida_alloc_max(&memcg_cache_ida, MEMCG_CACHES_MAX_SIZE - 1, - GFP_KERNEL); - if (memcg_id < 0) - return memcg_id; - objcg = obj_cgroup_alloc(); - if (!objcg) { - ida_free(&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; } @@ -3574,7 +3550,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; @@ -3589,20 +3564,12 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg) memcg_reparent_objcgs(memcg, parent); /* - * memcg_reparent_list_lrus() can change memcg->kmemcg_id. - * Cache it to local @kmemcg_id. - */ - kmemcg_id = memcg->kmemcg_id; - - /* * 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_reparent_list_lrus(). */ memcg_reparent_list_lrus(memcg, parent); - - ida_free(&memcg_cache_ida, kmemcg_id); } #else static int memcg_online_kmem(struct mem_cgroup *memcg) -- 2.11.0