Skip to content

Commit f18f982

Browse files
Izabela48Ingo Molnar
authored andcommitted
sched: CPU hotplug events must not destroy scheduler domains created by the cpusets
First issue is not related to the cpusets. We're simply leaking doms_cur. It's allocated in arch_init_sched_domains() which is called for every hotplug event. So we just keep reallocation doms_cur without freeing it. I introduced free_sched_domains() function that cleans things up. Second issue is that sched domains created by the cpusets are completely destroyed by the CPU hotplug events. For all CPU hotplug events scheduler attaches all CPUs to the NULL domain and then puts them all into the single domain thereby destroying domains created by the cpusets (partition_sched_domains). The solution is simple, when cpusets are enabled scheduler should not create default domain and instead let cpusets do that. Which is exactly what the patch does. Signed-off-by: Max Krasnyansky <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Acked-by: Peter Zijlstra <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 15a8641 commit f18f982

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

kernel/cpuset.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,12 @@ static void common_cpu_mem_hotplug_unplug(void)
18901890
top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY];
18911891
scan_for_empty_cpusets(&top_cpuset);
18921892

1893+
/*
1894+
* Scheduler destroys domains on hotplug events.
1895+
* Rebuild them based on the current settings.
1896+
*/
1897+
rebuild_sched_domains();
1898+
18931899
cgroup_unlock();
18941900
}
18951901

kernel/sched.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7237,6 +7237,18 @@ void __attribute__((weak)) arch_update_cpu_topology(void)
72377237
{
72387238
}
72397239

7240+
/*
7241+
* Free current domain masks.
7242+
* Called after all cpus are attached to NULL domain.
7243+
*/
7244+
static void free_sched_domains(void)
7245+
{
7246+
ndoms_cur = 0;
7247+
if (doms_cur != &fallback_doms)
7248+
kfree(doms_cur);
7249+
doms_cur = &fallback_doms;
7250+
}
7251+
72407252
/*
72417253
* Set up scheduler domains and groups. Callers must hold the hotplug lock.
72427254
* For now this just excludes isolated cpus, but could be used to
@@ -7384,6 +7396,7 @@ int arch_reinit_sched_domains(void)
73847396
get_online_cpus();
73857397
mutex_lock(&sched_domains_mutex);
73867398
detach_destroy_domains(&cpu_online_map);
7399+
free_sched_domains();
73877400
err = arch_init_sched_domains(&cpu_online_map);
73887401
mutex_unlock(&sched_domains_mutex);
73897402
put_online_cpus();
@@ -7469,6 +7482,7 @@ static int update_sched_domains(struct notifier_block *nfb,
74697482
case CPU_DOWN_PREPARE:
74707483
case CPU_DOWN_PREPARE_FROZEN:
74717484
detach_destroy_domains(&cpu_online_map);
7485+
free_sched_domains();
74727486
return NOTIFY_OK;
74737487

74747488
case CPU_UP_CANCELED:
@@ -7487,8 +7501,16 @@ static int update_sched_domains(struct notifier_block *nfb,
74877501
return NOTIFY_DONE;
74887502
}
74897503

7504+
#ifndef CONFIG_CPUSETS
7505+
/*
7506+
* Create default domain partitioning if cpusets are disabled.
7507+
* Otherwise we let cpusets rebuild the domains based on the
7508+
* current setup.
7509+
*/
7510+
74907511
/* The hotplug lock is already held by cpu_up/cpu_down */
74917512
arch_init_sched_domains(&cpu_online_map);
7513+
#endif
74927514

74937515
return NOTIFY_OK;
74947516
}

0 commit comments

Comments
 (0)