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 AF1323AB27F for ; Tue, 26 May 2026 20:12:30 +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=1779826352; cv=none; b=l0u7ssscPM124L7fROngERhGWDIjXDv5gGDypsgIvni4dhu/I5sOeIZRasKdM9z52caegIgJltyDLKaZcwsh6xD0PLikfjoHKdywume3oxrARtZAcnlr1UsE6omE478/4xxjPWz+zfktnz8Y2O+khtDLlX7+Ys8laNgzSJxH5IU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779826352; c=relaxed/simple; bh=4e81GXMCcGndVPJJu7ECtZfZVevip/NPAO6z/B3uxoM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=g/lEZK7a6QWcKmqWzXIS9UeG9g1PmBaoG2+fv4TnEf0zcVelIC8ANU+UxIdFciUT/essFFN1W8M9hUIGOe3KMwHK+2N2cI03aWGe1sdWmbPwbToDOM9qyal3msmwCi4MwjaoK91P51KeCRLKwlGPdvQtu2Gk/8gTc4URGjzYeQU= 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=TMXsWava; 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="TMXsWava" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779826349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5s01YmjIIQDHxWKsNiaTqIGMIOhNUeVbzMefhqESZy0=; b=TMXsWava7b7LEs8QbK0o5j/xIuwlTOEjeCqDWIgI+IH1dqASoqprtG4WJvy7aXJBiPBW5t BhCHc5c3neK5N1L8pY5bwZoARI36yO+4aKRI265lgPtbgmEFDQvwka9S5S8tBwvIJaUc01 4T/eUwX7Auxjxu3UMPGgE3gk4rgcdc0= Received: from mx-prod-mc-03.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-302-YK3y_hDHNdSd6F0vLh831g-1; Tue, 26 May 2026 16:12:23 -0400 X-MC-Unique: YK3y_hDHNdSd6F0vLh831g-1 X-Mimecast-MFC-AGG-ID: YK3y_hDHNdSd6F0vLh831g_1779826340 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D68BA1956066; Tue, 26 May 2026 20:12:18 +0000 (UTC) Received: from [10.22.65.22] (unknown [10.22.65.22]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4A0AB19560A3; Tue, 26 May 2026 20:12:15 +0000 (UTC) Message-ID: Date: Tue, 26 May 2026 16:12:14 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH cgroup/for-next v2 0/5] cgroup/cpuset: Support multiple source/destination cpusets for cpuset_*attach() To: Ridong Chen , Chen Ridong , Tejun Heo , Johannes Weiner , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Aaron Tomlin References: <20260516042448.698216-1-longman@redhat.com> <3936b856-cf88-41a9-bb3f-4f48440e2692@linux.dev> Content-Language: en-US From: Waiman Long In-Reply-To: <3936b856-cf88-41a9-bb3f-4f48440e2692@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 On 5/20/26 4:29 AM, Ridong Chen wrote: > > > On 2026/5/16 12:24, Waiman Long wrote: >> Sashiko AI review of another cpuset patch had found that cpuset_attach() >> and cpuset_can_attach() can be passed a cgroup_taskset with tasks >> migrating from one source cpuset to multiple destination cpusets and >> vice versa.  Further testing of the cpuset code indicates that this is >> indeed the case when the v2 cpuset controller is enabled or disabled. >> >> Unfortunately, cpuset_attach() and cpuset_can_attach() still assume that >> there will be one source and one destinaton cpuset which may result in >> inocrrect behavior. >> > > Hi Longman, > > I am thinking whether we can use the pids subsystem's approach to > solve this issue, which I think could be much simpler. > > For the DL task accounting, we can handle it the same way > pids_can_attach() does - just call task_cs(task) for each task > individually inside the can_attach() loop and do the nr_deadline_tasks > adjustment right there. This eliminates the need to pass per-task > source cpuset information to the attach() callback entirely for DL > accounting purposes. DL task accounting doesn't use the new oldcs stored in the task structure which is only used for mm migration. BTW, I believe task_cs(task) doesn't return the old cs in cpuset_attach(). > > For cpuset_migrate_mm(), I don't think we need per-task oldcs storage > in task_struct either. The scenarios where multiple source cpusets are > involved are: > > enable cpuset controller: child cpusets inherit parent's > effective_mems, so attach_mems_updated is false and > cpuset_migrate_mm() is never called. > > disable cpuset controller: tasks move from children to parent. Since > children's effective_mems is always a subset of parent's > effective_mems, even if cpuset_migrate_mm() is triggered, it's > effectively a noop (no pages need to move from a subset to its superset). > > cgroup.procs write with threads in different cpusets: this is a > many-to-one migration with a single process, so there is only one > group_leader and one mm. We only need to record the leader's oldcs, > which a single static variable can handle. > > So in all cases, the migration path only needs one oldcs for the > leader. We don't need to add a field to task_struct. > > What do you think? Yes, that makes sense. I will rework the patch series. Thanks, Longman > > > >> This patch series is created to fix this issue. The first 2 patches are >> just preparatory patches to make the remaining patches easier to review. >> >> Patch 3 adds a new attach_old_cs field into task_struct to track the >> old cpuset to be used in case when cpuset_migrate_mm() needs to be >> called in cpuset_attach(). >> >> Patch 4 moves mpol_rebind_mm() and cpuset_migrate_mm() inside >> cpuset_attach_task() to make CLONE_INTO_CGROUP flag of clone(2) works >> more like moving task from one cpuset to another one, while also make >> supporting multiple source and destination cpusets easier. >> >> Patch 5 makes the necessary changes to enable the support of multiple >> source and destination cpusets by keeping all the source and destination >> cpusets found during task iterations in two singly linked lists for >> source and destination cpusets respectively. >> >> Waiman Long (5): >>    cgroup/cpuset: Add a cpuset_reserve_dl_bw() helper >>    cgroup/cpuset: Expand the scope of cpuset_can_attach_check() >>    cgroup/cpuset: Replace cpuset_attach_old_cs by a new attach_old_cs >>      field in task_struct >>    cgroup/cpuset: Move mpol_rebind_mm/cpuset_migrate_mm() calls inside >>      cpuset_attach_task() >>    cgroup/cpuset: Support multiple source/destination cpusets for >>      cpuset_*attach() >> >>   include/linux/sched.h           |   3 + >>   kernel/cgroup/cpuset-internal.h |   6 + >>   kernel/cgroup/cpuset.c          | 358 +++++++++++++++++++++----------- >>   3 files changed, 249 insertions(+), 118 deletions(-) >> >