Skip to content

Commit ff0ce72

Browse files
Waiman-Longhtejun
authored andcommitted
cgroup/cpuset: Eliminate unncessary sched domains rebuilds in hotplug
It was found that some hotplug operations may cause multiple rebuild_sched_domains_locked() calls. Some of those intermediate calls may use cpuset states not in the final correct form leading to incorrect sched domain setting. Fix this problem by using the existing force_rebuild flag to inhibit immediate rebuild_sched_domains_locked() calls if set and only doing one final call at the end. Also renaming the force_rebuild flag to force_sd_rebuild to make its meaning for clear. Signed-off-by: Waiman Long <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 311a1bd commit ff0ce72

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

kernel/cgroup/cpuset.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ static cpumask_var_t isolated_cpus;
232232
/* List of remote partition root children */
233233
static struct list_head remote_children;
234234

235+
/*
236+
* A flag to force sched domain rebuild at the end of an operation while
237+
* inhibiting it in the intermediate stages when set. Currently it is only
238+
* set in hotplug code.
239+
*/
240+
static bool force_sd_rebuild;
241+
235242
/*
236243
* Partition root states:
237244
*
@@ -1475,7 +1482,7 @@ static void update_partition_sd_lb(struct cpuset *cs, int old_prs)
14751482
clear_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
14761483
}
14771484

1478-
if (rebuild_domains)
1485+
if (rebuild_domains && !force_sd_rebuild)
14791486
rebuild_sched_domains_locked();
14801487
}
14811488

@@ -1833,7 +1840,7 @@ static void remote_partition_check(struct cpuset *cs, struct cpumask *newmask,
18331840
remote_partition_disable(child, tmp);
18341841
disable_cnt++;
18351842
}
1836-
if (disable_cnt)
1843+
if (disable_cnt && !force_sd_rebuild)
18371844
rebuild_sched_domains_locked();
18381845
}
18391846

@@ -2442,7 +2449,8 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
24422449
}
24432450
rcu_read_unlock();
24442451

2445-
if (need_rebuild_sched_domains && !(flags & HIER_NO_SD_REBUILD))
2452+
if (need_rebuild_sched_domains && !(flags & HIER_NO_SD_REBUILD) &&
2453+
!force_sd_rebuild)
24462454
rebuild_sched_domains_locked();
24472455
}
24482456

@@ -3104,7 +3112,8 @@ static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
31043112
cs->flags = trialcs->flags;
31053113
spin_unlock_irq(&callback_lock);
31063114

3107-
if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed)
3115+
if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed &&
3116+
!force_sd_rebuild)
31083117
rebuild_sched_domains_locked();
31093118

31103119
if (spread_flag_changed)
@@ -4501,11 +4510,9 @@ hotplug_update_tasks(struct cpuset *cs,
45014510
update_tasks_nodemask(cs);
45024511
}
45034512

4504-
static bool force_rebuild;
4505-
45064513
void cpuset_force_rebuild(void)
45074514
{
4508-
force_rebuild = true;
4515+
force_sd_rebuild = true;
45094516
}
45104517

45114518
/**
@@ -4653,15 +4660,9 @@ static void cpuset_handle_hotplug(void)
46534660
!cpumask_empty(subpartitions_cpus);
46544661
mems_updated = !nodes_equal(top_cpuset.effective_mems, new_mems);
46554662

4656-
/*
4657-
* In the rare case that hotplug removes all the cpus in
4658-
* subpartitions_cpus, we assumed that cpus are updated.
4659-
*/
4660-
if (!cpus_updated && !cpumask_empty(subpartitions_cpus))
4661-
cpus_updated = true;
4662-
46634663
/* For v1, synchronize cpus_allowed to cpu_active_mask */
46644664
if (cpus_updated) {
4665+
cpuset_force_rebuild();
46654666
spin_lock_irq(&callback_lock);
46664667
if (!on_dfl)
46674668
cpumask_copy(top_cpuset.cpus_allowed, &new_cpus);
@@ -4717,8 +4718,8 @@ static void cpuset_handle_hotplug(void)
47174718
}
47184719

47194720
/* rebuild sched domains if cpus_allowed has changed */
4720-
if (cpus_updated || force_rebuild) {
4721-
force_rebuild = false;
4721+
if (force_sd_rebuild) {
4722+
force_sd_rebuild = false;
47224723
rebuild_sched_domains_cpuslocked();
47234724
}
47244725

0 commit comments

Comments
 (0)