From patchwork Tue May 28 21:44:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13677491 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 D2DA4C25B78 for ; Tue, 28 May 2024 21:45:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 850E96B00AE; Tue, 28 May 2024 17:45:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B46C6B00B0; Tue, 28 May 2024 17:45:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DDB46B00B1; Tue, 28 May 2024 17:45:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3EBCC6B00AE for ; Tue, 28 May 2024 17:45:06 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C34F81A041D for ; Tue, 28 May 2024 21:45:05 +0000 (UTC) X-FDA: 82169135370.04.1298373 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf24.hostedemail.com (Postfix) with ESMTP id 9272018000F for ; Tue, 28 May 2024 21:45:03 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="hrL47g/m"; spf=pass (imf24.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716932703; 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=l2pLA/RqNoqlbvbC4p4fDwpEqhgLufpxOxGhK7S1G2o=; b=ZY697+V58Ld8batFAOoGXRnTuKUdUk7nFU6g14b7l14AEG+KAVsxL0ndHMQRP2O7Ox0nTP cLktpf+wpIEgf+Orb1GivyRM3DuSMea0Gei84CLHL02BPNqG1UO0DxsYFtwlbTxJTJfBFa HQ6xklZyfWl2J686UYng22YKltGfS9U= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="hrL47g/m"; spf=pass (imf24.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716932703; a=rsa-sha256; cv=none; b=VD3dbZwI4S3Q4PlRRMhfqaO/PgaNb1jBfXnnxK4jKH05qlqDzF3VQguSShSzNpPCyndL0X 43dsSjwcDiRPAG/RzYsJhqHdDVsUIMxjEEwqrSMzolc9z3Te+aFqa1OGqZB5yYmz1gYmP1 8bLMAJUIf9eOxUIr78AxOhjEc51tNAw= X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1716932702; 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=l2pLA/RqNoqlbvbC4p4fDwpEqhgLufpxOxGhK7S1G2o=; b=hrL47g/mD1SQrSO2YhcIljWTdeJXZtuP+O7Sspx8GuL8CyR5bK0pB33DFF/Flum7NaPBcj wuqXxuVDRjfVR4Hq70V1K0YhgI/IldHzP4IpGe0FW+30xwSnmKy8X5nPUvW2IVWvuTOWSK y7K++vRfFd0kmbxOqcAuKddTyqUJAUo= X-Envelope-To: muchun.song@linux.dev X-Envelope-To: hannes@cmpxchg.org X-Envelope-To: mhocko@kernel.org X-Envelope-To: shakeel.butt@linux.dev X-Envelope-To: willy@infradead.org X-Envelope-To: linux-mm@kvack.org X-Envelope-To: linux-kernel@vger.kernel.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: Muchun Song , Johannes Weiner , Michal Hocko , Shakeel Butt , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Roman Gushchin Subject: [PATCH v1 13/14] mm: memcg: put cgroup v1-related members of task_struct under config option Date: Tue, 28 May 2024 14:44:34 -0700 Message-ID: <20240528214435.3125304-4-roman.gushchin@linux.dev> In-Reply-To: <20240528214435.3125304-1-roman.gushchin@linux.dev> References: <20240528202101.3099300-1-roman.gushchin@linux.dev> <20240528214435.3125304-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9272018000F X-Stat-Signature: xjpgewhp1dco7deyqpbx9zje1cwssg6n X-Rspam-User: X-HE-Tag: 1716932703-505982 X-HE-Meta: U2FsdGVkX18yr8dZs3EhQbzetN568DUBGJPAagK3ys5oumtZW30E3UxEQSPuOaBk+DBXqvWyxzGCBSEb8AZWBmDue54rvg6gaSgNmQ9V9EvYWaQMg8h4bfVQbdv7/7qQoAcjMlLL5vy1jQoA4NUaELkEgpv7LZb2LVy2UhChp8otre9Jqoz7+ICEb4nN2yZB1s2C3Sgj5yetYL9k2L9piGXrhgJoe7hJJpVoQo/v15FrM8rCLLPaTZp2g1QCY+RZEs1T5aMD4wV2J0kv5D8lS+Wz3w99AgjU1moavEgH4i+3jxkg8P2P78TL1p88QMpM8LT1zHD/fkhkM/paGM557dGwnhTakYaULaS3mZv6wNH584aCzkKt0AmOyZPtGrDuG+QvwbpuPnKNbC/qlf/VXapuB+xZLVrHYGBkVB2HZvdfEYrjRgLa0MJA70WZYf89t0+JNGBfWKPrvZXaZJ52hLe+h1jNpQZFqFxBDIZ8yB9cVw8ACnI0bxi0ohpz2hrfG9D9xCeLWj59lurAJG8ULeFQk8JGfvfOQHln9V316YoyltqYkXmOxs0ccxMk5ANRXLamW6AYarpSs9GO13aSZqnbX+23Ycih3lQgmB1f68Ed9g0CZr6SUjos66gQMtJk3WNrQlAU985X6/PzsLRnaj0c+aqo3UMleeCOMlCAxClYNEgXwJ3MQYshrop4jFbbPvsYHtLEyRL/1HUCejPoLbJJGcNpFYywVaQJvUpAAmK65xCk1dcMRxGRwa3NXyHhOPld2V/pzjWLiT19LKWVH20CqbpzVehxlNCuGeGjS5vj61JVcINZLbX8vWt0v0kF8CAvK0tlGBIl8ZqofTI7pDqKa32FH3BYqjMCQdAZ5Z1PmcBqbp7Mlmen78+hyRdsK2npCC1G5ao4sqnTrpIkO7ELf2CHYDe4jYcNkPt3+4MFmuVR5oVg0dwbbDpYhIfrsFrsgWF0DGZqvuQNndE wHszYkJW rf7FqY6Nv2OookxDkGi+RsGsRqJlvlZHyKolTK2VJKimzKepOHa/uZf/UkEpugO3hMtQ3sibYrVOxIRmNi3YZ9ORwVSjDlleTmwTETTty7FvsaMJ0i88BRgxOgwVlzcgBd+Uk 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: Shakeel Butt --- include/linux/memcontrol.h | 2 +- init/Kconfig | 9 +++++++++ mm/Makefile | 3 ++- mm/memcontrol-v1.h | 21 ++++++++++++++++++++- mm/memcontrol.c | 10 +++++++--- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 7474b20a5d3f5..aaa97ec0634f7 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1845,7 +1845,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); diff --git a/init/Kconfig b/init/Kconfig index febdea2afc3be..5191b6435b4e7 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 124d4dea20351..d2915f8c9dc01 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 89d4207930481..64b053d7f131e 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 8a28ba4ca93ea..8cbceeb9c7ac4 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4473,18 +4473,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, }; @@ -5655,7 +5657,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