Skip to contentSkip to conversation

cgroup/cpuset: Make cpuset hotplug processing synchronous

PATCH Applied Waiman Long 3 participants 5 messages Apr 4, 2024 – Apr 8, 2024

Subsystems (6)
lore
Share & tools
lore

Waiman Long

author maintainer
#0 lore raw

v2 cover cgroup/cpuset: Make cpuset hotplug processing synchronous

v2:
- Found that rebuild_sched_domains() has external callers, revert its change and introduce rebuild_sched_domains_cpuslocked() instead.

As discussed in the LKML thread [1], the asynchronous nature of cpuset hotplug handling code is causing problem with RCU testing. With recent changes in the way locking is being handled in the cpuset code, it is now possible to make the cpuset hotplug code synchronous again without major changes.

This series enables the hotplug code to call directly into cpuset hotplug core without indirection with the exception of the special case of v1 cpuset becoming empty still being handled indirectly with workqueue.

A new simple test case was also written to test this special v1 cpuset case. The test_cpuset_prs.sh script was also run with LOCKDEP on to verify that there is no regression.

[1] https://lore.kernel.org/lkml/[email protected]/

Waiman Long (2):
cgroup/cpuset: Make cpuset hotplug processing synchronous cgroup/cpuset: Add test_cpuset_v1_hp.sh

 include/linux/cpuset.h                        |   3 -
 kernel/cgroup/cpuset.c                        | 141 +++++++-----------
 kernel/cpu.c                                  |  48 ------
 kernel/power/process.c                        |   2 -
 tools/testing/selftests/cgroup/Makefile       |   2 +-
 .../selftests/cgroup/test_cpuset_v1_hp.sh     |  46 ++++++
 6 files changed, 103 insertions(+), 139 deletions(-)
 create mode 100755 tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh
Signature · 1 line
2.39.3
author maintainer
#1 lore raw

PATCH v2 1/2 cgroup/cpuset: Make cpuset hotplug processing synchronous

Since commit 3a5a6d0c2b03("cpuset: don't nest cgroup_mutex inside get_online_cpus()"), cpuset hotplug was done asynchronously via a work function. This is to avoid recursive locking of cgroup_mutex.

Since then, the cgroup locking scheme has changed quite a bit. A cpuset_mutex was introduced to protect cpuset specific operations. The cpuset_mutex is then replaced by a cpuset_rwsem. With commit d74b27d63a8b ("cgroup/cpuset: Change cpuset_rwsem and hotplug lock order"), cpu_hotplug_lock is acquired before cpuset_rwsem. Later on, cpuset_rwsem is reverted back to cpuset_mutex. All these locking changes allow the hotplug code to call into cpuset core directly.

The following commits were also merged due to the asynchronous nature of cpuset hotplug processing.

- commit b22afcdf04c9 ("cpu/hotplug: Cure the cpusets trainwreck")
- commit 50e76632339d ("sched/cpuset/pm: Fix cpuset vs. suspend-resume

    bugs")

- commit 28b89b9e6f7b ("cpuset: handle race between CPU hotplug and cpuset_hotplug_work")

Clean up all these bandages by making cpuset hotplug processing synchronous again with the exception that the call to cgroup_transfer_tasks() to transfer tasks out of an empty cgroup v1 cpuset, if necessary, will still be done via a work function due to the existing cgroup_mutex -> cpu_hotplug_lock dependency. It is possible to reverse that dependency, but that will require updating a number of different cgroup controllers. This special hotplug code path should be rarely taken anyway.

As all the cpuset states will be updated by the end of the hotplug operation, we can revert most the above commits except commit 50e76632339d ("sched/cpuset/pm: Fix cpuset vs. suspend-resume bugs") which is partially reverted. Also removing some cpus_read_lock trylock attempts in the cpuset partition code as they are no longer necessary since the cpu_hotplug_lock is now held for the whole duration of the cpuset hotplug code path.

---
 include/linux/cpuset.h |   3 -
 kernel/cgroup/cpuset.c | 141 ++++++++++++++++-------------------------
 kernel/cpu.c           |  48 --------------
 kernel/power/process.c |   2 -
 4 files changed, 56 insertions(+), 138 deletions(-)
include/linux/cpuset.h +0 -3
index 0ce6ff0d9c9a..de4cf0ee96f7 100644
@@ -70,7 +70,6 @@ extern int cpuset_init(void);
 extern void cpuset_init_smp(void);
 extern void cpuset_force_rebuild(void);
 extern void cpuset_update_active_cpus(void);
-extern void cpuset_wait_for_hotplug(void);
 extern void inc_dl_tasks_cs(struct task_struct *task);
 extern void dec_dl_tasks_cs(struct task_struct *task);
 extern void cpuset_lock(void);
@@ -185,8 +184,6 @@ static inline void cpuset_update_active_cpus(void)
 	partition_sched_domains(1, NULL, NULL);
 }
 
