From nobody Sat Feb 7 21:14:51 2026 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 A0F4E1F9F7A; Sun, 25 Jan 2026 22:46:17 +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=1769381177; cv=none; b=nYvKCxdP9uMF5eG57OM7zCOoH/rpQryQJJyB4xsBkKwvlt4gCelq7C+8RNlTMZ+A6MhLz8FPfcVcXmPrg/AF5FdSw3PCRtnbvSxBl1PaIdqEMrYS82/FjWBht/h9hVhDmP1jwvuNLm0ZlZl1gqSN5We1FS7ZH3JBKQd8g9IVJBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769381177; c=relaxed/simple; bh=xkhk7ZGxynk2RcaH6iYDB0TKNwEPyWR7khi8Efbu4u0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OEWVr6owVRyAV0nY1hDIjQSFWNePyqkt/DAhI9IWPWpbDqcr0zgYMGSD+mKYiJCa8wsMCZrTa86vQD3fEnpFefLReVwE/diTacSP+Ix3DLLOkWfCWwf9amhj0Ly7JBGNT7hR1JE9fA35OrE3/v4YsBpOr6FbnHymI/o9JbRtvck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bd15xw5x; 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="bd15xw5x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D6ACC16AAE; Sun, 25 Jan 2026 22:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769381177; bh=xkhk7ZGxynk2RcaH6iYDB0TKNwEPyWR7khi8Efbu4u0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bd15xw5xwORVoabUcDJ1q5vVXlUYP45MmfLpf1Wj7eumbe1G1offqX/LsP2i05p8/ HJs/Ycv5vPdLg/ki6rSHV563InBaJlvvNpL0K92O622nmbd042+g9S/1wd4T6PYK2D 9aiGuiOJSIPrOirt4z5JnC4GNDrneBm2dNyp/TSMPtL+M/AkK0EU8o6AL54sojyU6/ 6MOAnKTImcHfao+B+LDXo/+Z63S6rC0oSeuJTmLh4N6F1x8dDaL2uM2Wa/ReCCKUzp mY/kmoEtTP6ML9TH1hzaspFsZoenAkurH84HQ+FPm7nCHw49b+ruwIfNkN/xPSnIhb Q51QFBv+lYVgQ== 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 03/33] memcg: Prepare to protect against concurrent isolated cpuset change Date: Sun, 25 Jan 2026 23:45:10 +0100 Message-ID: <20260125224541.50226-4-frederic@kernel.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20260125224541.50226-1-frederic@kernel.org> References: <20260125224541.50226-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The HK_TYPE_DOMAIN housekeeping cpumask will soon be made modifiable at runtime. In order to synchronize against memcg workqueue to make sure that no asynchronous draining is pending or executing on a newly made isolated CPU, target and queue a drain work under the same RCU critical section. Whenever housekeeping will update the HK_TYPE_DOMAIN cpumask, a memcg workqueue flush will also be issued in a further change to make sure that no work remains pending after a CPU has been made isolated. Signed-off-by: Frederic Weisbecker Acked-by: Michal Hocko --- mm/memcontrol.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index be810c1fbfc3..2289a0299331 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2003,6 +2003,19 @@ static bool is_memcg_drain_needed(struct memcg_stock= _pcp *stock, return flush; } =20 +static void schedule_drain_work(int cpu, struct work_struct *work) +{ + /* + * Protect housekeeping cpumask read and work enqueue together + * in the same RCU critical section so that later cpuset isolated + * partition update only need to wait for an RCU GP and flush the + * pending work on newly isolated CPUs. + */ + guard(rcu)(); + if (!cpu_is_isolated(cpu)) + schedule_work_on(cpu, work); +} + /* * Drains all per-CPU charge caches for given root_memcg resp. subtree * of the hierarchy under it. @@ -2032,8 +2045,8 @@ void drain_all_stock(struct mem_cgroup *root_memcg) &memcg_st->flags)) { if (cpu =3D=3D curcpu) drain_local_memcg_stock(&memcg_st->work); - else if (!cpu_is_isolated(cpu)) - schedule_work_on(cpu, &memcg_st->work); + else + schedule_drain_work(cpu, &memcg_st->work); } =20 if (!test_bit(FLUSHING_CACHED_CHARGE, &obj_st->flags) && @@ -2042,8 +2055,8 @@ void drain_all_stock(struct mem_cgroup *root_memcg) &obj_st->flags)) { if (cpu =3D=3D curcpu) drain_local_obj_stock(&obj_st->work); - else if (!cpu_is_isolated(cpu)) - schedule_work_on(cpu, &obj_st->work); + else + schedule_drain_work(cpu, &obj_st->work); } } migrate_enable(); --=20 2.51.1