From patchwork Thu Aug 15 05:04:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13764402 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 9F28EC52D7F for ; Thu, 15 Aug 2024 05:05:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B2F26B0099; Thu, 15 Aug 2024 01:05:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23D336B009A; Thu, 15 Aug 2024 01:05:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B71A6B009B; Thu, 15 Aug 2024 01:05:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E13196B0099 for ; Thu, 15 Aug 2024 01:05:40 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 59EFDC1301 for ; Thu, 15 Aug 2024 05:05:40 +0000 (UTC) X-FDA: 82453292040.29.67028E4 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) by imf28.hostedemail.com (Postfix) with ESMTP id AB33BC0014 for ; Thu, 15 Aug 2024 05:05:38 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WP7X0cSU; spf=pass (imf28.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.184 as permitted sender) smtp.mailfrom=shakeel.butt@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=1723698281; 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=VYCZowvOZdc7ruHIIQXRY16w2zXEYkmh9LCBLV9ujoU=; b=jB35UxdaE+M5Nrx/O7E+KZnzLsJdPD8/g2PdgbNmcIcyfgULEYwkz62XQ8xYaWo1roZdOf p8+oQmU5ue9KGQO799auubbtMmrNnznIrLSnrkyL3BxdfRHJdtsTwTBTomMD4++pFaDvtb Cm8J6wdYRd6p7GRaUBfNJJ9zl8ySRQU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WP7X0cSU; spf=pass (imf28.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.184 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723698281; a=rsa-sha256; cv=none; b=hdWlwnucskl6jhAaNTEVfntsRCh1+iSU50kTc6c/JlF1oe2yHAp467EJ2BbamSkhCoTRh0 tCLI+TKAtH3OfzQCYg4CgVUPw1KBvpHC5BQvYINxIjo7ekXAOcLunZmXHbCB1Zqp5eU+RE a5W31YwyNAm8BEDHmAcUu+FoIvr28KY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1723698337; 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=VYCZowvOZdc7ruHIIQXRY16w2zXEYkmh9LCBLV9ujoU=; b=WP7X0cSUyHiZ4+RCUxJqB0xZEH6v5O2C7+QSCEYDQ2TRI05iHw9COqAeX0BwDbAN6DiHiA CjD2EZQ3q3DpSHkQKw1zthwY9fNApeaGXkV4jW0SMc4aMnVWGioC/q1zXwiZuRlA1DIV4k UpSi9xYB1LjAJK/yHmXtSeIAHYa2K1g= From: Shakeel Butt To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , "T . J . Mercier" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Meta kernel team , cgroups@vger.kernel.org Subject: [PATCH 6/7] memcg: allocate v1 event percpu only on v1 deployment Date: Wed, 14 Aug 2024 22:04:52 -0700 Message-ID: <20240815050453.1298138-7-shakeel.butt@linux.dev> In-Reply-To: <20240815050453.1298138-1-shakeel.butt@linux.dev> References: <20240815050453.1298138-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: pddaibms4btbcae996zdmco9yse6ic6s X-Rspam-User: X-Rspamd-Queue-Id: AB33BC0014 X-Rspamd-Server: rspam02 X-HE-Tag: 1723698338-940107 X-HE-Meta: U2FsdGVkX1/RKKaqURJkhM71lPf00SJYiWPjU4PInhQTm48EohtJX5/coOnyy2Ukmo0RcPcacmkypTlCeLE3XPIBs8Q7oGj6ON1auZ9y0zi7qhKhgf9SzBanaCJhDnPxS+rAqnBP6fqZVXTv5mzsAKocZYdQSsV7YWQT1V4ntFlMXgf4mQ98jaoKPp/fKX7VoqbnSDmne25C3RzqtAJdoZhd4kMYMSSjSs7ahkB2+fOjudn1nSQ7KM9yCEq2FwVq99c9L/H3GXUnQ3sBbOd+I7unrwZc+qr6nUAvzQKnlkkokSqyVoiCFkVxERuS8Ou+nVRMT5dfedjOLgiFawK35OxZMqRnxtzzUQG/zTUYBvXcmL4qnTdaZULayF6ttTAvBVXG+SV3X31/ZK8HB5TvndfjnC2peLdhNIqvt/XO2Oygko2y9J6tnZfycoS9vHxXgJ7ZTkGTfsSKu0Ov5EpX8rh4RPg2K82H/9Qjul/wCKOoPgbiXn3kQVjBst+nOgOpLKWivTZBtVuFUihalnAi6j3LS3DDWy9e9UUb9jouGpFsXcTRwIbskskFBcJOmSx+yX/GOrDR9s4L4hajLymiDdgMc/CaisahkvBuymvpniEqdxF54YcYdJxBz1uEEKxcpyfk1HaaldOEDwbPSu5xQ8dVYY67Lmd6rbl6cpB6MOaBcGGmPdjep9MjNXBe7a1bS56wruzwj5z8lA1QVKX2fTRL+Y2fBcEOtf7K64YFYC4PjO6uEyc0riH5juRdO9WK30mFlBpRS6I6+lqYQTjnFZEugXgFk5Z6TimmR13jr0Ff6/zApFXUJZvtNmHs25Q2Km7UbPShy/8d/8eIMEv9ZA4lZwCPhIcgMpr5U3xY/PsEM/5qTnvCNeCmTPckfWSGD8SIwRrRkK+DtzYsZyxTIyfHGYMbqLiuvxKr+bCRvzGM4zX2TuCqPB8szTG1ulHfhB2eb+AeEJHZGUVBEtQ bgGCs3wu p99vfmueJ2yXsKCSkLV4ZhnM7MKsi+7e6f2rX2ubthL5bDuhdviBpCMcx+TJ5yO/dHDF+5bU5jGJwXV6Za6GJrcSLdb1QLvmYUj7n2qT23tgt8WdC3Sj+BzUl6Q== 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: Currently memcg->events_percpu gets allocated on v2 deployments. Let's move the allocation to v1 only codebase. This is not needed in v2. Signed-off-by: Shakeel Butt --- include/linux/memcontrol.h | 3 ++- mm/memcontrol-v1.c | 19 +++++++++++++++++++ mm/memcontrol-v1.h | 26 +++++++------------------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index e21a1541adeb..1f86d01d3b97 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -255,7 +255,6 @@ struct mem_cgroup { struct list_head objcg_list; struct memcg_vmstats_percpu __percpu *vmstats_percpu; - struct memcg1_events_percpu __percpu *events_percpu; #ifdef CONFIG_CGROUP_WRITEBACK struct list_head cgwb_list; @@ -277,6 +276,8 @@ struct mem_cgroup { struct page_counter kmem; /* v1 only */ struct page_counter tcpmem; /* v1 only */ + struct memcg1_events_percpu __percpu *events_percpu; + unsigned long soft_limit; /* protected by memcg_oom_lock */ diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index 0589d08c1599..81d8819f13cd 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -1442,6 +1442,12 @@ static void mem_cgroup_threshold(struct mem_cgroup *memcg) } } +/* Cgroup1: threshold notifications & softlimit tree updates */ +struct memcg1_events_percpu { + unsigned long nr_page_events; + unsigned long targets[MEM_CGROUP_NTARGETS]; +}; + static void memcg1_charge_statistics(struct mem_cgroup *memcg, int nr_pages) { /* pagein of a big page is an event. So, ignore page size */ @@ -3049,6 +3055,19 @@ bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, return false; } +bool memcg1_alloc_events(struct mem_cgroup *memcg) +{ + memcg->events_percpu = alloc_percpu_gfp(struct memcg1_events_percpu, + GFP_KERNEL_ACCOUNT); + return !!memcg->events_percpu; +} + +void memcg1_free_events(struct mem_cgroup *memcg) +{ + if (memcg->events_percpu) + free_percpu(memcg->events_percpu); +} + static int __init memcg1_init(void) { int node; diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h index 0a9f3f9c2362..3bb8b3030e61 100644 --- a/mm/memcontrol-v1.h +++ b/mm/memcontrol-v1.h @@ -55,12 +55,6 @@ enum mem_cgroup_events_target { MEM_CGROUP_NTARGETS, }; -/* Cgroup1: threshold notifications & softlimit tree updates */ -struct memcg1_events_percpu { - unsigned long nr_page_events; - unsigned long targets[MEM_CGROUP_NTARGETS]; -}; - unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap); void drain_all_stock(struct mem_cgroup *root_memcg); @@ -72,21 +66,12 @@ unsigned long memcg_page_state_output(struct mem_cgroup *memcg, int item); unsigned long memcg_page_state_local_output(struct mem_cgroup *memcg, int item); int memory_stat_show(struct seq_file *m, void *v); -static inline bool memcg1_alloc_events(struct mem_cgroup *memcg) -{ - memcg->events_percpu = alloc_percpu_gfp(struct memcg1_events_percpu, - GFP_KERNEL_ACCOUNT); - return !!memcg->events_percpu; -} - -static inline void memcg1_free_events(struct mem_cgroup *memcg) -{ - if (memcg->events_percpu) - free_percpu(memcg->events_percpu); -} - /* Cgroup v1-specific declarations */ #ifdef CONFIG_MEMCG_V1 + +bool memcg1_alloc_events(struct mem_cgroup *memcg); +void memcg1_free_events(struct mem_cgroup *memcg); + void memcg1_memcg_init(struct mem_cgroup *memcg); void memcg1_remove_from_trees(struct mem_cgroup *memcg); @@ -139,6 +124,9 @@ extern struct cftype mem_cgroup_legacy_files[]; #else /* CONFIG_MEMCG_V1 */ +static inline bool memcg1_alloc_events(struct mem_cgroup *memcg) { return true; } +static inline void memcg1_free_events(struct mem_cgroup *memcg) {} + static inline void memcg1_memcg_init(struct mem_cgroup *memcg) {} static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {} static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {}