Skip to content

Commit 2685027

Browse files
Waiman-Longhtejun
authored andcommitted
cgroup/cpuset: Remove cpus_allowed/mems_allowed setup in cpuset_init_smp()
There are 3 places where the cpu and node masks of the top cpuset can be initialized in the order they are executed: 1) start_kernel -> cpuset_init() 2) start_kernel -> cgroup_init() -> cpuset_bind() 3) kernel_init_freeable() -> do_basic_setup() -> cpuset_init_smp() The first cpuset_init() call just sets all the bits in the masks. The second cpuset_bind() call sets cpus_allowed and mems_allowed to the default v2 values. The third cpuset_init_smp() call sets them back to v1 values. For systems with cgroup v2 setup, cpuset_bind() is called once. As a result, cpu and memory node hot add may fail to update the cpu and node masks of the top cpuset to include the newly added cpu or node in a cgroup v2 environment. For systems with cgroup v1 setup, cpuset_bind() is called again by rebind_subsystem() when the v1 cpuset filesystem is mounted as shown in the dmesg log below with an instrumented kernel. [ 2.609781] cpuset_bind() called - v2 = 1 [ 3.079473] cpuset_init_smp() called [ 7.103710] cpuset_bind() called - v2 = 0 smp_init() is called after the first two init functions. So we don't have a complete list of active cpus and memory nodes until later in cpuset_init_smp() which is the right time to set up effective_cpus and effective_mems. To fix this cgroup v2 mask setup problem, the potentially incorrect cpus_allowed & mems_allowed setting in cpuset_init_smp() are removed. For cgroup v2 systems, the initial cpuset_bind() call will set the masks correctly. For cgroup v1 systems, the second call to cpuset_bind() will do the right setup. cc: [email protected] Signed-off-by: Waiman Long <[email protected]> Tested-by: Feng Tang <[email protected]> Reviewed-by: Michal Koutný <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent a7391ad commit 2685027

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kernel/cgroup/cpuset.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3390,8 +3390,11 @@ static struct notifier_block cpuset_track_online_nodes_nb = {
33903390
*/
33913391
void __init cpuset_init_smp(void)
33923392
{
3393-
cpumask_copy(top_cpuset.cpus_allowed, cpu_active_mask);
3394-
top_cpuset.mems_allowed = node_states[N_MEMORY];
3393+
/*
3394+
* cpus_allowd/mems_allowed set to v2 values in the initial
3395+
* cpuset_bind() call will be reset to v1 values in another
3396+
* cpuset_bind() call when v1 cpuset is mounted.
3397+
*/
33953398
top_cpuset.old_mems_allowed = top_cpuset.mems_allowed;
33963399

33973400
cpumask_copy(top_cpuset.effective_cpus, cpu_active_mask);

0 commit comments

Comments
 (0)