public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Jackson <pj@sgi.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: nickpiggin@yahoo.com.au, Paul Menage <menage@google.com>,
	linux-kernel@vger.kernel.org,
	Dinakar Guniguntala <dino@in.ibm.com>, Paul Jackson <pj@sgi.com>,
	cpw@sgi.com, Ingo Molnar <mingo@elte.hu>
Subject: [PATCH] cpuset decrustify update and validate masks
Date: Sun, 30 Sep 2007 03:44:09 -0700	[thread overview]
Message-ID: <20070930104409.24828.5175.sendpatchset@jackhammer.engr.sgi.com> (raw)
In-Reply-To: <20070930104403.24828.48263.sendpatchset@jackhammer.engr.sgi.com>

From: Paul Jackson <pj@sgi.com>

The kernel/cpuset.c code handling the updating of a cpusets
'cpus' and 'mems' masks was starting to look a little bit
crufty to me.

So I rewrote it a little bit.  Other than subtle improvements
in the consistency of identifying white space at the beginning
and end of passed in masks, I don't see that it makes any
visible difference in behaviour.  But it's one or two hundred
kernel text bytes smaller, and to my eye, easier to understand.

Signed-off-by: Paul Jackson <pj@sgi.com>

---

Andrew - this patch goes after:
  cpuset-and-sched-domains-sched_load_balance-flag

 kernel/cpuset.c |   50 ++++++++++++++++++++------------------------------
 1 file changed, 20 insertions(+), 30 deletions(-)

--- 2.6.23-rc8-mm1.orig/kernel/cpuset.c	2007-09-30 01:27:28.442825126 -0700
+++ 2.6.23-rc8-mm1/kernel/cpuset.c	2007-09-30 01:38:22.829256421 -0700
@@ -488,6 +488,14 @@ static int validate_change(const struct 
 			return -EINVAL;
 	}
 
+	/* Cpusets with tasks can't have empty cpus_allowed or mems_allowed */
+	if (cgroup_task_count(cur->css.cgroup)) {
+		if (cpus_empty(trial->cpus_allowed) ||
+	    	    nodes_empty(trial->mems_allowed)) {
+			return -ENOSPC;
+		}
+	}
+
 	return 0;
 }
 
