Commit 4e74339af6a59c061cf02f1ac497766bca1de19a

Authored by Li Zefan
Committed by Linus Torvalds
1 parent dea420ce0e

cpuset: avoid changing cpuset's cpus when -errno returned

After the patch:

commit 0b2f630a28d53b5a2082a5275bc3334b10373508
Author: Miao Xie <miaox@cn.fujitsu.com>
Date:   Fri Jul 25 01:47:21 2008 -0700

    cpusets: restructure the function update_cpumask() and update_nodemask()

It might happen that 'echo 0 > /cpuset/sub/cpus' returned failure but 'cpus'
has been changed, because cpus was changed before calling heap_init() which
may return -ENOMEM.

This patch restores the orginal behavior.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Paul Menage <menage@google.com>
Cc: Paul Jackson <pj@sgi.com>
Cc: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 15 additions and 22 deletions Side-by-side Diff

... ... @@ -843,37 +843,25 @@
843 843 /**
844 844 * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
845 845 * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed
  846 + * @heap: if NULL, defer allocating heap memory to cgroup_scan_tasks()
846 847 *
847 848 * Called with cgroup_mutex held
848 849 *
849 850 * The cgroup_scan_tasks() function will scan all the tasks in a cgroup,
850 851 * calling callback functions for each.
851 852 *
852   - * Return 0 if successful, -errno if not.
  853 + * No return value. It's guaranteed that cgroup_scan_tasks() always returns 0
  854 + * if @heap != NULL.
853 855 */
854   -static int update_tasks_cpumask(struct cpuset *cs)
  856 +static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap)
855 857 {
856 858 struct cgroup_scanner scan;
857   - struct ptr_heap heap;
858   - int retval;
859 859  
860   - /*
861   - * cgroup_scan_tasks() will initialize heap->gt for us.
862   - * heap_init() is still needed here for we should not change
863   - * cs->cpus_allowed when heap_init() fails.
864   - */
865   - retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
866   - if (retval)
867   - return retval;
868   -
869 860 scan.cg = cs->css.cgroup;
870 861 scan.test_task = cpuset_test_cpumask;
871 862 scan.process_task = cpuset_change_cpumask;
872   - scan.heap = &heap;
873   - retval = cgroup_scan_tasks(&scan);
874   -
875   - heap_free(&heap);
876   - return retval;
  863 + scan.heap = heap;
  864 + cgroup_scan_tasks(&scan);
877 865 }
878 866  
879 867 /**
... ... @@ -883,6 +871,7 @@
883 871 */
884 872 static int update_cpumask(struct cpuset *cs, const char *buf)
885 873 {
  874 + struct ptr_heap heap;
886 875 struct cpuset trialcs;
887 876 int retval;
888 877 int is_load_balanced;
... ... @@ -917,6 +906,10 @@
917 906 if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed))
918 907 return 0;
919 908  
  909 + retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
  910 + if (retval)
  911 + return retval;
  912 +
920 913 is_load_balanced = is_sched_load_balance(&trialcs);
921 914  
922 915 mutex_lock(&callback_mutex);
923 916  
... ... @@ -927,10 +920,10 @@
927 920 * Scan tasks in the cpuset, and update the cpumasks of any
928 921 * that need an update.
929 922 */
930   - retval = update_tasks_cpumask(cs);
931   - if (retval < 0)
932   - return retval;
  923 + update_tasks_cpumask(cs, &heap);
933 924  
  925 + heap_free(&heap);
  926 +
934 927 if (is_load_balanced)
935 928 async_rebuild_sched_domains();
936 929 return 0;
... ... @@ -1965,7 +1958,7 @@
1965 1958 nodes_empty(cp->mems_allowed))
1966 1959 remove_tasks_in_empty_cpuset(cp);
1967 1960 else {
1968   - update_tasks_cpumask(cp);
  1961 + update_tasks_cpumask(cp, NULL);
1969 1962 update_tasks_nodemask(cp, &oldmems);
1970 1963 }
1971 1964 }