[PATCH 05/11] cpuset: inherite ancestor's masks if real_{cpus,mems}_allowedbecome empty

From: Li Zefan
Date: Wed Aug 21 2013 - 06:00:04 EST


We're going to have separate user-configured masks and effective ones.

At last configured masks can only be changed by writing cpuset.cpus
and cpuset.mems, and they won't be restricted by parent cpuset. While
effective masks reflect cpu/memory hotplug and hierachical restriction.

This is a preparation to make real_{cpus,mems}_allowed to be effective
masks of the cpuset:

- change the effective masks at hotplug: done
- change the effective masks at config change: done
- take on ancestor's mask when the effective mask is empty: done

This won't introduce behavior change.

Signed-off-by: Li Zefan <lizefan@xxxxxxxxxx>
---
kernel/cpuset.c | 33 +++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 72afef4..b7b63dd 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -904,12 +904,14 @@ static void update_cpumasks_hier(struct cpuset *cs, struct cpuset *trialcs,
parent->real_cpus_allowed);

/*
- * Skip the whole subtree if the cpumask is not changed, unless
- * it's empty, and in this case we need to update tasks to take
- * on an ancestor's cpumask.
+ * If it becomes empty, inherite the effective mask of the
+ * parent, which is guarantted to have some CPUs.
*/
- if (cpumask_equal(new_cpus, cp->real_cpus_allowed) &&
- ((cp == cs) || !cpumask_empty(new_cpus))) {
+ if (cpumask_empty(new_cpus))
+ cpumask_copy(new_cpus, parent->real_cpus_allowed);
+
+ /* Skip the whole subtree if the cpumask is not changed. */
+ if (cpumask_equal(new_cpus, cp->real_cpus_allowed)) {
pos_css = css_rightmost_descendant(pos_css);
continue;
}
@@ -1168,12 +1170,14 @@ static void update_nodemasks_hier(struct cpuset *cs, struct cpuset *trialcs,
parent->real_mems_allowed);

/*
- * Skip the whole subtree if the nodemask is not changed, unless
- * it's empty, and in this case we need to update tasks to take
- * on an ancestor's nodemask.
+ * If it becoms empty, inherite the effective mask of the
+ * parent, which is guaranteed to have some MEMs.
*/
- if (nodes_equal(*new_mems, cp->real_mems_allowed) &&
- ((cp == cs) || !nodes_empty(*new_mems))) {
+ if (nodes_empty(*new_mems))
+ *new_mems = parent->real_mems_allowed;
+
+ /* Skip the whole subtree if the nodemask is not changed. */
+ if (nodes_equal(*new_mems, cp->real_mems_allowed)) {
pos_css = css_rightmost_descendant(pos_css);
continue;
}
@@ -2202,8 +2206,13 @@ retry:

mutex_lock(&callback_mutex);
cpumask_andnot(cs->cpus_allowed, cs->cpus_allowed, &off_cpus);
+
cpumask_andnot(cs->real_cpus_allowed, cs->real_cpus_allowed,
&off_cpus);
+ /* Inherite the effective mask of the parent, if it becomes empty */
+ if (cpumask_empty(cs->real_cpus_allowed))
+ cpumask_copy(cs->real_cpus_allowed,
+ parent_cs(cs)->real_cpus_allowed);
mutex_unlock(&callback_mutex);

/*
@@ -2218,7 +2227,11 @@ retry:

mutex_lock(&callback_mutex);
nodes_andnot(cs->mems_allowed, cs->mems_allowed, off_mems);
+
nodes_andnot(cs->real_mems_allowed, cs->real_mems_allowed, off_mems);
+ /* Inherite the effective mask of the parent, if it becomes empty */
+ if (nodes_empty(cs->real_mems_allowed))
+ cs->real_mems_allowed = parent_cs(cs)->real_mems_allowed;
mutex_unlock(&callback_mutex);

/*
--
1.8.0.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/