From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 BB9021A0BD0 for ; Tue, 30 Jun 2026 03:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782790489; cv=none; b=A/93M/sL1L3T93vDqzPmWqQdscG3yIBNFQKtL4r8KFk1UOnkQDttqJXe9Hm7doNdnwpKcS7i30wrYxvxavH3Kwk8hgCR+xv63ND23rDZ0O3jbxKOwrW3rXzDFF5+3EgaF3k6K1yashXJCswuITnjLGtV8t1lN6uF3XG6Pv7poYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782790489; c=relaxed/simple; bh=WFhFw1Tu8rtC/tJEggn/ZnBPijNTVrajKNoSLRKUOCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RF8jIAU9685uTEIeSpRgRujZW1MsyHheCiJgsWmnO+Q+5c1JtE3oAr0jPsGZmJPd9H+16v8d5zkSPR9NvnBkGeQqiSBcGxkidaAD2Z9uNGcEeWePjUJHdV/4Y8nxeXkOzAhEvoEhWTk68yocYKsx6BKRSCAe+nWoFg+L3pk7fbc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HzGfJtrq; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HzGfJtrq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782790483; 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=B7RaO0h70WxACu28gPk17LlgtBHA1d9TjBjrqk5TGaw=; b=HzGfJtrqcykci2I4gXC76EZ9Jmjipn5/TFnHGdtGL7U9CTzjkeuz1+oyhQ12aqgu9AeXyZ HV8ORWXrwp2kWYB5iBo/ko75nMVCzvc+hFt7kfY7Q4xYk7bzUMMhJj2D+qAcc2YR3K26va xrG86JuAxEICIToQFR8xTkG7v1kU79Q= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-nN_xDGIVPT6MfV51oiNg4Q-1; Mon, 29 Jun 2026 23:34:41 -0400 X-MC-Unique: nN_xDGIVPT6MfV51oiNg4Q-1 X-Mimecast-MFC-AGG-ID: nN_xDGIVPT6MfV51oiNg4Q_1782790480 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EF632180AC4C; Tue, 30 Jun 2026 03:34:39 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.2.16.200]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A0246195608D; Tue, 30 Jun 2026 03:34:35 +0000 (UTC) From: Waiman Long To: Ridong Chen , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Shuah Khan , Juri Lelli Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Aaron Tomlin , Guopeng Zhang , Waiman Long Subject: [PATCH-next v9 07/11] cgroup/cpuset: Make attach_ctx.old_cs track task group leader Date: Mon, 29 Jun 2026 23:33:40 -0400 Message-ID: <20260630033344.352702-8-longman@redhat.com> In-Reply-To: <20260630033344.352702-1-longman@redhat.com> References: <20260630033344.352702-1-longman@redhat.com> Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 There are two possible ways that migration of tasks from multiple source cpusets to a target cpuset can happen. Either a multithread application with threads in different cpusets is wholely migrated to a new cpuset or disabling of v2 cpuset controller will move all the tasks in child cpusets to the parent cpuset. In the former case, it is the mm setting of the group leader that really matters. So attach_ctx.old_cs should track the oldcs of the thread leader. In the latter case, effective_mems of child cpusets must always be a subset of the parent. So no real page migration will not be necessary no matter which child cpuset is selected as attach_ctx.old_cs. IOW, attach_ctx.old_cs should be updated to match the latest task group leader in cpuset_can_attach(), but fall back to that of the first task if there is no group leader in the taskset. Suggested-by: Ridong Chen Signed-off-by: Waiman Long Reviewed-by: Ridong Chen --- kernel/cgroup/cpuset.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 4a3e2972884c..55cd580373b7 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -3105,11 +3105,32 @@ static int cpuset_can_attach(struct cgroup_taskset *tset) if (ret) goto out_unlock; + /* + * The attach_ctx.old_cs is used mainly by cpuset_migrate_mm() to get + * the old_mems_allowed value. There are two ways that many-to-one + * cpuset migration can happen: + * 1) A multithread application with threads in different cpusets is + * wholely migrated to a new cpuset. + * 2) Disabling v2 cpuset controller will move all the tasks in child + * cpusets to the parent cpuset. + * + * In the former case, it is the mm setting of the group leader that + * really matters. So attach_ctx.old_cs should track the oldcs of the + * group leader. It falls back to the oldcs of the first task if there + * is no group leader in the taskset. In the latter case, effective_mems + * of child cpusets must always be a subset of the parent. So no real + * page migration will be necessary no matter which child cpuset is + * selected as attach_ctx.old_cs. + */ cgroup_taskset_for_each(task, css, tset) { ret = task_can_attach(task); if (ret) goto out_unlock; + /* Update attach_ctx.old_cs to the latest group leader */ + if (task == task->group_leader) + attach_ctx.old_cs = task_cs(task); + if (setsched_check) { ret = security_task_setscheduler(task); if (ret) -- 2.54.0