summaryrefslogtreecommitdiffstats
path: root/kernel/cpuset.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-08-04 13:11:28 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-04 13:11:28 -0400
commit47dfe4037e37b2843055ea3feccf1c335ea23a9c (patch)
tree818e8da41b62e6e801d88feaccfb45ad60ed5968 /kernel/cpuset.c
parentf2a84170ede80e4b80f636e3700ef4d4d5dc7d33 (diff)
parenta13812683f1118ee4deed88d8d9bc2c268358b2e (diff)
Merge branch 'for-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup changes from Tejun Heo: "Mostly changes to get the v2 interface ready. The core features are mostly ready now and I think it's reasonable to expect to drop the devel mask in one or two devel cycles at least for a subset of controllers. - cgroup added a controller dependency mechanism so that block cgroup can depend on memory cgroup. This will be used to finally support IO provisioning on the writeback traffic, which is currently being implemented. - The v2 interface now uses a separate table so that the interface files for the new interface are explicitly declared in one place. Each controller will explicitly review and add the files for the new interface. - cpuset is getting ready for the hierarchical behavior which is in the similar style with other controllers so that an ancestor's configuration change doesn't change the descendants' configurations irreversibly and processes aren't silently migrated when a CPU or node goes down. All the changes are to the new interface and no behavior changed for the multiple hierarchies" * 'for-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: (29 commits) cpuset: fix the WARN_ON() in update_nodemasks_hier() cgroup: initialize cgrp_dfl_root_inhibit_ss_mask from !->dfl_files test cgroup: make CFTYPE_ONLY_ON_DFL and CFTYPE_NO_ internal to cgroup core cgroup: distinguish the default and legacy hierarchies when handling cftypes cgroup: replace cgroup_add_cftypes() with cgroup_add_legacy_cftypes() cgroup: rename cgroup_subsys->base_cftypes to ->legacy_cftypes cgroup: split cgroup_base_files[] into cgroup_{dfl|legacy}_base_files[] cpuset: export effective masks to userspace cpuset: allow writing offlined masks to cpuset.cpus/mems cpuset: enable onlined cpu/node in effective masks cpuset: refactor cpuset_hotplug_update_tasks() cpuset: make cs->{cpus, mems}_allowed as user-configured masks cpuset: apply cs->effective_{cpus,mems} cpuset: initialize top_cpuset's configured masks at mount cpuset: use effective cpumask to build sched domains cpuset: inherit ancestor's masks if effective_{cpus, mems} becomes empty cpuset: update cs->effective_{cpus, mems} when config changes cpuset: update cpuset->effective_{cpus,mems} at hotplug cpuset: add cs->effective_cpus and cs->effective_mems cgroup: clean up sane_behavior handling ...
Diffstat (limited to 'kernel/cpuset.c')
-rw-r--r--kernel/cpuset.c500
1 files changed, 306 insertions, 194 deletions
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 116a4164720a..22874d7cf2c0 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -76,8 +76,34 @@ struct cpuset {
76 struct cgroup_subsys_state css; 76 struct cgroup_subsys_state css;
77 77
78 unsigned long flags; /* "unsigned long" so bitops work */ 78 unsigned long flags; /* "unsigned long" so bitops work */
79 cpumask_var_t cpus_allowed; /* CPUs allowed to tasks in cpuset */ 79
80 nodemask_t mems_allowed; /* Memory Nodes allowed to tasks */ 80 /*
81 * On default hierarchy:
82 *
83 * The user-configured masks can only be changed by writing to
84 * cpuset.cpus and cpuset.mems, and won't be limited by the
85 * parent masks.
86 *
87 * The effective masks is the real masks that apply to the tasks
88 * in the cpuset. They may be changed if the configured masks are
89 * changed or hotplug happens.
90 *
91 * effective_mask == configured_mask & parent's effective_mask,
92 * and if it ends up empty, it will inherit the parent's mask.
93 *
94 *
95 * On legacy hierachy:
96 *
97 * The user-configured masks are always the same with effective masks.
98 */
99
100 /* user-configured CPUs and Memory Nodes allow to tasks */
101 cpumask_var_t cpus_allowed;
102 nodemask_t mems_allowed;
103
104 /* effective CPUs and Memory Nodes allow to tasks */
105 cpumask_var_t effective_cpus;
106 nodemask_t effective_mems;
81 107
82 /* 108 /*
83 * This is old Memory Nodes tasks took on. 109 * This is old Memory Nodes tasks took on.
@@ -307,9 +333,9 @@ static struct file_system_type cpuset_fs_type = {
307 */ 333 */
308static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask) 334static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask)
309{ 335{
310 while (!cpumask_intersects(cs->cpus_allowed, cpu_online_mask)) 336 while (!cpumask_intersects(cs->effective_cpus, cpu_online_mask))
311 cs = parent_cs(cs); 337 cs = parent_cs(cs);
312 cpumask_and(pmask, cs->cpus_allowed, cpu_online_mask); 338 cpumask_and(pmask, cs->effective_cpus, cpu_online_mask);
313} 339}
314 340
315/* 341/*
@@ -325,9 +351,9 @@ static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask)
325 */ 351 */
326static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask) 352static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask)
327{ 353{
328 while (!nodes_intersects(cs->mems_allowed, node_states[N_MEMORY])) 354 while (!nodes_intersects(cs->effective_mems, node_states[N_MEMORY]))
329 cs = parent_cs(cs); 355 cs = parent_cs(cs);
330 nodes_and(*pmask, cs->mems_allowed, node_states[N_MEMORY]); 356 nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]);
331} 357}
332 358
333/* 359/*
@@ -376,13 +402,20 @@ static struct cpuset *alloc_trial_cpuset(struct cpuset *cs)
376 if (!trial) 402 if (!trial)
377 return NULL; 403 return NULL;
378 404
379 if (!alloc_cpumask_var(&trial->cpus_allowed, GFP_KERNEL)) { 405 if (!alloc_cpumask_var(&trial->cpus_allowed, GFP_KERNEL))
380 kfree(trial); 406 goto free_cs;
381 return NULL; 407 if (!alloc_cpumask_var(&trial->effective_cpus, GFP_KERNEL))
382 } 408 goto free_cpus;
383 cpumask_copy(trial->cpus_allowed, cs->cpus_allowed);
384 409
410 cpumask_copy(trial->cpus_allowed, cs->cpus_allowed);
411 cpumask_copy(trial->effective_cpus, cs->effective_cpus);
385 return trial; 412 return trial;
413
414free_cpus:
415 free_cpumask_var(trial->cpus_allowed);
416free_cs:
417 kfree(trial);
418 return NULL;
386} 419}
387 420
388/** 421/**
@@ -391,6 +424,7 @@ static struct cpuset *alloc_trial_cpuset(struct cpuset *cs)
391 */ 424 */
392static void free_trial_cpuset(struct cpuset *trial) 425static void free_trial_cpuset(struct cpuset *trial)
393{ 426{
427 free_cpumask_var(trial->effective_cpus);
394 free_cpumask_var(trial->cpus_allowed); 428 free_cpumask_var(trial->cpus_allowed);
395 kfree(trial); 429 kfree(trial);
396} 430}
@@ -436,9 +470,9 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial)
436 470
437 par = parent_cs(cur); 471 par = parent_cs(cur);
438 472
439 /* We must be a subset of our parent cpuset */ 473 /* On legacy hiearchy, we must be a subset of our parent cpuset. */
440 ret = -EACCES; 474 ret = -EACCES;
441 if (!is_cpuset_subset(trial, par)) 475 if (!cgroup_on_dfl(cur->css.cgroup) && !is_cpuset_subset(trial, par))
442 goto out; 476 goto out;
443 477
444 /* 478 /*
@@ -480,11 +514,11 @@ out:
480#ifdef CONFIG_SMP 514#ifdef CONFIG_SMP
481/* 515/*
482 * Helper routine for generate_sched_domains(). 516 * Helper routine for generate_sched_domains().
483 * Do cpusets a, b have overlapping cpus_allowed masks? 517 * Do cpusets a, b have overlapping effective cpus_allowed masks?
484 */ 518 */
485static int cpusets_overlap(struct cpuset *a, struct cpuset *b) 519static int cpusets_overlap(struct cpuset *a, struct cpuset *b)
486{ 520{
487 return cpumask_intersects(a->cpus_allowed, b->cpus_allowed); 521 return cpumask_intersects(a->effective_cpus, b->effective_cpus);
488} 522}
489 523
490static void 524static void
@@ -601,7 +635,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
601 *dattr = SD_ATTR_INIT; 635 *dattr = SD_ATTR_INIT;
602 update_domain_attr_tree(dattr, &top_cpuset); 636 update_domain_attr_tree(dattr, &top_cpuset);
603 } 637 }
604 cpumask_copy(doms[0], top_cpuset.cpus_allowed); 638 cpumask_copy(doms[0], top_cpuset.effective_cpus);
605 639
606 goto done; 640 goto done;
607 } 641 }
@@ -705,7 +739,7 @@ restart:
705 struct cpuset *b = csa[j]; 739 struct cpuset *b = csa[j];
706 740
707 if (apn == b->pn) { 741 if (apn == b->pn) {
708 cpumask_or(dp, dp, b->cpus_allowed); 742 cpumask_or(dp, dp, b->effective_cpus);
709 if (dattr) 743 if (dattr)
710 update_domain_attr_tree(dattr + nslot, b); 744 update_domain_attr_tree(dattr + nslot, b);
711 745
@@ -757,7 +791,7 @@ static void rebuild_sched_domains_locked(void)
757 * passing doms with offlined cpu to partition_sched_domains(). 791 * passing doms with offlined cpu to partition_sched_domains().
758 * Anyways, hotplug work item will rebuild sched domains. 792 * Anyways, hotplug work item will rebuild sched domains.
759 */ 793 */
760 if (!cpumask_equal(top_cpuset.cpus_allowed, cpu_active_mask)) 794 if (!cpumask_equal(top_cpuset.effective_cpus, cpu_active_mask))
761 goto out; 795 goto out;
762 796
763 /* Generate domain masks and attrs */ 797 /* Generate domain masks and attrs */
@@ -781,45 +815,6 @@ void rebuild_sched_domains(void)
781 mutex_unlock(&cpuset_mutex); 815 mutex_unlock(&cpuset_mutex);
782} 816}
783 817
784/*
785 * effective_cpumask_cpuset - return nearest ancestor with non-empty cpus
786 * @cs: the cpuset in interest
787 *
788 * A cpuset's effective cpumask is the cpumask of the nearest ancestor
789 * with non-empty cpus. We use effective cpumask whenever:
790 * - we update tasks' cpus_allowed. (they take on the ancestor's cpumask
791 * if the cpuset they reside in has no cpus)
792 * - we want to retrieve task_cs(tsk)'s cpus_allowed.
793 *
794 * Called with cpuset_mutex held. cpuset_cpus_allowed_fallback() is an
795 * exception. See comments there.
796 */
797static struct cpuset *effective_cpumask_cpuset(struct cpuset *cs)
798{
799 while (cpumask_empty(cs->cpus_allowed))
800 cs = parent_cs(cs);
801 return cs;
802}
803
804/*
805 * effective_nodemask_cpuset - return nearest ancestor with non-empty mems
806 * @cs: the cpuset in interest
807 *
808 * A cpuset's effective nodemask is the nodemask of the nearest ancestor
809 * with non-empty memss. We use effective nodemask whenever:
810 * - we update tasks' mems_allowed. (they take on the ancestor's nodemask
811 * if the cpuset they reside in has no mems)
812 * - we want to retrieve task_cs(tsk)'s mems_allowed.
813 *
814 * Called with cpuset_mutex held.
815 */
816static struct cpuset *effective_nodemask_cpuset(struct cpuset *cs)
817{
818 while (nodes_empty(cs->mems_allowed))
819 cs = parent_cs(cs);
820 return cs;
821}
822
823/** 818/**
824 * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. 819 * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
825 * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed 820 * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed
@@ -830,53 +825,80 @@ static struct cpuset *effective_nodemask_cpuset(struct cpuset *cs)
830 */ 825 */
831static void update_tasks_cpumask(struct cpuset *cs) 826static void update_tasks_cpumask(struct cpuset *cs)
832{ 827{
833 struct cpuset *cpus_cs = effective_cpumask_cpuset(cs);
834 struct css_task_iter it; 828 struct css_task_iter it;
835 struct task_struct *task; 829 struct task_struct *task;
836 830
837 css_task_iter_start(&cs->css, &it); 831 css_task_iter_start(&cs->css, &it);
838 while ((task = css_task_iter_next(&it))) 832 while ((task = css_task_iter_next(&it)))
839 set_cpus_allowed_ptr(task, cpus_cs->cpus_allowed); 833 set_cpus_allowed_ptr(task, cs->effective_cpus);
840 css_task_iter_end(&it); 834 css_task_iter_end(&it);
841} 835}
842 836
843/* 837/*
844 * update_tasks_cpumask_hier - Update the cpumasks of tasks in the hierarchy. 838 * update_cpumasks_hier - Update effective cpumasks and tasks in the subtree
845 * @root_cs: the root cpuset of the hierarchy 839 * @cs: the cpuset to consider
846 * @update_root: update root cpuset or not? 840 * @new_cpus: temp variable for calculating new effective_cpus
841 *
842 * When congifured cpumask is changed, the effective cpumasks of this cpuset
843 * and all its descendants need to be updated.
847 * 844 *
848 * This will update cpumasks of tasks in @root_cs and all other empty cpusets 845 * On legacy hierachy, effective_cpus will be the same with cpu_allowed.
849 * which take on cpumask of @root_cs.
850 * 846 *
851 * Called with cpuset_mutex held 847 * Called with cpuset_mutex held
852 */ 848 */
853static void update_tasks_cpumask_hier(struct cpuset *root_cs, bool update_root) 849static void update_cpumasks_hier(struct cpuset *cs, struct cpumask *new_cpus)
854{ 850{
855 struct cpuset *cp; 851 struct cpuset *cp;
856 struct cgroup_subsys_state *pos_css; 852 struct cgroup_subsys_state *pos_css;
853 bool need_rebuild_sched_domains = false;
857 854
858 rcu_read_lock(); 855 rcu_read_lock();
859 cpuset_for_each_descendant_pre(cp, pos_css, root_cs) { 856 cpuset_for_each_descendant_pre(cp, pos_css, cs) {
860 if (cp == root_cs) { 857 struct cpuset *parent = parent_cs(cp);
861 if (!update_root) 858
862 continue; 859 cpumask_and(new_cpus, cp->cpus_allowed, parent->effective_cpus);
863 } else { 860
864 /* skip the whole subtree if @cp have some CPU */ 861 /*
865 if (!cpumask_empty(cp->cpus_allowed)) { 862 * If it becomes empty, inherit the effective mask of the
866 pos_css = css_rightmost_descendant(pos_css); 863 * parent, which is guaranteed to have some CPUs.
867 continue; 864 */
868 } 865 if (cpumask_empty(new_cpus))
866 cpumask_copy(new_cpus, parent->effective_cpus);
867
868 /* Skip the whole subtree if the cpumask remains the same. */
869 if (cpumask_equal(new_cpus, cp->effective_cpus)) {
870 pos_css = css_rightmost_descendant(pos_css);
871 continue;
869 } 872 }
873
870 if (!css_tryget_online(&cp->css)) 874 if (!css_tryget_online(&cp->css))
871 continue; 875 continue;
872 rcu_read_unlock(); 876 rcu_read_unlock();
873 877
878 mutex_lock(&callback_mutex);
879 cpumask_copy(cp->effective_cpus, new_cpus);
880 mutex_unlock(&callback_mutex);
881
882 WARN_ON(!cgroup_on_dfl(cp->css.cgroup) &&
883 !cpumask_equal(cp->cpus_allowed, cp->effective_cpus));
884
874 update_tasks_cpumask(cp); 885 update_tasks_cpumask(cp);
875 886
887 /*
888 * If the effective cpumask of any non-empty cpuset is changed,
889 * we need to rebuild sched domains.
890 */
891 if (!cpumask_empty(cp->cpus_allowed) &&
892 is_sched_load_balance(cp))
893 need_rebuild_sched_domains = true;
894
876 rcu_read_lock(); 895 rcu_read_lock();
877 css_put(&cp->css); 896 css_put(&cp->css);
878 } 897 }
879 rcu_read_unlock(); 898 rcu_read_unlock();
899
900 if (need_rebuild_sched_domains)
901 rebuild_sched_domains_locked();
880} 902}
881 903
882/** 904/**
@@ -889,7 +911,6 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
889 const char *buf) 911 const char *buf)
890{ 912{
891 int retval; 913 int retval;
892 int is_load_balanced;
893 914
894 /* top_cpuset.cpus_allowed tracks cpu_online_mask; it's read-only */ 915 /* top_cpuset.cpus_allowed tracks cpu_online_mask; it's read-only */
895 if (cs == &top_cpuset) 916 if (cs == &top_cpuset)
@@ -908,7 +929,8 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
908 if (retval < 0) 929 if (retval < 0)
909 return retval; 930 return retval;
910 931
911 if (!cpumask_subset(trialcs->cpus_allowed, cpu_active_mask)) 932 if (!cpumask_subset(trialcs->cpus_allowed,
933 top_cpuset.cpus_allowed))
912 return -EINVAL; 934 return -EINVAL;
913 } 935 }
914 936
@@ -920,16 +942,12 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
920 if (retval < 0) 942 if (retval < 0)
921 return retval; 943 return retval;
922 944
923 is_load_balanced = is_sched_load_balance(trialcs);
924
925 mutex_lock(&callback_mutex); 945 mutex_lock(&callback_mutex);
926 cpumask_copy(cs->cpus_allowed, trialcs->cpus_allowed); 946 cpumask_copy(cs->cpus_allowed, trialcs->cpus_allowed);
927 mutex_unlock(&callback_mutex); 947 mutex_unlock(&callback_mutex);
928 948
929 update_tasks_cpumask_hier(cs, true); 949 /* use trialcs->cpus_allowed as a temp variable */
930 950 update_cpumasks_hier(cs, trialcs->cpus_allowed);
931 if (is_load_balanced)
932 rebuild_sched_domains_locked();
933 return 0; 951 return 0;
934} 952}
935 953
@@ -951,15 +969,13 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from,
951 const nodemask_t *to) 969 const nodemask_t *to)
952{ 970{
953 struct task_struct *tsk = current; 971 struct task_struct *tsk = current;
954 struct cpuset *mems_cs;
955 972
956 tsk->mems_allowed = *to; 973 tsk->mems_allowed = *to;
957 974
958 do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL); 975 do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL);
959 976
960 rcu_read_lock(); 977 rcu_read_lock();
961 mems_cs = effective_nodemask_cpuset(task_cs(tsk)); 978 guarantee_online_mems(task_cs(tsk), &tsk->mems_allowed);
962 guarantee_online_mems(mems_cs, &tsk->mems_allowed);
963 rcu_read_unlock(); 979 rcu_read_unlock();
964} 980}
965 981
@@ -1028,13 +1044,12 @@ static void *cpuset_being_rebound;
1028static void update_tasks_nodemask(struct cpuset *cs) 1044static void update_tasks_nodemask(struct cpuset *cs)
1029{ 1045{
1030 static nodemask_t newmems; /* protected by cpuset_mutex */ 1046 static nodemask_t newmems; /* protected by cpuset_mutex */
1031 struct cpuset *mems_cs = effective_nodemask_cpuset(cs);
1032 struct css_task_iter it; 1047 struct css_task_iter it;
1033 struct task_struct *task; 1048 struct task_struct *task;
1034 1049
1035 cpuset_being_rebound = cs; /* causes mpol_dup() rebind */ 1050 cpuset_being_rebound = cs; /* causes mpol_dup() rebind */
1036 1051
1037 guarantee_online_mems(mems_cs, &newmems); 1052 guarantee_online_mems(cs, &newmems);
1038 1053
1039 /* 1054 /*
1040 * The mpol_rebind_mm() call takes mmap_sem, which we couldn't 1055 * The mpol_rebind_mm() call takes mmap_sem, which we couldn't
@@ -1077,36 +1092,52 @@ static void update_tasks_nodemask(struct cpuset *cs)
1077} 1092}
1078 1093
1079/* 1094/*
1080 * update_tasks_nodemask_hier - Update the nodemasks of tasks in the hierarchy. 1095 * update_nodemasks_hier - Update effective nodemasks and tasks in the subtree
1081 * @cs: the root cpuset of the hierarchy 1096 * @cs: the cpuset to consider
1082 * @update_root: update the root cpuset or not? 1097 * @new_mems: a temp variable for calculating new effective_mems
1083 * 1098 *
1084 * This will update nodemasks of tasks in @root_cs and all other empty cpusets 1099 * When configured nodemask is changed, the effective nodemasks of this cpuset
1085 * which take on nodemask of @root_cs. 1100 * and all its descendants need to be updated.
1101 *
1102 * On legacy hiearchy, effective_mems will be the same with mems_allowed.
1086 * 1103 *
1087 * Called with cpuset_mutex held 1104 * Called with cpuset_mutex held
1088 */ 1105 */
1089static void update_tasks_nodemask_hier(struct cpuset *root_cs, bool update_root) 1106static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
1090{ 1107{
1091 struct cpuset *cp; 1108 struct cpuset *cp;
1092 struct cgroup_subsys_state *pos_css; 1109 struct cgroup_subsys_state *pos_css;
1093 1110
1094 rcu_read_lock(); 1111 rcu_read_lock();
1095 cpuset_for_each_descendant_pre(cp, pos_css, root_cs) { 1112 cpuset_for_each_descendant_pre(cp, pos_css, cs) {
1096 if (cp == root_cs) { 1113 struct cpuset *parent = parent_cs(cp);
1097 if (!update_root) 1114
1098 continue; 1115 nodes_and(*new_mems, cp->mems_allowed, parent->effective_mems);
1099 } else { 1116
1100 /* skip the whole subtree if @cp have some CPU */ 1117 /*
1101 if (!nodes_empty(cp->mems_allowed)) { 1118 * If it becomes empty, inherit the effective mask of the
1102 pos_css = css_rightmost_descendant(pos_css); 1119 * parent, which is guaranteed to have some MEMs.
1103 continue; 1120 */
1104 } 1121 if (nodes_empty(*new_mems))
1122 *new_mems = parent->effective_mems;
1123
1124 /* Skip the whole subtree if the nodemask remains the same. */
1125 if (nodes_equal(*new_mems, cp->effective_mems)) {
1126 pos_css = css_rightmost_descendant(pos_css);
1127 continue;
1105 } 1128 }
1129
1106 if (!css_tryget_online(&cp->css)) 1130 if (!css_tryget_online(&cp->css))
1107 continue; 1131 continue;
1108 rcu_read_unlock(); 1132 rcu_read_unlock();
1109 1133
1134 mutex_lock(&callback_mutex);
1135 cp->effective_mems = *new_mems;
1136 mutex_unlock(&callback_mutex);
1137
1138 WARN_ON(!cgroup_on_dfl(cp->css.cgroup) &&
1139 !nodes_equal(cp->mems_allowed, cp->effective_mems));
1140
1110 update_tasks_nodemask(cp); 1141 update_tasks_nodemask(cp);
1111 1142
1112 rcu_read_lock(); 1143 rcu_read_lock();
@@ -1156,8 +1187,8 @@ static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs,
1156 goto done; 1187 goto done;
1157 1188
1158 if (!nodes_subset(trialcs->mems_allowed, 1189 if (!nodes_subset(trialcs->mems_allowed,
1159 node_states[N_MEMORY])) { 1190 top_cpuset.mems_allowed)) {
1160 retval = -EINVAL; 1191 retval = -EINVAL;
1161 goto done; 1192 goto done;
1162 } 1193 }
1163 } 1194 }
@@ -1174,7 +1205,8 @@ static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs,
1174 cs->mems_allowed = trialcs->mems_allowed; 1205 cs->mems_allowed = trialcs->mems_allowed;
1175 mutex_unlock(&callback_mutex); 1206 mutex_unlock(&callback_mutex);
1176 1207
1177 update_tasks_nodemask_hier(cs, true); 1208 /* use trialcs->mems_allowed as a temp variable */
1209 update_nodemasks_hier(cs, &cs->mems_allowed);
1178done: 1210done:
1179 return retval; 1211 return retval;
1180} 1212}
@@ -1389,12 +1421,9 @@ static int cpuset_can_attach(struct cgroup_subsys_state *css,
1389 1421
1390 mutex_lock(&cpuset_mutex); 1422 mutex_lock(&cpuset_mutex);
1391 1423
1392 /* 1424 /* allow moving tasks into an empty cpuset if on default hierarchy */
1393 * We allow to move tasks into an empty cpuset if sane_behavior
1394 * flag is set.
1395 */
1396 ret = -ENOSPC; 1425 ret = -ENOSPC;
1397 if (!cgroup_sane_behavior(css->cgroup) && 1426 if (!cgroup_on_dfl(css->cgroup) &&
1398 (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))) 1427 (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed)))
1399 goto out_unlock; 1428 goto out_unlock;
1400 1429
@@ -1452,8 +1481,6 @@ static void cpuset_attach(struct cgroup_subsys_state *css,
1452 struct task_struct *leader = cgroup_taskset_first(tset); 1481 struct task_struct *leader = cgroup_taskset_first(tset);
1453 struct cpuset *cs = css_cs(css); 1482 struct cpuset *cs = css_cs(css);
1454 struct cpuset *oldcs = cpuset_attach_old_cs; 1483 struct cpuset *oldcs = cpuset_attach_old_cs;
1455 struct cpuset *cpus_cs = effective_cpumask_cpuset(cs);
1456 struct cpuset *mems_cs = effective_nodemask_cpuset(cs);
1457 1484
1458 mutex_lock(&cpuset_mutex); 1485 mutex_lock(&cpuset_mutex);
1459 1486
@@ -1461,9 +1488,9 @@ static void cpuset_attach(struct cgroup_subsys_state *css,
1461 if (cs == &top_cpuset) 1488 if (cs == &top_cpuset)
1462 cpumask_copy(cpus_attach, cpu_possible_mask); 1489 cpumask_copy(cpus_attach, cpu_possible_mask);
1463 else 1490 else
1464 guarantee_online_cpus(cpus_cs, cpus_attach); 1491 guarantee_online_cpus(cs, cpus_attach);
1465 1492
1466 guarantee_online_mems(mems_cs, &cpuset_attach_nodemask_to); 1493 guarantee_online_mems(cs, &cpuset_attach_nodemask_to);
1467 1494
1468 cgroup_taskset_for_each(task, tset) { 1495 cgroup_taskset_for_each(task, tset) {
1469 /* 1496 /*
@@ -1480,11 +1507,9 @@ static void cpuset_attach(struct cgroup_subsys_state *css,
1480 * Change mm, possibly for multiple threads in a threadgroup. This is 1507 * Change mm, possibly for multiple threads in a threadgroup. This is
1481 * expensive and may sleep. 1508 * expensive and may sleep.
1482 */ 1509 */
1483 cpuset_attach_nodemask_to = cs->mems_allowed; 1510 cpuset_attach_nodemask_to = cs->effective_mems;
1484 mm = get_task_mm(leader); 1511 mm = get_task_mm(leader);
1485 if (mm) { 1512 if (mm) {
1486 struct cpuset *mems_oldcs = effective_nodemask_cpuset(oldcs);
1487
1488 mpol_rebind_mm(mm, &cpuset_attach_nodemask_to); 1513 mpol_rebind_mm(mm, &cpuset_attach_nodemask_to);
1489 1514
1490 /* 1515 /*
@@ -1495,7 +1520,7 @@ static void cpuset_attach(struct cgroup_subsys_state *css,
1495 * mm from. 1520 * mm from.
1496 */ 1521 */
1497 if (is_memory_migrate(cs)) { 1522 if (is_memory_migrate(cs)) {
1498 cpuset_migrate_mm(mm, &mems_oldcs->old_mems_allowed, 1523 cpuset_migrate_mm(mm, &oldcs->old_mems_allowed,
1499 &cpuset_attach_nodemask_to); 1524 &cpuset_attach_nodemask_to);
1500 } 1525 }
1501 mmput(mm); 1526 mmput(mm);
@@ -1516,6 +1541,8 @@ typedef enum {
1516 FILE_MEMORY_MIGRATE, 1541 FILE_MEMORY_MIGRATE,
1517 FILE_CPULIST, 1542 FILE_CPULIST,
1518 FILE_MEMLIST, 1543 FILE_MEMLIST,
1544 FILE_EFFECTIVE_CPULIST,
1545 FILE_EFFECTIVE_MEMLIST,
1519 FILE_CPU_EXCLUSIVE, 1546 FILE_CPU_EXCLUSIVE,
1520 FILE_MEM_EXCLUSIVE, 1547 FILE_MEM_EXCLUSIVE,
1521 FILE_MEM_HARDWALL, 1548 FILE_MEM_HARDWALL,
@@ -1694,6 +1721,12 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
1694 case FILE_MEMLIST: 1721 case FILE_MEMLIST:
1695 s += nodelist_scnprintf(s, count, cs->mems_allowed); 1722 s += nodelist_scnprintf(s, count, cs->mems_allowed);
1696 break; 1723 break;
1724 case FILE_EFFECTIVE_CPULIST:
1725 s += cpulist_scnprintf(s, count, cs->effective_cpus);
1726 break;
1727 case FILE_EFFECTIVE_MEMLIST:
1728 s += nodelist_scnprintf(s, count, cs->effective_mems);
1729 break;
1697 default: 1730 default:
1698 ret = -EINVAL; 1731 ret = -EINVAL;
1699 goto out_unlock; 1732 goto out_unlock;
@@ -1779,6 +1812,18 @@ static struct cftype files[] = {
1779 }, 1812 },
1780 1813
1781 { 1814 {
1815 .name = "effective_cpus",
1816 .seq_show = cpuset_common_seq_show,
1817 .private = FILE_EFFECTIVE_CPULIST,
1818 },
1819
1820 {
1821 .name = "effective_mems",
1822 .seq_show = cpuset_common_seq_show,
1823 .private = FILE_EFFECTIVE_MEMLIST,
1824 },
1825
1826 {
1782 .name = "cpu_exclusive", 1827 .name = "cpu_exclusive",
1783 .read_u64 = cpuset_read_u64, 1828 .read_u64 = cpuset_read_u64,
1784 .write_u64 = cpuset_write_u64, 1829 .write_u64 = cpuset_write_u64,
@@ -1869,18 +1914,26 @@ cpuset_css_alloc(struct cgroup_subsys_state *parent_css)
1869 cs = kzalloc(sizeof(*cs), GFP_KERNEL); 1914 cs = kzalloc(sizeof(*cs), GFP_KERNEL);
1870 if (!cs) 1915 if (!cs)
1871 return ERR_PTR(-ENOMEM); 1916 return ERR_PTR(-ENOMEM);
1872 if (!alloc_cpumask_var(&cs->cpus_allowed, GFP_KERNEL)) { 1917 if (!alloc_cpumask_var(&cs->cpus_allowed, GFP_KERNEL))
1873 kfree(cs); 1918 goto free_cs;
1874 return ERR_PTR(-ENOMEM); 1919 if (!alloc_cpumask_var(&cs->effective_cpus, GFP_KERNEL))
1875 } 1920 goto free_cpus;
1876 1921
1877 set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags); 1922 set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
1878 cpumask_clear(cs->cpus_allowed); 1923 cpumask_clear(cs->cpus_allowed);
1879 nodes_clear(cs->mems_allowed); 1924 nodes_clear(cs->mems_allowed);
1925 cpumask_clear(cs->effective_cpus);
1926 nodes_clear(cs->effective_mems);
1880 fmeter_init(&cs->fmeter); 1927 fmeter_init(&cs->fmeter);
1881 cs->relax_domain_level = -1; 1928 cs->relax_domain_level = -1;
1882 1929
1883 return &cs->css; 1930 return &cs->css;
1931
1932free_cpus:
1933 free_cpumask_var(cs->cpus_allowed);
1934free_cs:
1935 kfree(cs);
1936 return ERR_PTR(-ENOMEM);
1884} 1937}
1885 1938
1886static int cpuset_css_online(struct cgroup_subsys_state *css) 1939static int cpuset_css_online(struct cgroup_subsys_state *css)
@@ -1903,6 +1956,13 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
1903 1956
1904 cpuset_inc(); 1957 cpuset_inc();
1905 1958
1959 mutex_lock(&callback_mutex);
1960 if (cgroup_on_dfl(cs->css.cgroup)) {
1961 cpumask_copy(cs->effective_cpus, parent->effective_cpus);
1962 cs->effective_mems = parent->effective_mems;
1963 }
1964 mutex_unlock(&callback_mutex);
1965
1906 if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags)) 1966 if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags))
1907 goto out_unlock; 1967 goto out_unlock;
1908 1968
@@ -1962,20 +2022,40 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)
1962{ 2022{
1963 struct cpuset *cs = css_cs(css); 2023 struct cpuset *cs = css_cs(css);
1964 2024
2025 free_cpumask_var(cs->effective_cpus);
1965 free_cpumask_var(cs->cpus_allowed); 2026 free_cpumask_var(cs->cpus_allowed);
1966 kfree(cs); 2027 kfree(cs);
1967} 2028}
1968 2029
2030static void cpuset_bind(struct cgroup_subsys_state *root_css)
2031{
2032 mutex_lock(&cpuset_mutex);
2033 mutex_lock(&callback_mutex);
2034
2035 if (cgroup_on_dfl(root_css->cgroup)) {
2036 cpumask_copy(top_cpuset.cpus_allowed, cpu_possible_mask);
2037 top_cpuset.mems_allowed = node_possible_map;
2038 } else {
2039 cpumask_copy(top_cpuset.cpus_allowed,
2040 top_cpuset.effective_cpus);
2041 top_cpuset.mems_allowed = top_cpuset.effective_mems;
2042 }
2043
2044 mutex_unlock(&callback_mutex);
2045 mutex_unlock(&cpuset_mutex);
2046}
2047
1969struct cgroup_subsys cpuset_cgrp_subsys = { 2048struct cgroup_subsys cpuset_cgrp_subsys = {
1970 .css_alloc = cpuset_css_alloc, 2049 .css_alloc = cpuset_css_alloc,
1971 .css_online = cpuset_css_online, 2050 .css_online = cpuset_css_online,
1972 .css_offline = cpuset_css_offline, 2051 .css_offline = cpuset_css_offline,
1973 .css_free = cpuset_css_free, 2052 .css_free = cpuset_css_free,
1974 .can_attach = cpuset_can_attach, 2053 .can_attach = cpuset_can_attach,
1975 .cancel_attach = cpuset_cancel_attach, 2054 .cancel_attach = cpuset_cancel_attach,
1976 .attach = cpuset_attach, 2055 .attach = cpuset_attach,
1977 .base_cftypes = files, 2056 .bind = cpuset_bind,
1978 .early_init = 1, 2057 .legacy_cftypes = files,
2058 .early_init = 1,
1979}; 2059};
1980 2060
1981/** 2061/**
@@ -1990,9 +2070,13 @@ int __init cpuset_init(void)
1990 2070
1991 if (!alloc_cpumask_var(&top_cpuset.cpus_allowed, GFP_KERNEL)) 2071 if (!alloc_cpumask_var(&top_cpuset.cpus_allowed, GFP_KERNEL))
1992 BUG(); 2072 BUG();
2073 if (!alloc_cpumask_var(&top_cpuset.effective_cpus, GFP_KERNEL))
2074 BUG();
1993 2075
1994 cpumask_setall(top_cpuset.cpus_allowed); 2076 cpumask_setall(top_cpuset.cpus_allowed);
1995 nodes_setall(top_cpuset.mems_allowed); 2077 nodes_setall(top_cpuset.mems_allowed);
2078 cpumask_setall(top_cpuset.effective_cpus);
2079 nodes_setall(top_cpuset.effective_mems);
1996 2080
1997 fmeter_init(&top_cpuset.fmeter); 2081 fmeter_init(&top_cpuset.fmeter);
1998 set_bit(CS_SCHED_LOAD_BALANCE, &top_cpuset.flags); 2082 set_bit(CS_SCHED_LOAD_BALANCE, &top_cpuset.flags);
@@ -2035,6 +2119,66 @@ static void remove_tasks_in_empty_cpuset(struct cpuset *cs)
2035 } 2119 }
2036} 2120}
2037 2121
2122static void
2123hotplug_update_tasks_legacy(struct cpuset *cs,
2124 struct cpumask *new_cpus, nodemask_t *new_mems,
2125 bool cpus_updated, bool mems_updated)
2126{
2127 bool is_empty;
2128
2129 mutex_lock(&callback_mutex);
2130 cpumask_copy(cs->cpus_allowed, new_cpus);
2131 cpumask_copy(cs->effective_cpus, new_cpus);
2132 cs->mems_allowed = *new_mems;
2133 cs->effective_mems = *new_mems;
2134 mutex_unlock(&callback_mutex);
2135
2136 /*
2137 * Don't call update_tasks_cpumask() if the cpuset becomes empty,
2138 * as the tasks will be migratecd to an ancestor.
2139 */
2140 if (cpus_updated && !cpumask_empty(cs->cpus_allowed))
2141 update_tasks_cpumask(cs);
2142 if (mems_updated && !nodes_empty(cs->mems_allowed))
2143 update_tasks_nodemask(cs);
2144
2145 is_empty = cpumask_empty(cs->cpus_allowed) ||
2146 nodes_empty(cs->mems_allowed);
2147
2148 mutex_unlock(&cpuset_mutex);
2149
2150 /*
2151 * Move tasks to the nearest ancestor with execution resources,
2152 * This is full cgroup operation which will also call back into
2153 * cpuset. Should be done outside any lock.
2154 */
2155 if (is_empty)
2156 remove_tasks_in_empty_cpuset(cs);
2157
2158 mutex_lock(&cpuset_mutex);
2159}
2160
2161static void
2162hotplug_update_tasks(struct cpuset *cs,
2163 struct cpumask *new_cpus, nodemask_t *new_mems,
2164 bool cpus_updated, bool mems_updated)
2165{
2166 if (cpumask_empty(new_cpus))
2167 cpumask_copy(new_cpus, parent_cs(cs)->effective_cpus);
2168 if (nodes_empty(*new_mems))
2169 *new_mems = parent_cs(cs)->effective_mems;
2170
2171 mutex_lock(&callback_mutex);
2172 cpumask_copy(cs->effective_cpus, new_cpus);
2173 cs->effective_mems = *new_mems;
2174 mutex_unlock(&callback_mutex);
2175
2176 if (cpus_updated)
2177 update_tasks_cpumask(cs);
2178 if (mems_updated)
2179 update_tasks_nodemask(cs);
2180}
2181
2038/** 2182/**
2039 * cpuset_hotplug_update_tasks - update tasks in a cpuset for hotunplug 2183 * cpuset_hotplug_update_tasks - update tasks in a cpuset for hotunplug
2040 * @cs: cpuset in interest 2184 * @cs: cpuset in interest
@@ -2045,11 +2189,10 @@ static void remove_tasks_in_empty_cpuset(struct cpuset *cs)
2045 */ 2189 */
2046static void cpuset_hotplug_update_tasks(struct cpuset *cs) 2190static void cpuset_hotplug_update_tasks(struct cpuset *cs)
2047{ 2191{
2048 static cpumask_t off_cpus; 2192 static cpumask_t new_cpus;
2049 static nodemask_t off_mems; 2193 static nodemask_t new_mems;
2050 bool is_empty; 2194 bool cpus_updated;
2051 bool sane = cgroup_sane_behavior(cs->css.cgroup); 2195 bool mems_updated;
2052
2053retry: 2196retry:
2054 wait_event(cpuset_attach_wq, cs->attach_in_progress == 0); 2197 wait_event(cpuset_attach_wq, cs->attach_in_progress == 0);
2055 2198
@@ -2064,51 +2207,20 @@ retry:
2064 goto retry; 2207 goto retry;
2065 } 2208 }
2066 2209
2067 cpumask_andnot(&off_cpus, cs->cpus_allowed, top_cpuset.cpus_allowed); 2210 cpumask_and(&new_cpus, cs->cpus_allowed, parent_cs(cs)->effective_cpus);
2068 nodes_andnot(off_mems, cs->mems_allowed, top_cpuset.mems_allowed); 2211 nodes_and(new_mems, cs->mems_allowed, parent_cs(cs)->effective_mems);
2069
2070 mutex_lock(&callback_mutex);
2071 cpumask_andnot(cs->cpus_allowed, cs->cpus_allowed, &off_cpus);
2072 mutex_unlock(&callback_mutex);
2073
2074 /*
2075 * If sane_behavior flag is set, we need to update tasks' cpumask
2076 * for empty cpuset to take on ancestor's cpumask. Otherwise, don't
2077 * call update_tasks_cpumask() if the cpuset becomes empty, as
2078 * the tasks in it will be migrated to an ancestor.
2079 */
2080 if ((sane && cpumask_empty(cs->cpus_allowed)) ||
2081 (!cpumask_empty(&off_cpus) && !cpumask_empty(cs->cpus_allowed)))
2082 update_tasks_cpumask(cs);
2083 2212
2084 mutex_lock(&callback_mutex); 2213 cpus_updated = !cpumask_equal(&new_cpus, cs->effective_cpus);
2085 nodes_andnot(cs->mems_allowed, cs->mems_allowed, off_mems); 2214 mems_updated = !nodes_equal(new_mems, cs->effective_mems);
2086 mutex_unlock(&callback_mutex);
2087
2088 /*
2089 * If sane_behavior flag is set, we need to update tasks' nodemask
2090 * for empty cpuset to take on ancestor's nodemask. Otherwise, don't
2091 * call update_tasks_nodemask() if the cpuset becomes empty, as
2092 * the tasks in it will be migratd to an ancestor.
2093 */
2094 if ((sane && nodes_empty(cs->mems_allowed)) ||
2095 (!nodes_empty(off_mems) && !nodes_empty(cs->mems_allowed)))
2096 update_tasks_nodemask(cs);
2097 2215
2098 is_empty = cpumask_empty(cs->cpus_allowed) || 2216 if (cgroup_on_dfl(cs->css.cgroup))
2099 nodes_empty(cs->mems_allowed); 2217 hotplug_update_tasks(cs, &new_cpus, &new_mems,
2218 cpus_updated, mems_updated);
2219 else
2220 hotplug_update_tasks_legacy(cs, &new_cpus, &new_mems,
2221 cpus_updated, mems_updated);
2100 2222
2101 mutex_unlock(&cpuset_mutex); 2223 mutex_unlock(&cpuset_mutex);
2102
2103 /*
2104 * If sane_behavior flag is set, we'll keep tasks in empty cpusets.
2105 *
2106 * Otherwise move tasks to the nearest ancestor with execution
2107 * resources. This is full cgroup operation which will
2108 * also call back into cpuset. Should be done outside any lock.
2109 */
2110 if (!sane && is_empty)
2111 remove_tasks_in_empty_cpuset(cs);
2112} 2224}
2113 2225
2114/** 2226/**
@@ -2132,6 +2244,7 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
2132 static cpumask_t new_cpus; 2244 static cpumask_t new_cpus;
2133 static nodemask_t new_mems; 2245 static nodemask_t new_mems;
2134 bool cpus_updated, mems_updated; 2246 bool cpus_updated, mems_updated;
2247 bool on_dfl = cgroup_on_dfl(top_cpuset.css.cgroup);
2135 2248
2136 mutex_lock(&cpuset_mutex); 2249 mutex_lock(&cpuset_mutex);
2137 2250
@@ -2139,13 +2252,15 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
2139 cpumask_copy(&new_cpus, cpu_active_mask); 2252 cpumask_copy(&new_cpus, cpu_active_mask);
2140 new_mems = node_states[N_MEMORY]; 2253 new_mems = node_states[N_MEMORY];
2141 2254
2142 cpus_updated = !cpumask_equal(top_cpuset.cpus_allowed, &new_cpus); 2255 cpus_updated = !cpumask_equal(top_cpuset.effective_cpus, &new_cpus);
2143 mems_updated = !nodes_equal(top_cpuset.mems_allowed, new_mems); 2256 mems_updated = !nodes_equal(top_cpuset.effective_mems, new_mems);
2144 2257
2145 /* synchronize cpus_allowed to cpu_active_mask */ 2258 /* synchronize cpus_allowed to cpu_active_mask */
2146 if (cpus_updated) { 2259 if (cpus_updated) {
2147 mutex_lock(&callback_mutex); 2260 mutex_lock(&callback_mutex);
2148 cpumask_copy(top_cpuset.cpus_allowed, &new_cpus); 2261 if (!on_dfl)
2262 cpumask_copy(top_cpuset.cpus_allowed, &new_cpus);
2263 cpumask_copy(top_cpuset.effective_cpus, &new_cpus);
2149 mutex_unlock(&callback_mutex); 2264 mutex_unlock(&callback_mutex);
2150 /* we don't mess with cpumasks of tasks in top_cpuset */ 2265 /* we don't mess with cpumasks of tasks in top_cpuset */
2151 } 2266 }
@@ -2153,7 +2268,9 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
2153 /* synchronize mems_allowed to N_MEMORY */ 2268 /* synchronize mems_allowed to N_MEMORY */
2154 if (mems_updated) { 2269 if (mems_updated) {
2155 mutex_lock(&callback_mutex); 2270 mutex_lock(&callback_mutex);
2156 top_cpuset.mems_allowed = new_mems; 2271 if (!on_dfl)
2272 top_cpuset.mems_allowed = new_mems;
2273 top_cpuset.effective_mems = new_mems;
2157 mutex_unlock(&callback_mutex); 2274 mutex_unlock(&callback_mutex);
2158 update_tasks_nodemask(&top_cpuset); 2275 update_tasks_nodemask(&top_cpuset);
2159 } 2276 }
@@ -2228,6 +2345,9 @@ void __init cpuset_init_smp(void)
2228 top_cpuset.mems_allowed = node_states[N_MEMORY]; 2345 top_cpuset.mems_allowed = node_states[N_MEMORY];
2229 top_cpuset.old_mems_allowed = top_cpuset.mems_allowed; 2346 top_cpuset.old_mems_allowed = top_cpuset.mems_allowed;
2230 2347
2348 cpumask_copy(top_cpuset.effective_cpus, cpu_active_mask);
2349 top_cpuset.effective_mems = node_states[N_MEMORY];
2350
2231 register_hotmemory_notifier(&cpuset_track_online_nodes_nb); 2351 register_hotmemory_notifier(&cpuset_track_online_nodes_nb);
2232} 2352}
2233 2353
@@ -2244,23 +2364,17 @@ void __init cpuset_init_smp(void)
2244 2364
2245void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) 2365void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
2246{ 2366{
2247 struct cpuset *cpus_cs;
2248
2249 mutex_lock(&callback_mutex); 2367 mutex_lock(&callback_mutex);
2250 rcu_read_lock(); 2368 rcu_read_lock();
2251 cpus_cs = effective_cpumask_cpuset(task_cs(tsk)); 2369 guarantee_online_cpus(task_cs(tsk), pmask);
2252 guarantee_online_cpus(cpus_cs, pmask);
2253 rcu_read_unlock(); 2370 rcu_read_unlock();
2254 mutex_unlock(&callback_mutex); 2371 mutex_unlock(&callback_mutex);
2255} 2372}
2256 2373
2257void cpuset_cpus_allowed_fallback(struct task_struct *tsk) 2374void cpuset_cpus_allowed_fallback(struct task_struct *tsk)
2258{ 2375{
2259 struct cpuset *cpus_cs;
2260
2261 rcu_read_lock(); 2376 rcu_read_lock();
2262 cpus_cs = effective_cpumask_cpuset(task_cs(tsk)); 2377 do_set_cpus_allowed(tsk, task_cs(tsk)->effective_cpus);
2263 do_set_cpus_allowed(tsk, cpus_cs->cpus_allowed);
2264 rcu_read_unlock(); 2378 rcu_read_unlock();
2265 2379
2266 /* 2380 /*
@@ -2299,13 +2413,11 @@ void cpuset_init_current_mems_allowed(void)
2299 2413
2300nodemask_t cpuset_mems_allowed(struct task_struct *tsk) 2414nodemask_t cpuset_mems_allowed(struct task_struct *tsk)
2301{ 2415{
2302 struct cpuset *mems_cs;
2303 nodemask_t mask; 2416 nodemask_t mask;
2304 2417
2305 mutex_lock(&callback_mutex); 2418 mutex_lock(&callback_mutex);
2306 rcu_read_lock(); 2419 rcu_read_lock();
2307 mems_cs = effective_nodemask_cpuset(task_cs(tsk)); 2420 guarantee_online_mems(task_cs(tsk), &mask);
2308 guarantee_online_mems(mems_cs, &mask);
2309 rcu_read_unlock(); 2421 rcu_read_unlock();
2310 mutex_unlock(&callback_mutex); 2422 mutex_unlock(&callback_mutex);
2311 2423