From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35BFD33BBB2; Wed, 24 Dec 2025 13:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766584061; cv=none; b=bfidvUbWNGacJ60P4TkbhdkNpWE8txYonDUPESZ9zKzbOiWLySAQjCqyEgqwVftOn4GI6+GZrx+p+m03DKGGCAY963zouQ8461zga8GtWQDfrnq6b9beKh5hCH3DFR6koBGUSi4py9BYGX77qrIpZo1kd7vAAqpKwq6yAMit988= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766584061; c=relaxed/simple; bh=xO6EwhUZh8OcDIryDj7Wm/j7fSsdSfUbDLBqDZdL1Zw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LcWnSNy2vllbG5v/Etmqa/T6k6o0p1d6dkijBPkI3T64/cd3DTe3K9vi4J6mi+oA8WY0TfhyezSwSCQ7RzQLL9m7Zbnxe7Oc5QT1ZVNpCHTPeKoAK47vOBrBk/WQxVXN2t1WFiVdaS54LUD0ivtNBjUjTucVP19iIanZ9PZ6PGs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kE4lmyVY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kE4lmyVY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F251BC4CEFB; Wed, 24 Dec 2025 13:47:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766584060; bh=xO6EwhUZh8OcDIryDj7Wm/j7fSsdSfUbDLBqDZdL1Zw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kE4lmyVY9L7SUV+YO6U6zrFhuuc+nJunhNNyns5z3QEPme4MkwloUl1uWfJJZhFCE 14yBX8qKYdhhjBk4awDDQ84foJYyWO055ytUAypzr6qRdgdTp6JMBX5SHJgyPpTHmf MZNjjGM5gppBcP7Hyko2vjFgBZueQi4ad9pjul8so/5XvZ7lqhkttcW5AeiXyI7XXa FTLICigGKI8g6jzt5LTqcHSYsUxHPTrLhc9oS2oD9hISoczLpLx2+ckmtqWtY9MZkm CDeH3KzfbDrqG2uf3x4OFxZhxicYZPbLZbenrNwW1GKOEwciVwUJ9kHg5OLoVS4Kyc NY/rx9lg1+BeQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Andrew Morton , Bjorn Helgaas , Catalin Marinas , Chen Ridong , Danilo Krummrich , "David S . Miller" , Eric Dumazet , Gabriele Monaco , Greg Kroah-Hartman , Ingo Molnar , Jakub Kicinski , Jens Axboe , Johannes Weiner , Lai Jiangshan , Marco Crivellari , Michal Hocko , Muchun Song , Paolo Abeni , Peter Zijlstra , Phil Auld , "Rafael J . Wysocki" , Roman Gushchin , Shakeel Butt , Simon Horman , Tejun Heo , Thomas Gleixner , Vlastimil Babka , Waiman Long , Will Deacon , cgroups@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-block@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 15/33] sched/isolation: Flush memcg workqueues on cpuset isolated partition change Date: Wed, 24 Dec 2025 14:45:02 +0100 Message-ID: <20251224134520.33231-16-frederic@kernel.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251224134520.33231-1-frederic@kernel.org> References: <20251224134520.33231-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The HK_TYPE_DOMAIN housekeeping cpumask is now modifiable at runtime. In order to synchronize against memcg workqueue to make sure that no asynchronous draining is still pending or executing on a newly made isolated CPU, the housekeeping susbsystem must flush the memcg workqueues. However the memcg workqueues can't be flushed easily since they are queued to the main per-CPU workqueue pool. Solve this with creating a memcg specific pool and provide and use the appropriate flushing API. Acked-by: Shakeel Butt Signed-off-by: Frederic Weisbecker --- include/linux/memcontrol.h | 4 ++++ kernel/sched/isolation.c | 2 ++ kernel/sched/sched.h | 1 + mm/memcontrol.c | 12 +++++++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 0651865a4564..5b004b95648b 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1037,6 +1037,8 @@ static inline u64 cgroup_id_from_mm(struct mm_struct *mm) return id; } +void mem_cgroup_flush_workqueue(void); + extern int mem_cgroup_init(void); #else /* CONFIG_MEMCG */ @@ -1436,6 +1438,8 @@ static inline u64 cgroup_id_from_mm(struct mm_struct *mm) return 0; } +static inline void mem_cgroup_flush_workqueue(void) { } + static inline int mem_cgroup_init(void) { return 0; } #endif /* CONFIG_MEMCG */ diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index a124f1119f2e..bb6c36d2b97b 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -145,6 +145,8 @@ int housekeeping_update(struct cpumask *isol_mask, enum hk_type type) synchronize_rcu(); + mem_cgroup_flush_workqueue(); + kfree(old); return 0; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 653e898a996a..65dfa48e54b7 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c3c473c3dfca..89bf93cf97b9 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -96,6 +96,8 @@ static bool cgroup_memory_nokmem __ro_after_init; /* BPF memory accounting disabled? */ static bool cgroup_memory_nobpf __ro_after_init; +static struct workqueue_struct *memcg_wq __ro_after_init; + static struct kmem_cache *memcg_cachep; static struct kmem_cache *memcg_pn_cachep; @@ -2007,7 +2009,7 @@ static void schedule_drain_work(int cpu, struct work_struct *work) { guard(rcu)(); if (!cpu_is_isolated(cpu)) - schedule_work_on(cpu, work); + queue_work_on(cpu, memcg_wq, work); } /* @@ -5119,6 +5121,11 @@ void mem_cgroup_sk_uncharge(const struct sock *sk, unsigned int nr_pages) refill_stock(memcg, nr_pages); } +void mem_cgroup_flush_workqueue(void) +{ + flush_workqueue(memcg_wq); +} + static int __init cgroup_memory(char *s) { char *token; @@ -5161,6 +5168,9 @@ int __init mem_cgroup_init(void) cpuhp_setup_state_nocalls(CPUHP_MM_MEMCQ_DEAD, "mm/memctrl:dead", NULL, memcg_hotplug_cpu_dead); + memcg_wq = alloc_workqueue("memcg", WQ_PERCPU, 0); + WARN_ON(!memcg_wq); + for_each_possible_cpu(cpu) { INIT_WORK(&per_cpu_ptr(&memcg_stock, cpu)->work, drain_local_memcg_stock); -- 2.51.1