Skip to content

Commit 7e88291

Browse files
lizf-oshtejun
authored andcommitted
cpuset: make cs->{cpus, mems}_allowed as user-configured masks
Now we've used effective cpumasks to enforce hierarchical manner, we can use cs->{cpus,mems}_allowed as configured masks. Configured masks can be changed by writing cpuset.cpus and cpuset.mems only. The new behaviors are: - They won't be changed by hotplug anymore. - They won't be limited by its parent's masks. This ia a behavior change, but won't take effect unless mount with sane_behavior. v2: - Add comments to explain the differences between configured masks and effective masks. Signed-off-by: Li Zefan <lizefan@huawei.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent ae1c802 commit 7e88291

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

‎kernel/cpuset.c‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ struct cpuset {
7777

7878
unsigned long flags; /* "unsigned long" so bitops work */
7979

80+
/*
81+
* On default hierarchy:
82+
*
83+
* The user-configured masks can only be changed by writing to
84+
* cpuset.cpus and cpuset.mems, and won't be limited by the
85+
* parent masks.
86+
*
87+
* The effective masks is the real masks that apply to the tasks
88+
* in the cpuset. They may be changed if the configured masks are
89+
* changed or hotplug happens.
90+
*
91+
* effective_mask == configured_mask & parent's effective_mask,
92+
* and if it ends up empty, it will inherit the parent's mask.
93+
*
94+
*
95+
* On legacy hierachy:
96+
*
97+
* The user-configured masks are always the same with effective masks.
98+
*/
99+
80100
/* user-configured CPUs and Memory Nodes allow to tasks */
81101
cpumask_var_t cpus_allowed;
82102
nodemask_t mems_allowed;
@@ -450,9 +470,9 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial)
450470

451471
par = parent_cs(cur);
452472

453-
/* We must be a subset of our parent cpuset */
473+
/* On legacy hiearchy, we must be a subset of our parent cpuset. */
454474
ret = -EACCES;
455-
if (!is_cpuset_subset(trial, par))
475+
if (!cgroup_on_dfl(cur->css.cgroup) && !is_cpuset_subset(trial, par))
456476
goto out;
457477

458478
/*
@@ -2167,20 +2187,22 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
21672187
static cpumask_t new_cpus;
21682188
static nodemask_t new_mems;
21692189
bool cpus_updated, mems_updated;
2190+
bool on_dfl = cgroup_on_dfl(top_cpuset.css.cgroup);
21702191

21712192
mutex_lock(&cpuset_mutex);
21722193

21732194
/* fetch the available cpus/mems and find out which changed how */
21742195
cpumask_copy(&new_cpus, cpu_active_mask);
21752196
new_mems = node_states[N_MEMORY];
21762197

2177-
cpus_updated = !cpumask_equal(top_cpuset.cpus_allowed, &new_cpus);
2178-
mems_updated = !nodes_equal(top_cpuset.mems_allowed, new_mems);
2198+
cpus_updated = !cpumask_equal(top_cpuset.effective_cpus, &new_cpus);
2199+
mems_updated = !nodes_equal(top_cpuset.effective_mems, new_mems);
21792200

21802201
/* synchronize cpus_allowed to cpu_active_mask */
21812202
if (cpus_updated) {
21822203
mutex_lock(&callback_mutex);
2183-
cpumask_copy(top_cpuset.cpus_allowed, &new_cpus);
2204+
if (!on_dfl)
2205+
cpumask_copy(top_cpuset.cpus_allowed, &new_cpus);
21842206
cpumask_copy(top_cpuset.effective_cpus, &new_cpus);
21852207
mutex_unlock(&callback_mutex);
21862208
/* we don't mess with cpumasks of tasks in top_cpuset */
@@ -2189,7 +2211,8 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
21892211
/* synchronize mems_allowed to N_MEMORY */
21902212
if (mems_updated) {
21912213
mutex_lock(&callback_mutex);
2192-
top_cpuset.mems_allowed = new_mems;
2214+
if (!on_dfl)
2215+
top_cpuset.mems_allowed = new_mems;
21932216
top_cpuset.effective_mems = new_mems;
21942217
mutex_unlock(&callback_mutex);
21952218
update_tasks_nodemask(&top_cpuset);

0 commit comments

Comments
 (0)