From nobody Fri Jun 12 13:55:56 2026 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 364B231F986 for ; Thu, 14 May 2026 17:03:22 +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=1778778203; cv=none; b=uO+pmbdEJ+FKEXqj3wOgb08sCrEj3LH6gO4tyBTzrYEGIi0pNtDgbddflUY7GdiKft66aRdUmCTfO8AO+i1AlTc6+1HEK8ix1FoyKzI4LyJRluJy1CFUenf86OnYRQmAkcKSR4Wlr+k2mj8U8wZX06DjcG17VMuQanSgxDco7fQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778778203; c=relaxed/simple; bh=iKoFddTMDlVHV4CXsvi7sFe225ba9qRiv/Yem/1K3g0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fl6nNHDTVwXRt+U7sCPdj2022F7PG3xyJrDP7dnCa3DdIgyTMqH+jmJjtkpdtdTrLzNsZxgc6+WiTbzN7VbtXGMo6m8s7fdv8ITN7vQ+zxFOeNtkf08a/7NFVvRZjdRh0QlnHVXH/rPjLNFzIUPKWYuJZL3rEG9WxzSxM1g9az8= 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=CZ+Z1jf/; 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="CZ+Z1jf/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778778201; 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=X5qv11FgV5fy/6EX+8T25xoRvDD1FKxp0C5IFRIAwRw=; b=CZ+Z1jf/4rSvCzkKbfz98M3ZN1/85g4RlM0n8tJiDYLziMGX6KbkHRxPFw+zGk5IsB/m// 8OYoOL80vVMMorGFhuEn9hBeJFgm9/NAsNtEaPE+lA4TvZvJ47d7/r//6yAKhSs5tgWSU2 qcTpalETPFTmLxcUTMxfg2Llneklym8= Received: from mx-prod-mc-06.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-610-3OmNstXvN1m3sRrU8EZYlQ-1; Thu, 14 May 2026 13:03:16 -0400 X-MC-Unique: 3OmNstXvN1m3sRrU8EZYlQ-1 X-Mimecast-MFC-AGG-ID: 3OmNstXvN1m3sRrU8EZYlQ_1778778194 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0F2DA1800626; Thu, 14 May 2026 17:03:14 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.2.16.73]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 47AD530002DA; Thu, 14 May 2026 17:03:10 +0000 (UTC) From: Waiman Long To: Chen Ridong , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Dietmar Eggemann , Aaron Tomlin , Juri Lelli , Waiman Long Subject: [PATCH cgroup/for-next 1/4] cgroup/cpuset: Add an alloc_dl_bw() helper Date: Thu, 14 May 2026 13:02:37 -0400 Message-ID: <20260514170240.575156-2-longman@redhat.com> In-Reply-To: <20260514170240.575156-1-longman@redhat.com> References: <20260514170240.575156-1-longman@redhat.com> 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 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Extract the DL bandwidth allocation code in cpuset_attach() to a new alloc_dl_bw() helper to simplify code. No functional change is expected. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 50 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index bcefc9f50ac5..9de3c907436f 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2980,6 +2980,25 @@ static int cpuset_can_attach_check(struct cpuset *cs) return 0; } =20 +static int alloc_dl_bw(struct cpuset *cs) +{ + int cpu, ret; + + if (!cs->sum_migrate_dl_bw) + return 0; + + cpu =3D cpumask_any_and(cpu_active_mask, cs->effective_cpus); + if (unlikely(cpu >=3D nr_cpu_ids)) + return -EINVAL; + + ret =3D dl_bw_alloc(cpu, cs->sum_migrate_dl_bw); + if (ret) + return ret; + + cs->dl_bw_cpu =3D cpu; + return 0; +} + static void reset_migrate_dl_data(struct cpuset *cs) { cs->nr_migrate_dl_tasks =3D 0; @@ -2994,7 +3013,7 @@ static int cpuset_can_attach(struct cgroup_taskset *t= set) struct cpuset *cs, *oldcs; struct task_struct *task; bool setsched_check; - int cpu, ret; + int ret; =20 /* used later by cpuset_attach() */ cpuset_attach_old_cs =3D task_cs(cgroup_taskset_first(tset, &css)); @@ -3050,31 +3069,18 @@ static int cpuset_can_attach(struct cgroup_taskset = *tset) } } =20 - if (!cs->sum_migrate_dl_bw) - goto out_success; - - cpu =3D cpumask_any_and(cpu_active_mask, cs->effective_cpus); - if (unlikely(cpu >=3D nr_cpu_ids)) { - ret =3D -EINVAL; - goto out_unlock; - } - - ret =3D dl_bw_alloc(cpu, cs->sum_migrate_dl_bw); - if (ret) - goto out_unlock; - - cs->dl_bw_cpu =3D cpu; - -out_success: - /* - * Mark attach is in progress. This makes validate_change() fail - * changes which zero cpus/mems_allowed. - */ - cs->attach_in_progress++; + ret =3D alloc_dl_bw(cs); =20 out_unlock: if (ret) reset_migrate_dl_data(cs); + else + /* + * Mark attach is in progress. This makes validate_change() fail + * changes which zero cpus/mems_allowed. + */ + cs->attach_in_progress++; + mutex_unlock(&cpuset_mutex); return ret; } --=20 2.54.0 From nobody Fri Jun 12 13:55:56 2026 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 DA4D4386C30 for ; Thu, 14 May 2026 17:03:23 +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=1778778205; cv=none; b=mONIB9uN5Qhwb70A2xUobL5TLkN1ln3q3dCiu6RX1p0cOjzfPc+gan6AM/qZ/rNBMJY1MG5za5CXxcXiits8R/7qPFOYLCYxrQVhFuWGF3+b7wPLaFLYqFciq0Ibph80eKiort1LlqDqATYRWDvOn9yti88eEAKCpyDLipS8KRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778778205; c=relaxed/simple; bh=pYjUD22+aWQilVYJfFcAADyBmIDGS4OKvDVmoamoZ6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MmZUFjBkntAfOGTL5qR1f5JnWoKyDnWMHNlEpOgxw5aOgIg7vHCz/pDiNQ/yUTU8XomBb2AHlQkiymMeODeutTJT/JnOHZeBDZurNneabWtRnbjaxaeEp9f+TZi2snE2hwJrgTteAOBfPidSxVgxRDQgBbtszi5zGCL5ktrdiJw= 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=TxN04WVk; 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="TxN04WVk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778778202; 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=Quk631IVTLhhlacI05pnzuPc48gNliQ5Sn1YUb7VsWc=; b=TxN04WVkj8dafRs+FjJ1xMOxeKUMWfRRmBjOtSYuMXGQNPp4vXsSC322GInQ7jHOOywpxk S4//NP71Z7gC3PjS1ArL318+6mf1LsudPLSG2LdxsIRJIhvKpMoYalchJ5tHVizxRgPT9Z srXDSZKksnfa8pMfXVbotzxKsPABuDc= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680--KosFqCZPk2ycu5uzgzJ5A-1; Thu, 14 May 2026 13:03:19 -0400 X-MC-Unique: -KosFqCZPk2ycu5uzgzJ5A-1 X-Mimecast-MFC-AGG-ID: -KosFqCZPk2ycu5uzgzJ5A_1778778198 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8DEA11956080; Thu, 14 May 2026 17:03:17 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.2.16.73]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8661130002DC; Thu, 14 May 2026 17:03:14 +0000 (UTC) From: Waiman Long To: Chen Ridong , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Dietmar Eggemann , Aaron Tomlin , Juri Lelli , Waiman Long Subject: [PATCH cgroup/for-next 2/4] cgroup/cpuset: Expand the scope of cpuset_can_attach_check() Date: Thu, 14 May 2026 13:02:38 -0400 Message-ID: <20260514170240.575156-3-longman@redhat.com> In-Reply-To: <20260514170240.575156-1-longman@redhat.com> References: <20260514170240.575156-1-longman@redhat.com> 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 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Expand the scope of cpuset_can_attach_check() by including the setting of setsched flag inside cpuset_can_attach_check() with the new @oldcs and @psetsched argument. As cpuset_can_attach_check() is also called from cpuset_can_fork(), set the new arguments to NULL from that caller. While at it, expose the source and destination cpuset cpu/memory check results in the new attach_cpus_updated and attach_mems_updated static flags so that these flags can be used directly from cpuset_attach() without the need to do the same computations again. No functional change is expected. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 69 +++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 9de3c907436f..68392cf6429b 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2964,19 +2964,55 @@ static int update_prstate(struct cpuset *cs, int ne= w_prs) return 0; } =20 +/* + * cpuset_can_attach() and cpuset_attach() specific internal data + */ static struct cpuset *cpuset_attach_old_cs; +static bool attach_cpus_updated; +static bool attach_mems_updated; =20 /* * Check to see if a cpuset can accept a new task * For v1, cpus_allowed and mems_allowed can't be empty. * For v2, effective_cpus can't be empty. * Note that in v1, effective_cpus =3D cpus_allowed. + * + * Also set the boolean flag passed in by @psetsched depending on if + * security_task_setscheduler() call is needed and @oldcs is not NULL. */ -static int cpuset_can_attach_check(struct cpuset *cs) +static int cpuset_can_attach_check(struct cpuset *cs, struct cpuset *oldcs, + bool *psetsched) { if (cpumask_empty(cs->effective_cpus) || (!is_in_v2_mode() && nodes_empty(cs->mems_allowed))) return -ENOSPC; + + if (!oldcs) + return 0; + + /* + * Update attach specific data + */ + attach_cpus_updated =3D !cpumask_equal(cs->effective_cpus, oldcs->effecti= ve_cpus); + attach_mems_updated =3D !nodes_equal(cs->effective_mems, oldcs->effective= _mems); + + /* + * Skip rights over task setsched check in v2 when nothing changes, + * migration permission derives from hierarchy ownership in + * cgroup_procs_write_permission()). + */ + *psetsched =3D !cpuset_v2() || attach_cpus_updated || attach_mems_updated; + + /* + * A v1 cpuset with tasks will have no CPU left only when CPU hotplug + * brings the last online CPU offline as users are not allowed to empty + * cpuset.cpus when there are active tasks inside. When that happens, + * we should allow tasks to migrate out without security check to make + * sure they will be able to run after migration. + */ + if (!is_in_v2_mode() && cpumask_empty(oldcs->effective_cpus)) + *psetsched =3D false; + return 0; } =20 @@ -3023,29 +3059,10 @@ static int cpuset_can_attach(struct cgroup_taskset = *tset) mutex_lock(&cpuset_mutex); =20 /* Check to see if task is allowed in the cpuset */ - ret =3D cpuset_can_attach_check(cs); + ret =3D cpuset_can_attach_check(cs, oldcs, &setsched_check); if (ret) goto out_unlock; =20 - /* - * Skip rights over task setsched check in v2 when nothing changes, - * migration permission derives from hierarchy ownership in - * cgroup_procs_write_permission()). - */ - setsched_check =3D !cpuset_v2() || - !cpumask_equal(cs->effective_cpus, oldcs->effective_cpus) || - !nodes_equal(cs->effective_mems, oldcs->effective_mems); - - /* - * A v1 cpuset with tasks will have no CPU left only when CPU hotplug - * brings the last online CPU offline as users are not allowed to empty - * cpuset.cpus when there are active tasks inside. When that happens, - * we should allow tasks to migrate out without security check to make - * sure they will be able to run after migration. - */ - if (!is_in_v2_mode() && cpumask_empty(oldcs->effective_cpus)) - setsched_check =3D false; - cgroup_taskset_for_each(task, css, tset) { ret =3D task_can_attach(task); if (ret) @@ -3139,7 +3156,6 @@ static void cpuset_attach(struct cgroup_taskset *tset) struct cgroup_subsys_state *css; struct cpuset *cs; struct cpuset *oldcs =3D cpuset_attach_old_cs; - bool cpus_updated, mems_updated; bool queue_task_work =3D false; =20 cgroup_taskset_first(tset, &css); @@ -3147,9 +3163,6 @@ static void cpuset_attach(struct cgroup_taskset *tset) =20 lockdep_assert_cpus_held(); /* see cgroup_attach_lock() */ mutex_lock(&cpuset_mutex); - cpus_updated =3D !cpumask_equal(cs->effective_cpus, - oldcs->effective_cpus); - mems_updated =3D !nodes_equal(cs->effective_mems, oldcs->effective_mems); =20 /* * In the default hierarchy, enabling cpuset in the child cgroups @@ -3157,7 +3170,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) * in effective cpus and mems. In that case, we can optimize out * by skipping the task iteration and update. */ - if (cpuset_v2() && !cpus_updated && !mems_updated) { + if (cpuset_v2() && !attach_cpus_updated && !attach_mems_updated) { cpuset_attach_nodemask_to =3D cs->effective_mems; goto out; } @@ -3174,7 +3187,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) * not set. */ cpuset_attach_nodemask_to =3D cs->effective_mems; - if (!is_memory_migrate(cs) && !mems_updated) + if (!is_memory_migrate(cs) && !attach_mems_updated) goto out; =20 cgroup_taskset_for_each_leader(leader, css, tset) { @@ -3589,7 +3602,7 @@ static int cpuset_can_fork(struct task_struct *task, = struct css_set *cset) mutex_lock(&cpuset_mutex); =20 /* Check to see if task is allowed in the cpuset */ - ret =3D cpuset_can_attach_check(cs); + ret =3D cpuset_can_attach_check(cs, NULL, NULL); if (ret) goto out_unlock; =20 --=20 2.54.0 From nobody Fri Jun 12 13:55:56 2026 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 8160A3890E0 for ; Thu, 14 May 2026 17:03:28 +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=1778778209; cv=none; b=EyWQsbk6CDOq0kjeJzxHhfdPzEQWghNo3Fbpwl6Omtu5HQItQivkFu3xL6PjbF2Lm049sMPMmOQE4fg4tAAbVwOrQjZYir0uwYoWRL+jA03oIJZFX4DeVOtz/jXujSbvnBtSgblzy/OD849GTVNpYGEBejA7RDABvizBwI6wYPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778778209; c=relaxed/simple; bh=2CPgVrj0NT1gX38aqCa21xvtd73b37MX8+ApDO92tlg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DUaOGdBvQQ4OvKicxUYtQcxwsdKe0F801dOhR4S9dni3Xi15kgKZR5Q0sw4P6NJVsFwpk2SrGQ6CZkrroZunzrACgO5pVV+W2gq5pR9WrTw4AlsHxgHO3uSsV28jljjC6fcoUpeI83KHCBXT6VV89q/X39iJSejOW1cuMqFe2jM= 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=XTsFhpar; 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="XTsFhpar" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778778207; 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=CqVFB9YopdZw9qu89CsUJQEJgWpqo6bFaKJu6uJdmm0=; b=XTsFhparH89rs7UwGWrSYxRFShII+juo/WJ/qTU6IEeWrxkp0VMIAZZM+uqZOhQsl+p2MA axKiK3p4KtNs8vD/DxJUNuj8plytDRt48hHpby7q45HBI3AGqGzlY0k1qFVQpKF9ufyync sHGl3D/14o1//gSzH9jNEu3sb0nSeFs= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-16-fVFei_UKOyunT454G7CQhw-1; Thu, 14 May 2026 13:03:22 -0400 X-MC-Unique: fVFei_UKOyunT454G7CQhw-1 X-Mimecast-MFC-AGG-ID: fVFei_UKOyunT454G7CQhw_1778778200 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 663E2195608E; Thu, 14 May 2026 17:03:20 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.2.16.73]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF7E730002DA; Thu, 14 May 2026 17:03:17 +0000 (UTC) From: Waiman Long To: Chen Ridong , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Dietmar Eggemann , Aaron Tomlin , Juri Lelli , Waiman Long Subject: [PATCH cgroup/for-next 3/4] cgroup/cpuset: Optimize cpuset_attach_task() Date: Thu, 14 May 2026 13:02:39 -0400 Message-ID: <20260514170240.575156-4-longman@redhat.com> In-Reply-To: <20260514170240.575156-1-longman@redhat.com> References: <20260514170240.575156-1-longman@redhat.com> 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 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Within cpuset_attach(), cpuset_attach_task() is called only if either the CPU and/or the memory setting are updated. If only one of the settings is updated, cpuset_attach_task() still updates both CPU and memory node setting of each task. Further optimize it by checking attach_cpus_updated and attach_mems_updated for v2 to skip the unnecessary update. While at it, also move the mpol_rebind_mm() call for mm group leader to cpuset_attach_task(). This change shouldn't affect the cpuset_fork() caller as the newly cloned task isn't the group leader. For that caller, it is assumed that both CPU and memory nodes are updated to keep the existing behavior. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 68392cf6429b..8ced1fa0900f 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -3132,8 +3132,13 @@ static nodemask_t cpuset_attach_nodemask_to; =20 static void cpuset_attach_task(struct cpuset *cs, struct task_struct *task) { + struct mm_struct *mm; + lockdep_assert_cpuset_lock_held(); =20 + if (cpuset_v2() && !attach_cpus_updated) + goto update_mem; + if (cs !=3D &top_cpuset) guarantee_active_cpus(task, cpus_attach); else @@ -3145,8 +3150,21 @@ static void cpuset_attach_task(struct cpuset *cs, st= ruct task_struct *task) */ WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpus_attach)); =20 +update_mem: + if (cpuset_v2() && !attach_mems_updated) + return; + cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to); cpuset1_update_task_spread_flags(cs, task); + + if (task !=3D task->group_leader) + return; + + mm =3D get_task_mm(task); + if (mm) { + mpol_rebind_mm(mm, &cs->effective_mems); + mmput(mm); + } } =20 static void cpuset_attach(struct cgroup_taskset *tset) @@ -3187,15 +3205,13 @@ static void cpuset_attach(struct cgroup_taskset *ts= et) * not set. */ cpuset_attach_nodemask_to =3D cs->effective_mems; - if (!is_memory_migrate(cs) && !attach_mems_updated) + if (!is_memory_migrate(cs)) goto out; =20 cgroup_taskset_for_each_leader(leader, css, tset) { struct mm_struct *mm =3D get_task_mm(leader); =20 if (mm) { - mpol_rebind_mm(mm, &cpuset_attach_nodemask_to); - /* * old_mems_allowed is the same with mems_allowed * here, except if this task is being moved @@ -3204,18 +3220,15 @@ static void cpuset_attach(struct cgroup_taskset *ts= et) * @old_mems_allowed is the right nodesets that we * migrate mm from. */ - if (is_memory_migrate(cs)) { - cpuset_migrate_mm(mm, &oldcs->old_mems_allowed, - &cpuset_attach_nodemask_to); - queue_task_work =3D true; - } else - mmput(mm); + cpuset_migrate_mm(mm, &oldcs->old_mems_allowed, + &cpuset_attach_nodemask_to); + queue_task_work =3D true; } } =20 -out: if (queue_task_work) schedule_flush_migrate_mm(); +out: cs->old_mems_allowed =3D cpuset_attach_nodemask_to; =20 if (cs->nr_migrate_dl_tasks) { @@ -3666,7 +3679,10 @@ static void cpuset_fork(struct task_struct *task) /* CLONE_INTO_CGROUP */ mutex_lock(&cpuset_mutex); guarantee_online_mems(cs, &cpuset_attach_nodemask_to); + /* Assume CPUs and memory nodes are updated */ + attach_cpus_updated =3D attach_mems_updated =3D true; cpuset_attach_task(cs, task); + attach_cpus_updated =3D attach_mems_updated =3D false; =20 dec_attach_in_progress_locked(cs); mutex_unlock(&cpuset_mutex); --=20 2.54.0 From nobody Fri Jun 12 13:55:56 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 04DF238AC68 for ; Thu, 14 May 2026 17:03:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778778215; cv=none; b=tS/hgy/zBCJZ0tfRDCVIIA179w7Y/JFadS0viH0o6JKRl9Lm5qdL2LOhRyhLkzDRAXry2WkopfWr3Sey0b732rit68sT8z32+rf43FtZuhGsCDkZRMI/OUGxsCJqy2VX/6eWO5496ac2ljt2s8GSzzehxBWZCqm4iqIM3keCYtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778778215; c=relaxed/simple; bh=iRNqhYmZ1TMr6hzbVQ9eWe0Eh120laNQC3FyJd2jJuo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fgydubtwyzTdkkgVd7fEDUwyB3nfoz2UdjdKxzY47SDfQEKquhUfekcXlTVa5o4N1/YdrRffn0DGbS9VM0kgegpectThKQHXTrREUlULT/GSCtCaqPne3OxdS7A6UiM//Kp9/oYQNlQG+zgs9+6V95cGRcNc/FQWfWpiEhivMPs= 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=CjmV7bHu; arc=none smtp.client-ip=170.10.129.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="CjmV7bHu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778778211; 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=jjJNzrFjKmrD4V4JJnVcoPFpev53VCvIaz6cbH8bCgA=; b=CjmV7bHuOs5d/M5uiqvheC25Q0ZnA4RFzqD9tF/qzEfqjr79keqYRFQOXWsPRvZarFTFV1 QW18Xq9p0tMLF1Bdj0u/XwB7KE0AtT1m5GXxaDvA0NL790ns0DE+1+Wv2fHBN2noi7U+/5 7O+CQX+J8HGl/5LuWZ1yD9zLq2nPNgU= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-103-skuhS_ZGPCGIhxpzuiGB5w-1; Thu, 14 May 2026 13:03:25 -0400 X-MC-Unique: skuhS_ZGPCGIhxpzuiGB5w-1 X-Mimecast-MFC-AGG-ID: skuhS_ZGPCGIhxpzuiGB5w_1778778204 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AD46319560B7; Thu, 14 May 2026 17:03:23 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.2.16.73]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C315C30001A2; Thu, 14 May 2026 17:03:20 +0000 (UTC) From: Waiman Long To: Chen Ridong , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Dietmar Eggemann , Aaron Tomlin , Juri Lelli , Waiman Long Subject: [PATCH cgroup/for-next 4/4] cgroup/cpuset: Support multiple source/destination cpusets for cpuset_*attach() Date: Thu, 14 May 2026 13:02:40 -0400 Message-ID: <20260514170240.575156-5-longman@redhat.com> In-Reply-To: <20260514170240.575156-1-longman@redhat.com> References: <20260514170240.575156-1-longman@redhat.com> 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 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" With cgroup v2, the cgroup_taskset structure passed into the cgroup can_attach() and attach() methods can contain task migration data with multiple destination or source cpusets when the cpuset controller is enabled or disabled respectively. Since cpuset is threaded, another possible way to cause many-to-one migration is to move the whole process with multiple threads in different cpuset enabled threaded cgroups into another cpuset enabled cgroup. Alternatively, multiple processs from different cpusets can be written into cgroup.proc as a single operation. The current cpuset_can_attach() and cpuset_attach() functions still expect task migration is from one source cpuset to one destination cpuset. This has been the case since cpuset was enabled for cgroup v2 in commit 4ec22e9c5a90 ("cpuset: Enable cpuset controller in default hierarchy"). This problem is less an issue when enabling the cpuset controller as all the newly created child cpusets will have exactly the same set of CPUs and memory nodes except when deadline tasks are involved in migration as the deadline task accounting data can be off. It can be more problematic when the cpuset controller is disabled as their set of CPUs and memory nodes may differ from their parent or with the moving of multi-threaded process from different threaded cgroups. Fix that by tracking the set of source (old) and destination cpusets in singly linked lists and iterating them all to properly update the internal data. Also keep the current cs and oldcs variables up-to-date with the css and task iterators. cpuset_attach_old_cs is now dropped as the old cpusets are now being tracked. To ensure proper DL tasks accounting, the nr_migrate_dl_tasks in both the source and destination cpusets are decremented/incremented with their values added to nr_deadline_tasks when the migration is successful. Fixes: 4ec22e9c5a90 ("cpuset: Enable cpuset controller in default hierarchy= ") Signed-off-by: Waiman Long --- kernel/cgroup/cpuset-internal.h | 6 + kernel/cgroup/cpuset.c | 206 +++++++++++++++++++++++--------- 2 files changed, 158 insertions(+), 54 deletions(-) diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-interna= l.h index f7aaf01f7cd5..4c2772a7fd5e 100644 --- a/kernel/cgroup/cpuset-internal.h +++ b/kernel/cgroup/cpuset-internal.h @@ -161,6 +161,12 @@ struct cpuset { */ bool remote_partition; =20 + /* + * cpuset_can_attach() and cpuset_attach() specific data + */ + bool attach_node_in_llist; + struct llist_node attach_node; + /* * number of SCHED_DEADLINE tasks attached to this cpuset, so that we * know when to rebuild associated root domain bandwidth information. diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 8ced1fa0900f..c46454b29d74 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -37,6 +37,7 @@ #include #include #include +#include =20 DEFINE_STATIC_KEY_FALSE(cpusets_pre_enable_key); DEFINE_STATIC_KEY_FALSE(cpusets_enabled_key); @@ -2967,7 +2968,8 @@ static int update_prstate(struct cpuset *cs, int new_= prs) /* * cpuset_can_attach() and cpuset_attach() specific internal data */ -static struct cpuset *cpuset_attach_old_cs; +static LLIST_HEAD(src_cs_head); +static LLIST_HEAD(dst_cs_head); static bool attach_cpus_updated; static bool attach_mems_updated; =20 @@ -2980,9 +2982,10 @@ static bool attach_mems_updated; * Also set the boolean flag passed in by @psetsched depending on if * security_task_setscheduler() call is needed and @oldcs is not NULL. */ -static int cpuset_can_attach_check(struct cpuset *cs, struct cpuset *oldcs, - bool *psetsched) +static int cpuset_can_attach_check(struct cpuset *cs, struct cpuset *oldcs= , bool *psetsched) { + bool cpu_match, mem_match; + if (cpumask_empty(cs->effective_cpus) || (!is_in_v2_mode() && nodes_empty(cs->mems_allowed))) return -ENOSPC; @@ -2993,15 +2996,34 @@ static int cpuset_can_attach_check(struct cpuset *c= s, struct cpuset *oldcs, /* * Update attach specific data */ - attach_cpus_updated =3D !cpumask_equal(cs->effective_cpus, oldcs->effecti= ve_cpus); - attach_mems_updated =3D !nodes_equal(cs->effective_mems, oldcs->effective= _mems); + if (!cs->attach_node_in_llist) { + llist_add(&cs->attach_node, &dst_cs_head); + cs->attach_node_in_llist =3D true; + } + if (!oldcs->attach_node_in_llist) { + llist_add(&oldcs->attach_node, &src_cs_head); + oldcs->attach_node_in_llist =3D true; + } + + cpu_match =3D cpumask_equal(cs->effective_cpus, oldcs->effective_cpus); + mem_match =3D nodes_equal(cs->effective_mems, oldcs->effective_mems); + + /* + * Set the updated flags whenever there is a mismatch in any of the + * src/dst pairs. + */ + if (!attach_cpus_updated) + attach_cpus_updated =3D !cpu_match; + + if (!attach_mems_updated) + attach_mems_updated =3D !mem_match; =20 /* * Skip rights over task setsched check in v2 when nothing changes, * migration permission derives from hierarchy ownership in * cgroup_procs_write_permission()). */ - *psetsched =3D !cpuset_v2() || attach_cpus_updated || attach_mems_updated; + *psetsched =3D !cpuset_v2() || !cpu_match || !mem_match; =20 /* * A v1 cpuset with tasks will have no CPU left only when CPU hotplug @@ -3016,33 +3038,105 @@ static int cpuset_can_attach_check(struct cpuset *= cs, struct cpuset *oldcs, return 0; } =20 -static int alloc_dl_bw(struct cpuset *cs) +/* + * If reset_dl_bw is set, reset the previous dl_bw_alloc() call. Otherwise, + * update nr_deadline_tasks according to nr_migrate_dl_tasks in both source + * and destination cpusets. + */ +static void clear_attach_data(bool reset_dl_bw) +{ + struct cpuset *cs, *next; + + llist_for_each_entry_safe(cs, next, src_cs_head.first, attach_node) { + cs->attach_node.next =3D NULL; + cs->attach_node_in_llist =3D false; + if (cs->nr_migrate_dl_tasks && !reset_dl_bw) + cs->nr_deadline_tasks +=3D cs->nr_migrate_dl_tasks; + cs->nr_migrate_dl_tasks =3D 0; + } + + llist_for_each_entry_safe(cs, next, dst_cs_head.first, attach_node) { + cs->attach_node.next =3D NULL; + cs->attach_node_in_llist =3D false; + if (reset_dl_bw && cs->dl_bw_cpu >=3D 0) + dl_bw_free(cs->dl_bw_cpu, cs->sum_migrate_dl_bw); + if (cs->nr_migrate_dl_tasks && !reset_dl_bw) + cs->nr_deadline_tasks +=3D cs->nr_migrate_dl_tasks; + cs->nr_migrate_dl_tasks =3D 0; + cs->sum_migrate_dl_bw =3D 0; + cs->dl_bw_cpu =3D -1; + } + + src_cs_head.first =3D NULL; + dst_cs_head.first =3D NULL; + attach_cpus_updated =3D false; + attach_mems_updated =3D false; +} + +static int alloc_dl_bw(void) { + struct cpuset *cs; int cpu, ret; =20 - if (!cs->sum_migrate_dl_bw) - return 0; + llist_for_each_entry(cs, dst_cs_head.first, attach_node) { + if (!cs->sum_migrate_dl_bw) + continue; =20 - cpu =3D cpumask_any_and(cpu_active_mask, cs->effective_cpus); - if (unlikely(cpu >=3D nr_cpu_ids)) - return -EINVAL; + cpu =3D cpumask_any_and(cpu_active_mask, cs->effective_cpus); + if (unlikely(cpu >=3D nr_cpu_ids)) + return -EINVAL; =20 - ret =3D dl_bw_alloc(cpu, cs->sum_migrate_dl_bw); - if (ret) - return ret; + ret =3D dl_bw_alloc(cpu, cs->sum_migrate_dl_bw); + if (ret) + return ret; =20 - cs->dl_bw_cpu =3D cpu; + cs->dl_bw_cpu =3D cpu; + } return 0; } =20 -static void reset_migrate_dl_data(struct cpuset *cs) +static void set_attach_in_progress(void) { - cs->nr_migrate_dl_tasks =3D 0; - cs->sum_migrate_dl_bw =3D 0; - cs->dl_bw_cpu =3D -1; + struct cpuset *cs; + + /* + * Mark attach is in progress. This makes validate_change() fail + * changes which zero cpus/mems_allowed. + */ + llist_for_each_entry(cs, dst_cs_head.first, attach_node) + cs->attach_in_progress++; } =20 -/* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held= */ +static void reset_attach_in_progress(void) +{ + struct cpuset *cs; + + llist_for_each_entry(cs, dst_cs_head.first, attach_node) + dec_attach_in_progress_locked(cs); +} + +/* + * Called by cgroups to determine if a cpuset is usable; cpuset_mutex held. + * + * With cgroup v2, enabling of cpuset controller in a cgroup subtree can + * cause @tset to contain task migration data from one parent cpuset to mu= ltiple + * child cpusets. Not much is needed to be done here other than tracking t= he + * number of DL tasks in each cpuset as the CPUs and memory nodes of the c= hild + * cpusets are exactly the same as the parent. + * + * Conversely, disabling of cpuset controller can cause @tset to contain t= ask + * migration data from multiple child cpusets to one parent cpuset. Here, = the + * CPUs and memory nodes of the child cpusets may be different from the pa= rent, + * but must be a subset of its parent. + * + * Another possible many-to-one migration is the moving of the whole + * multithreaded process with threads in different cpusets to another cpus= et. + * Alternatively, multiple processes from multiple cpusets can be moved to + * another cpuset in a single operation. + * + * For all other use cases including cgroup v1, @tset task migration data + * should be from one source cpuset to one destination cpuset. + */ static int cpuset_can_attach(struct cgroup_taskset *tset) { struct cgroup_subsys_state *css; @@ -3052,8 +3146,7 @@ static int cpuset_can_attach(struct cgroup_taskset *t= set) int ret; =20 /* used later by cpuset_attach() */ - cpuset_attach_old_cs =3D task_cs(cgroup_taskset_first(tset, &css)); - oldcs =3D cpuset_attach_old_cs; + oldcs =3D task_cs(cgroup_taskset_first(tset, &css)); cs =3D css_cs(css); =20 mutex_lock(&cpuset_mutex); @@ -3064,6 +3157,16 @@ static int cpuset_can_attach(struct cgroup_taskset *= tset) goto out_unlock; =20 cgroup_taskset_for_each(task, css, tset) { + struct cpuset *newcs =3D css_cs(css); + struct cpuset *new_oldcs =3D task_cs(task); + + if ((newcs !=3D cs) || (new_oldcs !=3D oldcs)) { + cs =3D newcs; + oldcs =3D new_oldcs; + ret =3D cpuset_can_attach_check(cs, oldcs, &setsched_check); + if (ret) + goto out_unlock; + } ret =3D task_can_attach(task); if (ret) goto out_unlock; @@ -3081,23 +3184,18 @@ static int cpuset_can_attach(struct cgroup_taskset = *tset) * contribute to sum_migrate_dl_bw. */ cs->nr_migrate_dl_tasks++; + oldcs->nr_migrate_dl_tasks--; if (dl_task_needs_bw_move(task, cs->effective_cpus)) cs->sum_migrate_dl_bw +=3D task->dl.dl_bw; } } =20 - ret =3D alloc_dl_bw(cs); - + ret =3D alloc_dl_bw(); out_unlock: if (ret) - reset_migrate_dl_data(cs); + clear_attach_data(true); else - /* - * Mark attach is in progress. This makes validate_change() fail - * changes which zero cpus/mems_allowed. - */ - cs->attach_in_progress++; - + set_attach_in_progress(); mutex_unlock(&cpuset_mutex); return ret; } @@ -3111,14 +3209,8 @@ static void cpuset_cancel_attach(struct cgroup_tasks= et *tset) cs =3D css_cs(css); =20 mutex_lock(&cpuset_mutex); - dec_attach_in_progress_locked(cs); - - if (cs->dl_bw_cpu >=3D 0) - dl_bw_free(cs->dl_bw_cpu, cs->sum_migrate_dl_bw); - - if (cs->nr_migrate_dl_tasks) - reset_migrate_dl_data(cs); - + reset_attach_in_progress(); + clear_attach_data(true); mutex_unlock(&cpuset_mutex); } =20 @@ -3172,8 +3264,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) struct task_struct *task; struct task_struct *leader; struct cgroup_subsys_state *css; - struct cpuset *cs; - struct cpuset *oldcs =3D cpuset_attach_old_cs; + struct cpuset *cs, *oldcs; bool queue_task_work =3D false; =20 cgroup_taskset_first(tset, &css); @@ -3184,9 +3275,9 @@ static void cpuset_attach(struct cgroup_taskset *tset) =20 /* * In the default hierarchy, enabling cpuset in the child cgroups - * will trigger a number of cpuset_attach() calls with no change - * in effective cpus and mems. In that case, we can optimize out - * by skipping the task iteration and update. + * will trigger a cpuset_attach() call with no change in effective cpus + * and mems. In that case, we can optimize out by skipping the task + * iteration and update. */ if (cpuset_v2() && !attach_cpus_updated && !attach_mems_updated) { cpuset_attach_nodemask_to =3D cs->effective_mems; @@ -3195,8 +3286,16 @@ static void cpuset_attach(struct cgroup_taskset *tse= t) =20 guarantee_online_mems(cs, &cpuset_attach_nodemask_to); =20 - cgroup_taskset_for_each(task, css, tset) + cgroup_taskset_for_each(task, css, tset) { + struct cpuset *newcs =3D css_cs(css); + + if (newcs !=3D cs) { + cs->old_mems_allowed =3D cs->effective_mems; + cs =3D newcs; + guarantee_online_mems(cs, &cpuset_attach_nodemask_to); + } cpuset_attach_task(cs, task); + } =20 /* * Change mm for all threadgroup leaders. This is expensive and may @@ -3208,6 +3307,11 @@ static void cpuset_attach(struct cgroup_taskset *tse= t) if (!is_memory_migrate(cs)) goto out; =20 + /* + * Only v1 supports memory_migrate and there should only be one source + * and one destination cpuset. + */ + oldcs =3D llist_entry(src_cs_head.first, struct cpuset, attach_node); cgroup_taskset_for_each_leader(leader, css, tset) { struct mm_struct *mm =3D get_task_mm(leader); =20 @@ -3231,14 +3335,8 @@ static void cpuset_attach(struct cgroup_taskset *tse= t) out: cs->old_mems_allowed =3D cpuset_attach_nodemask_to; =20 - if (cs->nr_migrate_dl_tasks) { - cs->nr_deadline_tasks +=3D cs->nr_migrate_dl_tasks; - oldcs->nr_deadline_tasks -=3D cs->nr_migrate_dl_tasks; - reset_migrate_dl_data(cs); - } - - dec_attach_in_progress_locked(cs); - + reset_attach_in_progress(); + clear_attach_data(false); mutex_unlock(&cpuset_mutex); } =20 --=20 2.54.0