public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpuset: allow empty cpu/node masks
@ 2011-04-19 10:07 Konstantin Khlebnikov
  2011-04-19 10:17 ` Paul Menage
  0 siblings, 1 reply; 5+ messages in thread
From: Konstantin Khlebnikov @ 2011-04-19 10:07 UTC (permalink / raw)
  To: Paul Menage; +Cc: linux-kernel

Allow to attach tasks to cpusets with empty cpu/node masks.
Handle empty masks with help guarantee_online_cpus() and guarantee_online_mems()

This aimed to fix attaching tasks to the newly created cgroups in hierarchies with
cpuset subsystem. Cpuset always require initializing cpuset.cpus and cpuset.mems,
because they are empty by default, this fact block task attaching with -ENOSPC.

After this patch empty masks are always handled by waking up the cpuset hierarchy
and searching valid masks on parents. cpuset_attach() already handle it corretly.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
---
 kernel/cpuset.c |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 33eee16..e32453a 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -226,6 +226,9 @@ static char cpuset_name[CPUSET_NAME_LEN];
 static char cpuset_nodelist[CPUSET_NODELIST_LEN];
 static DEFINE_SPINLOCK(cpuset_buffer_lock);
 
+/* Protected by cgroup_lock */
+static cpumask_var_t cpus_attach;
+
 /*
  * This is ugly, but preserves the userspace API for existing cpuset
  * users. If someone tries to mount the "cpuset" filesystem, we
@@ -428,8 +431,10 @@ static int validate_change(const struct cpuset *cur, const struct cpuset *trial)
 
 	/* Cpusets with tasks can't have empty cpus_allowed or mems_allowed */
 	if (cgroup_task_count(cur->css.cgroup)) {
-		if (cpumask_empty(trial->cpus_allowed) ||
-		    nodes_empty(trial->mems_allowed)) {
+		if ((!cpumask_empty(cur->cpus_allowed) &&
+		      cpumask_empty(trial->cpus_allowed)) ||
+		     (!nodes_empty(cur->mems_allowed) &&
+		       nodes_empty(trial->mems_allowed))) {
 			return -ENOSPC;
 		}
 	}
@@ -797,8 +802,7 @@ void rebuild_sched_domains(void)
 static int cpuset_test_cpumask(struct task_struct *tsk,
 			       struct cgroup_scanner *scan)
 {
-	return !cpumask_equal(&tsk->cpus_allowed,
-			(cgroup_cs(scan->cg))->cpus_allowed);
+	return !cpumask_equal(&tsk->cpus_allowed, cpus_attach);
 }
 
 /**
@@ -815,7 +819,7 @@ static int cpuset_test_cpumask(struct task_struct *tsk,
 static void cpuset_change_cpumask(struct task_struct *tsk,
 				  struct cgroup_scanner *scan)
 {
-	set_cpus_allowed_ptr(tsk, ((cgroup_cs(scan->cg))->cpus_allowed));
+	set_cpus_allowed_ptr(tsk, cpus_attach);
 }
 
 /**
@@ -835,6 +839,7 @@ static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap)
 {
 	struct cgroup_scanner scan;
 
+	guarantee_online_cpus(cs, cpus_attach);
 	scan.cg = cs->css.cgroup;
 	scan.test_task = cpuset_test_cpumask;
 	scan.process_task = cpuset_change_cpumask;
@@ -1367,18 +1372,11 @@ static int fmeter_getrate(struct fmeter *fmp)
 	return val;
 }
 
-/* Protected by cgroup_lock */
-static cpumask_var_t cpus_attach;
-
 /* Called by cgroups to determine if a cpuset is usable; cgroup_mutex held */
 static int cpuset_can_attach(struct cgroup_subsys *ss, struct cgroup *cont,
 			     struct task_struct *tsk, bool threadgroup)
 {
 	int ret;
-	struct cpuset *cs = cgroup_cs(cont);
-
-	if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
-		return -ENOSPC;
 
 	/*
 	 * Kthreads bound to specific cpus cannot be moved to a new cpuset; we


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-04-19 12:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-19 10:07 [PATCH] cpuset: allow empty cpu/node masks Konstantin Khlebnikov
2011-04-19 10:17 ` Paul Menage
2011-04-19 11:08   ` Konstantin Khlebnikov
2011-04-19 11:47     ` Paul Menage
2011-04-19 12:17       ` Konstantin Khlebnikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox