From patchwork Tue Jun 25 00:59:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13710407 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A997FC2BD09 for ; Tue, 25 Jun 2024 01:00:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 643046B0367; Mon, 24 Jun 2024 20:59:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CA5B6B0368; Mon, 24 Jun 2024 20:59:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CE3C6B0369; Mon, 24 Jun 2024 20:59:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 12BDA6B0367 for ; Mon, 24 Jun 2024 20:59:58 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9C6461A157A for ; Tue, 25 Jun 2024 00:59:57 +0000 (UTC) X-FDA: 82267604034.01.02FCCA2 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by imf18.hostedemail.com (Postfix) with ESMTP id 7ACF01C0006 for ; Tue, 25 Jun 2024 00:59:55 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="xZ/trUm1"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719277179; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=aKa/FfyHPEH4o1sFdYYdtwpHqrQqG+YVicTF0vyr7Es=; b=zq7gRRvlXq6CYhdDzRL/NGnCn/Yz29to1vSOEnKEi+ZpzIy5C/gv5caxbewF34ZUOfAj1C 8N4GUBJzy0DPt2aUM4XKkYMBp8RQGc12j5XVT+PkoxzuZ0y36X3UqWHz417dcvGsGcJOC0 Webl5/1/u2a45TuxdGG+KYy+TyTMLT0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719277179; a=rsa-sha256; cv=none; b=GVvy3CJ7WtttcRmvIJzBW6OwC6QMg6bd7ATGZde2b3VvjHxQzJFPLe5YXbHYdyLAJYQVOH r3SoSh23NyKpQUuxy72frHE0xh5+xDc0TP4VWgP4HlKokZsuYpD6PrFDO2bFhzXgURt9ft ytmXGV/tQPhzCUxPCui4BDFy3yxE+KU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="xZ/trUm1"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1719277194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aKa/FfyHPEH4o1sFdYYdtwpHqrQqG+YVicTF0vyr7Es=; b=xZ/trUm1bPRxjkxHdfwXYw23D8g3nT4RuyvbkwX3GrpmF6OUjQPtABVAGUzjlLOXtMZzFy N73Jm3sr4Sw/t537Ch/wnspIKfD3obUNU29cQ4gbrd662+v0CBRE7p65+BiGKRMKacyg7m gBsWfxX0p2NJAop6892EaPa5rPKrxWk= X-Envelope-To: hannes@cmpxchg.org X-Envelope-To: mhocko@kernel.org X-Envelope-To: shakeel.butt@linux.dev X-Envelope-To: muchun.song@linux.dev X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: cgroups@vger.kernel.org X-Envelope-To: linux-mm@kvack.org X-Envelope-To: roman.gushchin@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Roman Gushchin Subject: [PATCH v2 13/14] mm: memcg: put cgroup v1-related members of task_struct under config option Date: Mon, 24 Jun 2024 17:59:05 -0700 Message-ID: <20240625005906.106920-14-roman.gushchin@linux.dev> In-Reply-To: <20240625005906.106920-1-roman.gushchin@linux.dev> References: <20240625005906.106920-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7ACF01C0006 X-Stat-Signature: ampt5mt3egcbcgnqs5s6emdu4ijrkff4 X-Rspam-User: X-HE-Tag: 1719277195-623815 X-HE-Meta: U2FsdGVkX18Ti9deGHlcNedNqBvNYXMLu688uqaUtZJQxYCi5QBwJi80GUp1DyGb75XJSSfJ6QP3pRXi3cv/OhrYeRKbYrNe+7S1jiosqY6TN0j9i6/eZd5h/Aqp4luDbmJp8d5WKZRy30dg3+4rLP57QEvMooaM/EkVbr1tEKFexLGDTUaYHU2M8TB2t6SQDpb4EJHgHhAn543Xlu8OFX43FpDpZhLjCmjcWtK1MN9G9vnWsxeGwfkbaNERE/P5J/H5yiyrdYWB0QtqExuu/2CuAlWlobgrAn38EAaETBfjRcm2TRCkFLO8kzMQDwlow4GMhzpr19kgJUI5MpGvXpoS1ayQDUh71FpKOuxZr520UzIgXDvjVUzE0XMJ3QqjNUS1LFZz8Cq/gZelNJi0djbmuiBl6hU0QX/TLSkjn7hgqSHUaS+lHIyJWlXLuD8ZbxXj/QbWvZYudJqF5dCD0ufJDMwID2R+lyWAFYiEJHVETZ33NwZDvbmaFbmpbcFItiU9wdxbCM4uF4DVKpZ+Dm1Eg/xsHTIAd9Npq0v5knkA04R2FkYlog++mBgzxawsJcKFqe12K6UyfKdD30o+xNBwJERnjXrZ0dYXL87XbbrKPsF/yDZ/VMADaT2VA0V5rVzr19O1ZDpDZBgnyPI9TdRaXE4DOwZsz8wnE3lalbOEajDLdVORTV1SYmt9TDMgI8ZkxmP5SOww2EmoqFv1LOSqVJ06AnhfeoMa5X1VZ4bLHryPJlFxqemDsoXutm8lpZuELewtOuWEdFRTO6+DS7Koztg10JlMyPFGF1EgbXviKgDmsXumY3OI9qmwu1q6qEHSmbf30Y48OdP8ElqDm3AhfrFhnMN26acNiXv+EzN5sB5+2agJfPdeNRhr4PSI6DbyE2n7jl7wYt5SrIbUHSS6BzWsz8QDTS+NneLkj3N6iGGSx5ThYCcY1KvteLblX8CkXm8nrL8Ra0f/Dex fcop44ZV 7H7XK3FxzPUgAi7ywHB9g+SvGMXskk6dO3ExdxLS76lA3gXwrFqOE/2Ki8DV93/ZkbCDxb7s5ItDOpA7EOSpi2I7Dk2Dd3nsaYqTmMbolJSfCEpS6s/j65QZpxiJZFjyFbSU3zfrprAyrq3+3BiDmODjzgZnztaqLjVcS 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: List-Subscribe: List-Unsubscribe: Guard cgroup v1-related members of task_struct under the CONFIG_MEMCG_V1 config option, so that users who adopted cgroup v2 don't have to waste the memory for fields which are never accessed. Signed-off-by: Roman Gushchin Acked-by: Michal Hocko --- include/linux/memcontrol.h | 6 +++--- init/Kconfig | 9 +++++++++ mm/Makefile | 3 ++- mm/memcontrol-v1.h | 21 ++++++++++++++++++++- mm/memcontrol.c | 10 +++++++--- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index a70d64ed04f5..796cfa842346 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1851,7 +1851,7 @@ static inline bool mem_cgroup_zswap_writeback_enabled(struct mem_cgroup *memcg) /* Cgroup v1-related declarations */ -#ifdef CONFIG_MEMCG +#ifdef CONFIG_MEMCG_V1 unsigned long memcg1_soft_limit_reclaim(pg_data_t *pgdat, int order, gfp_t gfp_mask, unsigned long *total_scanned); @@ -1883,7 +1883,7 @@ static inline void mem_cgroup_unlock_pages(void) rcu_read_unlock(); } -#else /* CONFIG_MEMCG */ +#else /* CONFIG_MEMCG_V1 */ static inline unsigned long memcg1_soft_limit_reclaim(pg_data_t *pgdat, int order, gfp_t gfp_mask, @@ -1922,6 +1922,6 @@ static inline bool mem_cgroup_oom_synchronize(bool wait) return false; } -#endif /* CONFIG_MEMCG */ +#endif /* CONFIG_MEMCG_V1 */ #endif /* _LINUX_MEMCONTROL_H */ diff --git a/init/Kconfig b/init/Kconfig index febdea2afc3b..5191b6435b4e 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -969,6 +969,15 @@ config MEMCG help Provides control over the memory footprint of tasks in a cgroup. +config MEMCG_V1 + bool "Legacy memory controller" + depends on MEMCG + default n + help + Legacy cgroup v1 memory controller. + + San N is unsure. + config MEMCG_KMEM bool depends on MEMCG diff --git a/mm/Makefile b/mm/Makefile index 124d4dea2035..d2915f8c9dc0 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -96,7 +96,8 @@ obj-$(CONFIG_NUMA) += memory-tiers.o obj-$(CONFIG_DEVICE_MIGRATION) += migrate_device.o obj-$(CONFIG_TRANSPARENT_HUGEPAGE) += huge_memory.o khugepaged.o obj-$(CONFIG_PAGE_COUNTER) += page_counter.o -obj-$(CONFIG_MEMCG) += memcontrol.o memcontrol-v1.o vmpressure.o +obj-$(CONFIG_MEMCG_V1) += memcontrol-v1.o +obj-$(CONFIG_MEMCG) += memcontrol.o vmpressure.o ifdef CONFIG_SWAP obj-$(CONFIG_MEMCG) += swap_cgroup.o endif diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h index 89d420793048..64b053d7f131 100644 --- a/mm/memcontrol-v1.h +++ b/mm/memcontrol-v1.h @@ -75,7 +75,7 @@ unsigned long memcg_page_state_local_output(struct mem_cgroup *memcg, int item); int memory_stat_show(struct seq_file *m, void *v); /* Cgroup v1-specific declarations */ - +#ifdef CONFIG_MEMCG_V1 void memcg1_remove_from_trees(struct mem_cgroup *memcg); static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) @@ -110,4 +110,23 @@ void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s); extern struct cftype memsw_files[]; extern struct cftype mem_cgroup_legacy_files[]; +#else /* CONFIG_MEMCG_V1 */ + +static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {} +static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {} +static inline bool memcg1_wait_acct_move(struct mem_cgroup *memcg) { return false; } +static inline void memcg1_css_offline(struct mem_cgroup *memcg) {} + +static inline bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked) { return true; } +static inline void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked) {} +static inline void memcg1_oom_recover(struct mem_cgroup *memcg) {} + +static inline void memcg1_check_events(struct mem_cgroup *memcg, int nid) {} + +static inline void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) {} + +extern struct cftype memsw_files[]; +extern struct cftype mem_cgroup_legacy_files[]; +#endif /* CONFIG_MEMCG_V1 */ + #endif /* __MM_MEMCONTROL_V1_H */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c7341e811945..d2e1f8baeae8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4471,18 +4471,20 @@ struct cgroup_subsys memory_cgrp_subsys = { .css_free = mem_cgroup_css_free, .css_reset = mem_cgroup_css_reset, .css_rstat_flush = mem_cgroup_css_rstat_flush, - .can_attach = memcg1_can_attach, #if defined(CONFIG_LRU_GEN) || defined(CONFIG_MEMCG_KMEM) .attach = mem_cgroup_attach, #endif - .cancel_attach = memcg1_cancel_attach, - .post_attach = memcg1_move_task, #ifdef CONFIG_MEMCG_KMEM .fork = mem_cgroup_fork, .exit = mem_cgroup_exit, #endif .dfl_cftypes = memory_files, +#ifdef CONFIG_MEMCG_V1 + .can_attach = memcg1_can_attach, + .cancel_attach = memcg1_cancel_attach, + .post_attach = memcg1_move_task, .legacy_cftypes = mem_cgroup_legacy_files, +#endif .early_init = 0, }; @@ -5653,7 +5655,9 @@ static int __init mem_cgroup_swap_init(void) return 0; WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, swap_files)); +#ifdef CONFIG_MEMCG_V1 WARN_ON(cgroup_add_legacy_cftypes(&memory_cgrp_subsys, memsw_files)); +#endif #if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP) WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, zswap_files)); #endif