From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796392297; b=1c5tANoBnikfvJRLTmTExH/BXLHniQnOXor2MJwHhQ3c+xnU5BgQzvMU6b/aAtj+XTfr Fi9ziRXfbHejYnEFk1kFBjX2kTTOfLa6NmwuW2qg71cUjsHjMFIEaViotry+p9/YZK7mp PziVhQPbO+rSJKV9qtgiDH1dCcsiFwPkglpn+M5P/EnOKCllJ0jf5IHY7gaqTYC9USWTn Sr/Gq1nrYXwB7mDgE+vgda4w1HWthEspGaAZdHlxWxL6i2B/e9iX+NuMNo8sN87c87Qde 2CTfMidv0ob5jDEakpCafj4xGhnyiX8sdbaDyxMN7HFXHUn0np31XS+lKxy23U7PBTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796392297; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=9MWq/vvErMwN161k49zgDz6IHEKN1tapmR8tQGJ3FrU=; b=gwcksRF/H3pmxy/gk5FPS5zfIXp0sjj+Mzqyf/1dpQbJDzTnJkJFBr6F2ow+05CIjkBa 5rDI9fBb3mml7f8dbDKdt8aFHvGlXtO29k2Ox/YjDulVky5MFECHx7TCoVgw6ZkKU5H7k hI6IMSLN1axzMI8azekOUpzA6JKiIG++wTsNwaalK+yMaOJzGGkQRdf/rARCdHwxvWgCm cc2rGN6rW7SzCqLF3ymi1dR6GIMzNapuYeVgdGAqpwhr9jDxfaTlg1b/ql8AQ2lYRZkHj sEiLmpd+jvFuQbCr7vYll3vR/ObxZ+/6jEtTbOEq9ixjbj669t58AN4cAIJ19UzvroA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Xc0Xy3IR; arc=none smtp.remote-ip=74.125.82.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50C82606A337 for ; Fri, 4 Dec 2026 13:51:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 50C82606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Xc0Xy3IR Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-38431138772so1320700eec.1 for ; Fri, 04 Dec 2026 05:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796392295; x=1796997095; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9MWq/vvErMwN161k49zgDz6IHEKN1tapmR8tQGJ3FrU=; b=Xc0Xy3IRIQQb0I76wvnL/dMiK83coDV5bfh/0MY5yixgriFcekCFMRWyZJMcmvvJHu mAngfeVixiIPAOM75rAl1Vmcqr4z5CdJm7TMrNmdR5rR2Bg7hFcmMUIStvRaFhkRMNhg pxDznX1aewKV0pAErkgFrt3LdZaA2DhrVMsTT2GTKBNxllpmipQMYRHsNGOl7WLwFSlk 4/OlLBrK6Q3S4Svq/x2wlxbjYu+yDoSbg2kIvDKWEqidYdzju8v+K1rjjfekZfe6Z8zp Zes1lCwnhfeSpF0+sd3a7JpTLcdARUVJZUDpI4uMyNIOwSkwfIcazF8/TKvmcm4eLYBu IOwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796392295; x=1796997095; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9MWq/vvErMwN161k49zgDz6IHEKN1tapmR8tQGJ3FrU=; b=XJNm962GKuUc5d2Qkn900SSoR7rH0//gq4TbfVbPleGJgQcbIZZUWpSGQRziKgAQf/ lTyc5olYm8zu6Fa1C17CMVtR277vPU5cvXa0frq1tmJQ7fBiP8HnWTQGx6biqITj16Ww 9PdT56aeuIvFnrLI9gLyA+g+z1FrVcl6aTLVUGDiSOqQv6jdR6CF3RNKi7TbPE0wX/LX XAEmSwWg0ARi8bpdk9h8i8E22czCmH2MMclgj2pTeE0CAIgyhFOni7PxzTphWXsUj0DF O4w9Ab4l4NchhrrpBYfHpuZDIaoXCSF0RBHn0nWNq5BGqKD7HY4Lfm8Yao46jA2E9Iw0 tF4A== X-Forwarded-Encrypted: i=1; AL+hErFYkXgW9M/QKPVsfxuf+LCs1eRLsYBziS9SwPcWJbAZl+Ezez0QZQjq4ocHLbfKeo6MgFc99y9hy7VoX/Q=@vger.kernel.org X-Gm-Message-State: AB4q+uEaCGOY3GLYZm7FnQm+PYWGKA1lt3HwJwJNLvsPtQQ5oVQNNVYM 5fCUcsDuHXwrG4/WpIKRudccbO5coXSLZ/9am/RYkQ4d1XmFck4h3Obs X-Gm-Gg: AZFdTZd73uQTGnZubrZkSTKIl1Q2InZsO+SkAQESTrog0M5Ed7ehUiX3IA+yWd7vwGs 9XCaAVebaOAglouRdGTMDc+O2M87rKC0/1fHjs+CT6KFZJKo/c/CfhHfNlpSGymOKcQavDDtn50 ihXxMtaPgUp2ejRYGZixekB+pjAO2Wn+U6T9r2PZJQnk9Qw1nlfCo0F8lU52NBPP4g4q8d5mDa/ ICv2oZ1nijXo9ypcpJsVC3tCr2A13G58UU0FUGXopRDitWeD4bWijD/gO6Sp3/6Ap1Ii+VI3TAh 0Ax7qIP1Xr8G6vXOFG+rsE+aBFSXlWTLAkuMG6wQPvvMAvyO3KpWc2KGP4CZO6Rmo1Eg70qjkxz +Q8Ysq72xO7/CNbjPSW4GbhNMJ/GIzHz0zGiczR3VGXzOg2YjrQKw7n+z+GIN1cPy3DWecamp/s J3y0lT/gS3VaFA5eiDxd5y6YVhPVaG/eGWFkyzqri0V+eWj26fvBQBtepD8CkxAzd+tCYpTUvxb b7W7lnjzqdIdQ1UFyhmmmcsoRG8DYk5AEsdnyw7bgIYh3oskiWpYelo9F0qKE7eWW4AQJaHBkY7 qXRemyz3CtgiSlp5HYlRGiCXNR0PHha4OyjHli4FOICbCzuuldlFmVhTUyyR+ndZcQ== X-Received: by 2002:a05:693c:880a:b0:385:5b47:8aad with SMTP id 5a478bee46e88-3875219f3f9mr1885892eec.19.1796392295122; Fri, 04 Dec 2026 05:51:35 -0800 (PST) Received: from 6610b1a2ef46 ([203.116.140.24]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875222ff7fsm8972759eec.25.2026.12.04.05.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 05:51:34 -0800 (PST) From: Hang Zhengyang To: Waiman Long , Ridong Chen , Tejun Heo Cc: Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Shuah Khan , Christian Brauner , Matthew Ruffell , Caron Wills , cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH cgroup/for-7.4-fixes 1/2] cgroup/cpuset: Don't migrate the parent's memory on CLONE_INTO_CGROUP Date: Fri, 4 Dec 2026 13:51:25 +0000 Message-ID: <20261204135126.598380-2-hang.zhengyang1010@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204135126.598380-1-hang.zhengyang1010@gmail.com> References: <20261204135126.598380-1-hang.zhengyang1010@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Since commit 65e510cd30d0 ("cgroup/cpuset: Move mpol_rebind_mm/cpuset_migrate_mm() calls inside cpuset_attach_task()"), cpuset_fork() rebinds and migrates the mm of a child created with CLONE_INTO_CGROUP in a cpuset with other mems. The child has not run yet, so its pages are still shared with the parent, which stays in its own cpuset. With CLONE_VM, the mm is the parent's. posix_spawn() with a cgroup attribute, which systemd uses to start services, passes CLONE_VM | CLONE_VFORK | CLONE_INTO_CGROUP. With the parent in mems 0 and the child in mems 1, a region the parent bound to node 0 with mbind() goes in /proc/self/numa_maps from bind:0 anon=4096 dirty=4096 active=0 N0=4096 to bind:1 anon=4096 dirty=4096 active=0 N1=4096 Don't migrate the mm in cpuset_fork(): its pages can't move without the parent's, and commit 42a11bf5c543 ("cgroup/cpuset: Make cpuset_fork() handle CLONE_INTO_CGROUP properly") already noted that the memory use of a new task isn't known. Drop the flush of the migration, and rebind the mm only if the child doesn't share it. Fixes: 65e510cd30d0 ("cgroup/cpuset: Move mpol_rebind_mm/cpuset_migrate_mm() calls inside cpuset_attach_task()") Cc: stable@vger.kernel.org # v7.3+ Signed-off-by: Hang Zhengyang --- kernel/cgroup/cpuset.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index aa82080dd1fa..420d519b11ae 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -364,6 +364,7 @@ static struct { bool mems_updated; bool task_work_queued; bool many_dest_cs; /* Have many destination cpusets */ + bool in_fork; /* Called from cpuset_fork() */ struct cpuset *old_cs; /* Source cpuset */ nodemask_t nodemask_to; } attach_ctx; @@ -3350,6 +3351,22 @@ static void cpuset_attach_task(struct cpuset *cs, struct task_struct *task) if ((task != task->group_leader) || !attach_ctx.mems_updated) return; + /* + * A child created with CLONE_INTO_CGROUP hasn't run yet: its pages are + * still shared with the parent (current), which stays in its cpuset. + * Don't migrate them, and with CLONE_VM, don't rebind the parent's mm. + */ + if (attach_ctx.in_fork) { + if (task->mm != current->mm) { + mm = get_task_mm(task); + if (mm) { + mpol_rebind_mm(mm, &cs->effective_mems); + mmput(mm); + } + } + return; + } + /* * Change mm for threadgroup leader. This is expensive and may * sleep and should be moved outside migration path proper. @@ -3877,11 +3894,9 @@ static void cpuset_fork(struct task_struct *task) * and so there shouldn't be a competing cpuset_attach() operation. */ attach_ctx.cpus_updated = attach_ctx.mems_updated = true; - attach_ctx.task_work_queued = false; - attach_ctx.old_cs = oldcs; + attach_ctx.in_fork = true; cpuset_attach_task(cs, task); - if (attach_ctx.task_work_queued) - schedule_flush_migrate_mm(); + attach_ctx.in_fork = false; dec_attach_in_progress_locked(); mutex_unlock(&cpuset_mutex); -- 2.53.0