-static inline void cpuset_wait_for_hotplug(void) { }
-
 static inline void inc_dl_tasks_cs(struct task_struct *task) { }
 static inline void dec_dl_tasks_cs(struct task_struct *task) { }
 static inline void cpuset_lock(void) { }
kernel/cgroup/cpuset.c +56 -85

271 lines not on this page · raw message

kernel/cpu.c +0 -48

66 lines not on this page · raw message

kernel/power/process.c +0 -2
index cae81a87cc91..66ac067d9ae6 100644
@@ -194,8 +194,6 @@ void thaw_processes(void)
 	__usermodehelper_set_disable_depth(UMH_FREEZING);
 	thaw_workqueues();
 
-	cpuset_wait_for_hotplug();
-
 	read_lock(&tasklist_lock);
 	for_each_process_thread(g, p) {
 		/* No other threads should have PF_SUSPEND_TASK set */
Signature · 1 line
2.39.3
Tested-by on v2 1/2
#2 lore raw
Quoted 38 lines · Waiman Long

Since commit 3a5a6d0c2b03("cpuset: don't nest cgroup_mutex inside get_online_cpus()"), cpuset hotplug was done asynchronously via a work function. This is to avoid recursive locking of cgroup_mutex.

Since then, the cgroup locking scheme has changed quite a bit. A cpuset_mutex was introduced to protect cpuset specific operations. The cpuset_mutex is then replaced by a cpuset_rwsem. With commit d74b27d63a8b ("cgroup/cpuset: Change cpuset_rwsem and hotplug lock order"), cpu_hotplug_lock is acquired before cpuset_rwsem. Later on, cpuset_rwsem is reverted back to cpuset_mutex. All these locking changes allow the hotplug code to call into cpuset core directly.

The following commits were also merged due to the asynchronous nature of cpuset hotplug processing.

- commit b22afcdf04c9 ("cpu/hotplug: Cure the cpusets trainwreck")
- commit 50e76632339d ("sched/cpuset/pm: Fix cpuset vs. suspend-resume

    bugs")

- commit 28b89b9e6f7b ("cpuset: handle race between CPU hotplug and cpuset_hotplug_work")

Clean up all these bandages by making cpuset hotplug processing synchronous again with the exception that the call to cgroup_transfer_tasks() to transfer tasks out of an empty cgroup v1 cpuset, if necessary, will still be done via a work function due to the existing cgroup_mutex -> cpu_hotplug_lock dependency. It is possible to reverse that dependency, but that will require updating a number of different cgroup controllers. This special hotplug code path should be rarely taken anyway.

As all the cpuset states will be updated by the end of the hotplug operation, we can revert most the above commits except commit 50e76632339d ("sched/cpuset/pm: Fix cpuset vs. suspend-resume bugs") which is partially reverted. Also removing some cpus_read_lock trylock attempts in the cpuset partition code as they are no longer necessary since the cpu_hotplug_lock is now held for the whole duration of the cpuset hotplug code path.

Quoted 1 line
author maintainer
#3 lore raw

PATCH v2 2/2 cgroup/cpuset: Add test_cpuset_v1_hp.sh

In reply to Waiman Long

Add a simple test to verify that an empty v1 cpuset will force its tasks to be moved to an ancestor node. It is based on the test case documented in commit 76bb5ab8f6e3 ("cpuset: break kernfs active protection in cpuset_write_resmask()").

---
 tools/testing/selftests/cgroup/Makefile       |  2 +-
 .../selftests/cgroup/test_cpuset_v1_hp.sh     | 46 +++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh
tools/testing/selftests/cgroup/Makefile +1 -1
index 00b441928909..16461dc0ffdf 100644
@@ -4,7 +4,7 @@ CFLAGS += -Wall -pthread
 all: ${HELPER_PROGS}
 
 TEST_FILES     := with_stress.sh
-TEST_PROGS     := test_stress.sh test_cpuset_prs.sh
+TEST_PROGS     := test_stress.sh test_cpuset_prs.sh test_cpuset_v1_hp.sh
 TEST_GEN_FILES := wait_inotify
 TEST_GEN_PROGS = test_memcontrol
 TEST_GEN_PROGS += test_kmem
tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.39.3
maintainer Applied
#4 lore raw
In reply to Waiman Long
Quoted 10 lines · Waiman Long

v2:
- Found that rebuild_sched_domains() has external callers, revert its change and introduce rebuild_sched_domains_cpuslocked() instead.

As discussed in the LKML thread [1], the asynchronous nature of cpuset hotplug handling code is causing problem with RCU testing. With recent changes in the way locking is being handled in the cpuset code, it is now possible to make the cpuset hotplug code synchronous again without major changes.

Quoted 7 lines

This series enables the hotplug code to call directly into cpuset hotplug core without indirection with the exception of the special case of v1 cpuset becoming empty still being handled indirectly with workqueue.

A new simple test case was also written to test this special v1 cpuset case. The test_cpuset_prs.sh script was also run with LOCKDEP on to verify that there is no regression.

Applied to cgroup/for-6.10. Hopefully, this one will work out. Thanks for working on this.

Signature · 1 line
tejun