Commit 020958b6272882c1a8bfbe5f3e0927f3845c2698

Authored by Paul Jackson
Committed by Linus Torvalds
1 parent 029190c515

cpusets: decrustify cpuset mask update code

Decrustify the kernel/cpuset.c 'cpus' and 'mems' updating code.

Other than subtle improvements in the consistency of identifying
white space at the beginning and end of passed in masks, this
doesn't make any visible difference in behaviour.  But it's
one or two hundred kernel text bytes smaller, and easier to
understand.

[akpm@linux-foundation.org: coding-style fix]
Signed-off-by: Paul Jackson <pj@sgi.com>
Reviewed-by: Paul Menage <menage@google.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 20 additions and 30 deletions Side-by-side Diff

... ... @@ -488,6 +488,14 @@
488 488 return -EINVAL;
489 489 }
490 490  
  491 + /* Cpusets with tasks can't have empty cpus_allowed or mems_allowed */
  492 + if (cgroup_task_count(cur->css.cgroup)) {
  493 + if (cpus_empty(trial->cpus_allowed) ||
  494 + nodes_empty(trial->mems_allowed)) {
  495 + return -ENOSPC;
  496 + }
  497 + }
  498 +
491 499 return 0;
492 500 }
493 501  
494 502  
... ... @@ -710,11 +718,13 @@
710 718 trialcs = *cs;
711 719  
712 720 /*
713   - * We allow a cpuset's cpus_allowed to be empty; if it has attached
714   - * tasks, we'll catch it later when we validate the change and return
715   - * -ENOSPC.
  721 + * An empty cpus_allowed is ok iff there are no tasks in the cpuset.
  722 + * Since cpulist_parse() fails on an empty mask, we special case
  723 + * that parsing. The validate_change() call ensures that cpusets
  724 + * with tasks have cpus.
716 725 */
717   - if (!buf[0] || (buf[0] == '\n' && !buf[1])) {
  726 + buf = strstrip(buf);
  727 + if (!*buf) {
718 728 cpus_clear(trialcs.cpus_allowed);
719 729 } else {
720 730 retval = cpulist_parse(buf, trialcs.cpus_allowed);
... ... @@ -722,10 +732,6 @@
722 732 return retval;
723 733 }
724 734 cpus_and(trialcs.cpus_allowed, trialcs.cpus_allowed, cpu_online_map);
725   - /* cpus_allowed cannot be empty for a cpuset with attached tasks. */
726   - if (cgroup_task_count(cs->css.cgroup) &&
727   - cpus_empty(trialcs.cpus_allowed))
728   - return -ENOSPC;
729 735 retval = validate_change(cs, &trialcs);
730 736 if (retval < 0)
731 737 return retval;
732 738  
733 739  
734 740  
735 741  
... ... @@ -830,40 +836,24 @@
830 836 trialcs = *cs;
831 837  
832 838 /*
833   - * We allow a cpuset's mems_allowed to be empty; if it has attached
834   - * tasks, we'll catch it later when we validate the change and return
835   - * -ENOSPC.
  839 + * An empty mems_allowed is ok iff there are no tasks in the cpuset.
  840 + * Since nodelist_parse() fails on an empty mask, we special case
  841 + * that parsing. The validate_change() call ensures that cpusets
  842 + * with tasks have memory.
836 843 */
837   - if (!buf[0] || (buf[0] == '\n' && !buf[1])) {
  844 + buf = strstrip(buf);
  845 + if (!*buf) {
838 846 nodes_clear(trialcs.mems_allowed);
839 847 } else {
840 848 retval = nodelist_parse(buf, trialcs.mems_allowed);
841 849 if (retval < 0)
842 850 goto done;
843   - if (!nodes_intersects(trialcs.mems_allowed,
844   - node_states[N_HIGH_MEMORY])) {
845   - /*
846   - * error if only memoryless nodes specified.
847   - */
848   - retval = -ENOSPC;
849   - goto done;
850   - }
851 851 }
852   - /*
853   - * Exclude memoryless nodes. We know that trialcs.mems_allowed
854   - * contains at least one node with memory.
855   - */
856 852 nodes_and(trialcs.mems_allowed, trialcs.mems_allowed,
857 853 node_states[N_HIGH_MEMORY]);
858 854 oldmem = cs->mems_allowed;
859 855 if (nodes_equal(oldmem, trialcs.mems_allowed)) {
860 856 retval = 0; /* Too easy - nothing to do */
861   - goto done;
862   - }
863   - /* mems_allowed cannot be empty for a cpuset with attached tasks. */
864   - if (cgroup_task_count(cs->css.cgroup) &&
865   - nodes_empty(trialcs.mems_allowed)) {
866   - retval = -ENOSPC;
867 857 goto done;
868 858 }
869 859 retval = validate_change(cs, &trialcs);