diff options
author | Li Zefan <lizefan@huawei.com> | 2013-06-09 05:15:22 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-06-13 13:48:32 -0400 |
commit | 070b57fcacc9dfc23a180290079078373fb697e1 (patch) | |
tree | 12bec33a6fbcb8b4db4cd5f2938dd902f244070a /kernel/cpuset.c | |
parent | 33ad801dfb5c8b1127c72fdb745ce8c630150f3f (diff) |
cpuset: introduce effective_{cpumask|nodemask}_cpuset()
effective_cpumask_cpuset() returns an ancestor cpuset which has
non-empty cpumask.
If a cpuset is empty and the tasks in it need to update their
cpus_allowed, they take on the ancestor cpuset's cpumask.
This currently won't change any behavior, but it will later allow us
to keep tasks in empty cpusets.
Signed-off-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel/cpuset.c')
-rw-r--r-- | kernel/cpuset.c | 76 |
1 files changed, 65 insertions, 11 deletions
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 2b4554588a04..82ac1f862cbc 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -791,6 +791,45 @@ void rebuild_sched_domains(void) | |||
791 | mutex_unlock(&cpuset_mutex); | 791 | mutex_unlock(&cpuset_mutex); |
792 | } | 792 | } |
793 | 793 | ||
794 | /* | ||
795 | * effective_cpumask_cpuset - return nearest ancestor with non-empty cpus | ||
796 | * @cs: the cpuset in interest | ||
797 | * | ||
798 | * A cpuset's effective cpumask is the cpumask of the nearest ancestor | ||
799 | * with non-empty cpus. We use effective cpumask whenever: | ||
800 | * - we update tasks' cpus_allowed. (they take on the ancestor's cpumask | ||
801 | * if the cpuset they reside in has no cpus) | ||
802 | * - we want to retrieve task_cs(tsk)'s cpus_allowed. | ||
803 | * | ||
804 | * Called with cpuset_mutex held. cpuset_cpus_allowed_fallback() is an | ||
805 | * exception. See comments there. | ||
806 | */ | ||
807 | static struct cpuset *effective_cpumask_cpuset(struct cpuset *cs) | ||
808 | { | ||
809 | while (cpumask_empty(cs->cpus_allowed)) | ||
810 | cs = parent_cs(cs); | ||
811 | return cs; | ||
812 | } | ||
813 | |||
814 | /* | ||
815 | * effective_nodemask_cpuset - return nearest ancestor with non-empty mems | ||
816 | * @cs: the cpuset in interest | ||
817 | * | ||
818 | * A cpuset's effective nodemask is the nodemask of the nearest ancestor | ||
819 | * with non-empty memss. We use effective nodemask whenever: | ||
820 | * - we update tasks' mems_allowed. (they take on the ancestor's nodemask | ||
821 | * if the cpuset they reside in has no mems) | ||
822 | * - we want to retrieve task_cs(tsk)'s mems_allowed. | ||
823 | * | ||
824 | * Called with cpuset_mutex held. | ||
825 | */ | ||
826 | static struct cpuset *effective_nodemask_cpuset(struct cpuset *cs) | ||
827 | { | ||
828 | while (nodes_empty(cs->mems_allowed)) | ||
829 | cs = parent_cs(cs); | ||
830 | return cs; | ||
831 | } | ||
832 | |||
794 | /** | 833 | /** |
795 | * cpuset_change_cpumask - make a task's cpus_allowed the same as its cpuset's | 834 | * cpuset_change_cpumask - make a task's cpus_allowed the same as its cpuset's |
796 | * @tsk: task to test | 835 | * @tsk: task to test |
@@ -805,7 +844,10 @@ void rebuild_sched_domains(void) | |||
805 | static void cpuset_change_cpumask(struct task_struct *tsk, | 844 | static void cpuset_change_cpumask(struct task_struct *tsk, |
806 | struct cgroup_scanner *scan) | 845 | struct cgroup_scanner *scan) |
807 | { | 846 | { |
808 | set_cpus_allowed_ptr(tsk, ((cgroup_cs(scan->cg))->cpus_allowed)); | 847 | struct cpuset *cpus_cs; |
848 | |||
849 | cpus_cs = effective_cpumask_cpuset(cgroup_cs(scan->cg)); | ||
850 | set_cpus_allowed_ptr(tsk, cpus_cs->cpus_allowed); | ||
809 | } | 851 | } |
810 | 852 | ||
811 | /** | 853 | /** |
@@ -920,12 +962,14 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from, | |||
920 | const nodemask_t *to) | 962 | const nodemask_t *to) |
921 | { | 963 | { |
922 | struct task_struct *tsk = current; | 964 | struct task_struct *tsk = current; |
965 | struct cpuset *mems_cs; | ||
923 | 966 | ||
924 | tsk->mems_allowed = *to; | 967 | tsk->mems_allowed = *to; |
925 | 968 | ||
926 | do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL); | 969 | do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL); |
927 | 970 | ||
928 | guarantee_online_mems(task_cs(tsk),&tsk->mems_allowed); | 971 | mems_cs = effective_nodemask_cpuset(task_cs(tsk)); |
972 | guarantee_online_mems(mems_cs, &tsk->mems_allowed); | ||
929 | } | 973 | } |
930 | 974 | ||
931 | /* | 975 | /* |
@@ -1018,10 +1062,11 @@ static void update_tasks_nodemask(struct cpuset *cs, struct ptr_heap *heap) | |||
1018 | { | 1062 | { |
1019 | static nodemask_t newmems; /* protected by cpuset_mutex */ | 1063 | static nodemask_t newmems; /* protected by cpuset_mutex */ |
1020 | struct cgroup_scanner scan; | 1064 | struct cgroup_scanner scan; |
1065 | struct cpuset *mems_cs = effective_nodemask_cpuset(cs); | ||
1021 | 1066 | ||
1022 | cpuset_being_rebound = cs; /* causes mpol_dup() rebind */ | 1067 | cpuset_being_rebound = cs; /* causes mpol_dup() rebind */ |
1023 | 1068 | ||
1024 | guarantee_online_mems(cs, &newmems); | 1069 | guarantee_online_mems(mems_cs, &newmems); |
1025 | 1070 | ||
1026 | scan.cg = cs->css.cgroup; | 1071 | scan.cg = cs->css.cgroup; |
1027 | scan.test_task = NULL; | 1072 | scan.test_task = NULL; |
@@ -1405,6 +1450,8 @@ static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) | |||
1405 | struct cgroup *oldcgrp = cgroup_taskset_cur_cgroup(tset); | 1450 | struct cgroup *oldcgrp = cgroup_taskset_cur_cgroup(tset); |
1406 | struct cpuset *cs = cgroup_cs(cgrp); | 1451 | struct cpuset *cs = cgroup_cs(cgrp); |
1407 | struct cpuset *oldcs = cgroup_cs(oldcgrp); | 1452 | struct cpuset *oldcs = cgroup_cs(oldcgrp); |
1453 | struct cpuset *cpus_cs = effective_cpumask_cpuset(cs); | ||
1454 | struct cpuset *mems_cs = effective_nodemask_cpuset(cs); | ||
1408 | 1455 | ||
1409 | mutex_lock(&cpuset_mutex); | 1456 | mutex_lock(&cpuset_mutex); |
1410 | 1457 | ||
@@ -1412,9 +1459,9 @@ static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) | |||
1412 | if (cs == &top_cpuset) | 1459 | if (cs == &top_cpuset) |
1413 | cpumask_copy(cpus_attach, cpu_possible_mask); | 1460 | cpumask_copy(cpus_attach, cpu_possible_mask); |
1414 | else | 1461 | else |
1415 | guarantee_online_cpus(cs, cpus_attach); | 1462 | guarantee_online_cpus(cpus_cs, cpus_attach); |
1416 | 1463 | ||
1417 | guarantee_online_mems(cs, &cpuset_attach_nodemask_to); | 1464 | guarantee_online_mems(mems_cs, &cpuset_attach_nodemask_to); |
1418 | 1465 | ||
1419 | cgroup_taskset_for_each(task, cgrp, tset) { | 1466 | cgroup_taskset_for_each(task, cgrp, tset) { |
1420 | /* | 1467 | /* |
@@ -1434,9 +1481,11 @@ static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) | |||
1434 | cpuset_attach_nodemask_to = cs->mems_allowed; | 1481 | cpuset_attach_nodemask_to = cs->mems_allowed; |
1435 | mm = get_task_mm(leader); | 1482 | mm = get_task_mm(leader); |
1436 | if (mm) { | 1483 | if (mm) { |
1484 | struct cpuset *mems_oldcs = effective_nodemask_cpuset(oldcs); | ||
1485 | |||
1437 | mpol_rebind_mm(mm, &cpuset_attach_nodemask_to); | 1486 | mpol_rebind_mm(mm, &cpuset_attach_nodemask_to); |
1438 | if (is_memory_migrate(cs)) | 1487 | if (is_memory_migrate(cs)) |
1439 | cpuset_migrate_mm(mm, &oldcs->mems_allowed, | 1488 | cpuset_migrate_mm(mm, &mems_oldcs->mems_allowed, |
1440 | &cpuset_attach_nodemask_to); | 1489 | &cpuset_attach_nodemask_to); |
1441 | mmput(mm); | 1490 | mmput(mm); |
1442 | } | 1491 | } |
@@ -2186,20 +2235,23 @@ void __init cpuset_init_smp(void) | |||
2186 | 2235 | ||
2187 | void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) | 2236 | void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) |
2188 | { | 2237 | { |
2238 | struct cpuset *cpus_cs; | ||
2239 | |||
2189 | mutex_lock(&callback_mutex); | 2240 | mutex_lock(&callback_mutex); |
2190 | task_lock(tsk); | 2241 | task_lock(tsk); |
2191 | guarantee_online_cpus(task_cs(tsk), pmask); | 2242 | cpus_cs = effective_cpumask_cpuset(task_cs(tsk)); |
2243 | guarantee_online_cpus(cpus_cs, pmask); | ||
2192 | task_unlock(tsk); | 2244 | task_unlock(tsk); |
2193 | mutex_unlock(&callback_mutex); | 2245 | mutex_unlock(&callback_mutex); |
2194 | } | 2246 | } |
2195 | 2247 | ||
2196 | void cpuset_cpus_allowed_fallback(struct task_struct *tsk) | 2248 | void cpuset_cpus_allowed_fallback(struct task_struct *tsk) |
2197 | { | 2249 | { |
2198 | const struct cpuset *cs; | 2250 | const struct cpuset *cpus_cs; |
2199 | 2251 | ||
2200 | rcu_read_lock(); | 2252 | rcu_read_lock(); |
2201 | cs = task_cs(tsk); | 2253 | cpus_cs = effective_cpumask_cpuset(task_cs(tsk)); |
2202 | do_set_cpus_allowed(tsk, cs->cpus_allowed); | 2254 | do_set_cpus_allowed(tsk, cpus_cs->cpus_allowed); |
2203 | rcu_read_unlock(); | 2255 | rcu_read_unlock(); |
2204 | 2256 | ||
2205 | /* | 2257 | /* |
@@ -2238,11 +2290,13 @@ void cpuset_init_current_mems_allowed(void) | |||
2238 | 2290 | ||
2239 | nodemask_t cpuset_mems_allowed(struct task_struct *tsk) | 2291 | nodemask_t cpuset_mems_allowed(struct task_struct *tsk) |
2240 | { | 2292 | { |
2293 | struct cpuset *mems_cs; | ||
2241 | nodemask_t mask; | 2294 | nodemask_t mask; |
2242 | 2295 | ||
2243 | mutex_lock(&callback_mutex); | 2296 | mutex_lock(&callback_mutex); |
2244 | task_lock(tsk); | 2297 | task_lock(tsk); |
2245 | guarantee_online_mems(task_cs(tsk), &mask); | 2298 | mems_cs = effective_nodemask_cpuset(task_cs(tsk)); |
2299 | guarantee_online_mems(mems_cs, &mask); | ||
2246 | task_unlock(tsk); | 2300 | task_unlock(tsk); |
2247 | mutex_unlock(&callback_mutex); | 2301 | mutex_unlock(&callback_mutex); |
2248 | 2302 | ||