@@ -691,11 +699,13 @@ static int update_cpumask(struct cpuset 
 	trialcs = *cs;
 
 	/*
-	 * We allow a cpuset's cpus_allowed to be empty; if it has attached
-	 * tasks, we'll catch it later when we validate the change and return
-	 * -ENOSPC.
+	 * An empty cpus_allowed is ok iff there are no tasks in the cpuset.
+	 * Since cpulist_parse() fails on an empty mask, we special case
+	 * that parsing.  The validate_change() call ensures that cpusets
+	 * with tasks have cpus.
 	 */
-	if (!buf[0] || (buf[0] == '\n' && !buf[1])) {
+	buf = strstrip(buf);
+	if (!*buf) {
 		cpus_clear(trialcs.cpus_allowed);
 	} else {
 		retval = cpulist_parse(buf, trialcs.cpus_allowed);
@@ -703,10 +713,6 @@ static int update_cpumask(struct cpuset 
 			return retval;
 	}
 	cpus_and(trialcs.cpus_allowed, trialcs.cpus_allowed, cpu_online_map);
-	/* cpus_allowed cannot be empty for a cpuset with attached tasks. */
-	if (cgroup_task_count(cs->css.cgroup) &&
-	    cpus_empty(trialcs.cpus_allowed))
-		return -ENOSPC;
 	retval = validate_change(cs, &trialcs);
 	if (retval < 0)
 		return retval;
@@ -811,29 +817,19 @@ static int update_nodemask(struct cpuset
 	trialcs = *cs;
 
 	/*
-	 * We allow a cpuset's mems_allowed to be empty; if it has attached
-	 * tasks, we'll catch it later when we validate the change and return
-	 * -ENOSPC.
+	 * An empty mems_allowed is ok iff there are no tasks in the cpuset.
+	 * Since nodelist_parse() fails on an empty mask, we special case
+	 * that parsing.  The validate_change() call ensures that cpusets
+	 * with tasks have memory.
 	 */
-	if (!buf[0] || (buf[0] == '\n' && !buf[1])) {
+	buf = strstrip(buf);
+	if (!*buf) {
 		nodes_clear(trialcs.mems_allowed);
 	} else {
 		retval = nodelist_parse(buf, trialcs.mems_allowed);
 		if (retval < 0)
 			goto done;
-		if (!nodes_intersects(trialcs.mems_allowed,
-						node_states[N_HIGH_MEMORY])) {
-			/*
-			 * error if only memoryless nodes specified.
-			 */
-			retval = -ENOSPC;
-			goto done;
-		}
 	}
-	/*
-	 * Exclude memoryless nodes.  We know that trialcs.mems_allowed
-	 * contains at least one node with memory.
-	 */
 	nodes_and(trialcs.mems_allowed, trialcs.mems_allowed,
 						node_states[N_HIGH_MEMORY]);
 	oldmem = cs->mems_allowed;
@@ -841,12 +837,6 @@ static int update_nodemask(struct cpuset
 		retval = 0;		/* Too easy - nothing to do */
 		goto done;
 	}
-	/* mems_allowed cannot be empty for a cpuset with attached tasks. */
-	if (cgroup_task_count(cs->css.cgroup) &&
-	    nodes_empty(trialcs.mems_allowed)) {
-		retval = -ENOSPC;
-		goto done;
-	}
 	retval = validate_change(cs, &trialcs);
 	if (retval < 0)
 		goto done;

-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

  parent reply	other threads:[~2007-09-30 10:44 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-30 10:44 [PATCH] cpuset and sched domains: sched_load_balance flag Paul Jackson
2007-09-29 19:21 ` Nick Piggin
2007-09-30 18:07   ` Paul Jackson
2007-09-30  3:34     ` Nick Piggin
2007-10-01  3:42       ` Paul Jackson
2007-10-02 13:05         ` Nick Piggin
2007-10-03  6:58           ` Paul Jackson
2007-10-02 16:09             ` Nick Piggin
2007-10-03  9:55               ` Paul Jackson
2007-10-02 17:56                 ` Nick Piggin
2007-10-03 11:38                   ` Paul Jackson
2007-10-02 19:25                     ` Nick Piggin
2007-10-03 12:14                       ` Paul Jackson
2007-10-02 19:53                         ` Nick Piggin
2007-10-03 12:41                           ` Paul Jackson
2007-10-02 20:30                             ` Nick Piggin
2007-10-03 17:46                               ` Paul Jackson
2007-10-03 12:17                   ` Paul Jackson
2007-10-02 20:31                     ` Nick Piggin
2007-10-03 17:44                       ` Paul Jackson
2007-10-01 18:15       ` Paul Jackson
2007-10-02 13:35         ` Nick Piggin
2007-10-03  6:22           ` [patch] sched: fix sched-domains partitioning by cpusets Ingo Molnar
2007-10-03  6:56             ` Paul Jackson
2007-10-02 15:46               ` Nick Piggin
2007-10-03  9:21                 ` Paul Jackson
2007-10-02 17:23                   ` Nick Piggin
2007-10-03 10:08                     ` Paul Jackson
2007-10-03  9:35                   ` Ingo Molnar
2007-10-03  9:39                     ` Paul Jackson
2007-10-02 17:29                       ` Nick Piggin
2007-10-03  7:20               ` Ingo Molnar
2007-10-03  7:25           ` [PATCH] cpuset and sched domains: sched_load_balance flag Paul Jackson
2007-10-02 16:14             ` Nick Piggin
2007-09-30 10:44 ` Paul Jackson [this message]
2007-09-30 17:33 ` Ingo Molnar
2007-10-02 20:22 ` Randy Dunlap
2007-10-02 20:57   ` Paul Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070930104409.24828.5175.sendpatchset@jackhammer.engr.sgi.com \
    --to=pj@sgi.com \
    --cc=akpm@linux-foundation.org \
    --cc=cpw@sgi.com \
    --cc=dino@in.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=menage@google.com \
    --cc=mingo@elte.hu \
    --cc=nickpiggin@yahoo.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox