diff options
author | Li Zefan <lizefan@huawei.com> | 2014-07-09 04:48:32 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-07-09 15:56:17 -0400 |
commit | ae1c802382f7af60aa54879fb4f5920a9df1ff48 (patch) | |
tree | 90a1cc5209552ab0046b423d64b58d6a8cdc5eab | |
parent | 39bd0d15eca5af15ee1492964f317ecdb024a9d6 (diff) |
cpuset: apply cs->effective_{cpus,mems}
Now we can use cs->effective_{cpus,mems} as effective masks. It's
used whenever:
- we update tasks' cpus_allowed/mems_allowed,
- we want to retrieve tasks_cs(tsk)'s cpus_allowed/mems_allowed.
They actually replace effective_{cpu,node}mask_cpuset().
effective_mask == configured_mask & parent effective_mask except when
the reault is empty, in which case it inherits parent effective_mask.
The result equals the mask computed from effective_{cpu,node}mask_cpuset().
This won't affect the original legacy hierarchy, because in this case we
make sure the effective masks are always the same with user-configured
masks.
Signed-off-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
-rw-r--r-- | kernel/cpuset.c | 83 |
1 files changed, 14 insertions, 69 deletions
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index e4c31e6b8716..820870a715f8 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -313,9 +313,9 @@ static struct file_system_type cpuset_fs_type = { | |||
313 | */ | 313 | */ |
314 | static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask) | 314 | static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask) |
315 | { | 315 | { |
316 | while (!cpumask_intersects(cs->cpus_allowed, cpu_online_mask)) | 316 | while (!cpumask_intersects(cs->effective_cpus, cpu_online_mask)) |
317 | cs = parent_cs(cs); | 317 | cs = parent_cs(cs); |
318 | cpumask_and(pmask, cs->cpus_allowed, cpu_online_mask); | 318 | cpumask_and(pmask, cs->effective_cpus, cpu_online_mask); |
319 | } | 319 | } |
320 | 320 | ||
321 | /* | 321 | /* |
@@ -331,9 +331,9 @@ static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask) | |||
331 | */ | 331 | */ |
332 | static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask) | 332 | static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask) |
333 | { | 333 | { |
334 | while (!nodes_intersects(cs->mems_allowed, node_states[N_MEMORY])) | 334 | while (!nodes_intersects(cs->effective_mems, node_states[N_MEMORY])) |
335 | cs = parent_cs(cs); | 335 | cs = parent_cs(cs); |
336 | nodes_and(*pmask, cs->mems_allowed, node_states[N_MEMORY]); | 336 | nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]); |
337 | } | 337 | } |
338 | 338 | ||
339 | /* | 339 | /* |
@@ -795,45 +795,6 @@ void rebuild_sched_domains(void) | |||
795 | mutex_unlock(&cpuset_mutex); | 795 | mutex_unlock(&cpuset_mutex); |
796 | } | 796 | } |
797 | 797 | ||
798 | /* | ||
799 | * effective_cpumask_cpuset - return nearest ancestor with non-empty cpus | ||
800 | * @cs: the cpuset in interest | ||
801 | * | ||
802 | * A cpuset's effective cpumask is the cpumask of the nearest ancestor | ||
803 | * with non-empty cpus. We use effective cpumask whenever: | ||
804 | * - we update tasks' cpus_allowed. (they take on the ancestor's cpumask | ||
805 | * if the cpuset they reside in has no cpus) | ||
806 | * - we want to retrieve task_cs(tsk)'s cpus_allowed. | ||
807 | * | ||
808 | * Called with cpuset_mutex held. cpuset_cpus_allowed_fallback() is an | ||
809 | * exception. See comments there. | ||
810 | */ | ||
811 | static struct cpuset *effective_cpumask_cpuset(struct cpuset *cs) | ||
812 | { | ||
813 | while (cpumask_empty(cs->cpus_allowed)) | ||
814 | cs = parent_cs(cs); | ||
815 | return cs; | ||
816 | } | ||
817 | |||
818 | /* | ||
819 | * effective_nodemask_cpuset - return nearest ancestor with non-empty mems | ||
820 | * @cs: the cpuset in interest | ||
821 | * | ||
822 | * A cpuset's effective nodemask is the nodemask of the nearest ancestor | ||
823 | * with non-empty memss. We use effective nodemask whenever: | ||
824 | * - we update tasks' mems_allowed. (they take on the ancestor's nodemask | ||
825 | * if the cpuset they reside in has no mems) | ||
826 | * - we want to retrieve task_cs(tsk)'s mems_allowed. | ||
827 | * | ||
828 | * Called with cpuset_mutex held. | ||
829 | */ | ||
830 | static struct cpuset *effective_nodemask_cpuset(struct cpuset *cs) | ||
831 | { | ||
832 | while (nodes_empty(cs->mems_allowed)) | ||
833 | cs = parent_cs(cs); | ||
834 | return cs; | ||
835 | } | ||
836 | |||
837 | /** | 798 | /** |
838 | * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. | 799 | * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. |
839 | * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed | 800 | * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed |
@@ -844,13 +805,12 @@ static struct cpuset *effective_nodemask_cpuset(struct cpuset *cs) | |||
844 | */ | 805 | */ |
845 | static void update_tasks_cpumask(struct cpuset *cs) | 806 | static void update_tasks_cpumask(struct cpuset *cs) |
846 | { | 807 | { |
847 | struct cpuset *cpus_cs = effective_cpumask_cpuset(cs); | ||
848 | struct css_task_iter it; | 808 | struct css_task_iter it; |
849 | struct task_struct *task; | 809 | struct task_struct *task; |
850 | 810 | ||
851 | css_task_iter_start(&cs->css, &it); | 811 | css_task_iter_start(&cs->css, &it); |
852 | while ((task = css_task_iter_next(&it))) | 812 | while ((task = css_task_iter_next(&it))) |
853 | set_cpus_allowed_ptr(task, cpus_cs->cpus_allowed); | 813 | set_cpus_allowed_ptr(task, cs->effective_cpus); |
854 | css_task_iter_end(&it); | 814 | css_task_iter_end(&it); |
855 | } | 815 | } |
856 | 816 | ||
@@ -988,15 +948,13 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from, | |||
988 | const nodemask_t *to) | 948 | const nodemask_t *to) |
989 | { | 949 | { |
990 | struct task_struct *tsk = current; | 950 | struct task_struct *tsk = current; |
991 | struct cpuset *mems_cs; | ||
992 | 951 | ||
993 | tsk->mems_allowed = *to; | 952 | tsk->mems_allowed = *to; |
994 | 953 | ||
995 | do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL); | 954 | do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL); |
996 | 955 | ||
997 | rcu_read_lock(); | 956 | rcu_read_lock(); |
998 | mems_cs = effective_nodemask_cpuset(task_cs(tsk)); | 957 | guarantee_online_mems(task_cs(tsk), &tsk->mems_allowed); |
999 | guarantee_online_mems(mems_cs, &tsk->mems_allowed); | ||
1000 | rcu_read_unlock(); | 958 | rcu_read_unlock(); |
1001 | } | 959 | } |
1002 | 960 | ||
@@ -1065,13 +1023,12 @@ static void *cpuset_being_rebound; | |||
1065 | static void update_tasks_nodemask(struct cpuset *cs) | 1023 | static void update_tasks_nodemask(struct cpuset *cs) |
1066 | { | 1024 | { |
1067 | static nodemask_t newmems; /* protected by cpuset_mutex */ | 1025 | static nodemask_t newmems; /* protected by cpuset_mutex */ |
1068 | struct cpuset *mems_cs = effective_nodemask_cpuset(cs); | ||
1069 | struct css_task_iter it; | 1026 | struct css_task_iter it; |
1070 | struct task_struct *task; | 1027 | struct task_struct *task; |
1071 | 1028 | ||
1072 | cpuset_being_rebound = cs; /* causes mpol_dup() rebind */ | 1029 | cpuset_being_rebound = cs; /* causes mpol_dup() rebind */ |
1073 | 1030 | ||
1074 | guarantee_online_mems(mems_cs, &newmems); | 1031 | guarantee_online_mems(cs, &newmems); |
1075 | 1032 | ||
1076 | /* | 1033 | /* |
1077 | * The mpol_rebind_mm() call takes mmap_sem, which we couldn't | 1034 | * The mpol_rebind_mm() call takes mmap_sem, which we couldn't |
@@ -1497,8 +1454,6 @@ static void cpuset_attach(struct cgroup_subsys_state *css, | |||
1497 | struct task_struct *leader = cgroup_taskset_first(tset); | 1454 | struct task_struct *leader = cgroup_taskset_first(tset); |
1498 | struct cpuset *cs = css_cs(css); | 1455 | struct cpuset *cs = css_cs(css); |
1499 | struct cpuset *oldcs = cpuset_attach_old_cs; | 1456 | struct cpuset *oldcs = cpuset_attach_old_cs; |
1500 | struct cpuset *cpus_cs = effective_cpumask_cpuset(cs); | ||
1501 | struct cpuset *mems_cs = effective_nodemask_cpuset(cs); | ||
1502 | 1457 | ||
1503 | mutex_lock(&cpuset_mutex); | 1458 | mutex_lock(&cpuset_mutex); |
1504 | 1459 | ||
@@ -1506,9 +1461,9 @@ static void cpuset_attach(struct cgroup_subsys_state *css, | |||
1506 | if (cs == &top_cpuset) | 1461 | if (cs == &top_cpuset) |
1507 | cpumask_copy(cpus_attach, cpu_possible_mask); | 1462 | cpumask_copy(cpus_attach, cpu_possible_mask); |
1508 | else | 1463 | else |
1509 | guarantee_online_cpus(cpus_cs, cpus_attach); | 1464 | guarantee_online_cpus(cs, cpus_attach); |
1510 | 1465 | ||
1511 | guarantee_online_mems(mems_cs, &cpuset_attach_nodemask_to); | 1466 | guarantee_online_mems(cs, &cpuset_attach_nodemask_to); |
1512 | 1467 | ||
1513 | cgroup_taskset_for_each(task, tset) { | 1468 | cgroup_taskset_for_each(task, tset) { |
1514 | /* | 1469 | /* |
@@ -1525,11 +1480,9 @@ static void cpuset_attach(struct cgroup_subsys_state *css, | |||
1525 | * Change mm, possibly for multiple threads in a threadgroup. This is | 1480 | * Change mm, possibly for multiple threads in a threadgroup. This is |
1526 | * expensive and may sleep. | 1481 | * expensive and may sleep. |
1527 | */ | 1482 | */ |
1528 | cpuset_attach_nodemask_to = cs->mems_allowed; | 1483 | cpuset_attach_nodemask_to = cs->effective_mems; |
1529 | mm = get_task_mm(leader); | 1484 | mm = get_task_mm(leader); |
1530 | if (mm) { | 1485 | if (mm) { |
1531 | struct cpuset *mems_oldcs = effective_nodemask_cpuset(oldcs); | ||
1532 | |||
1533 | mpol_rebind_mm(mm, &cpuset_attach_nodemask_to); | 1486 | mpol_rebind_mm(mm, &cpuset_attach_nodemask_to); |
1534 | 1487 | ||
1535 | /* | 1488 | /* |
@@ -1540,7 +1493,7 @@ static void cpuset_attach(struct cgroup_subsys_state *css, | |||
1540 | * mm from. | 1493 | * mm from. |
1541 | */ | 1494 | */ |
1542 | if (is_memory_migrate(cs)) { | 1495 | if (is_memory_migrate(cs)) { |
1543 | cpuset_migrate_mm(mm, &mems_oldcs->old_mems_allowed, | 1496 | cpuset_migrate_mm(mm, &oldcs->old_mems_allowed, |
1544 | &cpuset_attach_nodemask_to); | 1497 | &cpuset_attach_nodemask_to); |
1545 | } | 1498 | } |
1546 | mmput(mm); | 1499 | mmput(mm); |
@@ -2331,23 +2284,17 @@ void __init cpuset_init_smp(void) | |||
2331 | 2284 | ||
2332 | void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) | 2285 | void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) |
2333 | { | 2286 | { |
2334 | struct cpuset *cpus_cs; | ||
2335 | |||
2336 | mutex_lock(&callback_mutex); | 2287 | mutex_lock(&callback_mutex); |
2337 | rcu_read_lock(); | 2288 | rcu_read_lock(); |
2338 | cpus_cs = effective_cpumask_cpuset(task_cs(tsk)); | 2289 | guarantee_online_cpus(task_cs(tsk), pmask); |
2339 | guarantee_online_cpus(cpus_cs, pmask); | ||
2340 | rcu_read_unlock(); | 2290 | rcu_read_unlock(); |
2341 | mutex_unlock(&callback_mutex); | 2291 | mutex_unlock(&callback_mutex); |
2342 | } | 2292 | } |
2343 | 2293 | ||
2344 | void cpuset_cpus_allowed_fallback(struct task_struct *tsk) | 2294 | void cpuset_cpus_allowed_fallback(struct task_struct *tsk) |
2345 | { | 2295 | { |
2346 | struct cpuset *cpus_cs; | ||
2347 | |||
2348 | rcu_read_lock(); | 2296 | rcu_read_lock(); |
2349 | cpus_cs = effective_cpumask_cpuset(task_cs(tsk)); | 2297 | do_set_cpus_allowed(tsk, task_cs(tsk)->effective_cpus); |
2350 | do_set_cpus_allowed(tsk, cpus_cs->cpus_allowed); | ||
2351 | rcu_read_unlock(); | 2298 | rcu_read_unlock(); |
2352 | 2299 | ||
2353 | /* | 2300 | /* |
@@ -2386,13 +2333,11 @@ void cpuset_init_current_mems_allowed(void) | |||
2386 | 2333 | ||
2387 | nodemask_t cpuset_mems_allowed(struct task_struct *tsk) | 2334 | nodemask_t cpuset_mems_allowed(struct task_struct *tsk) |
2388 | { | 2335 | { |
2389 | struct cpuset *mems_cs; | ||
2390 | nodemask_t mask; | 2336 | nodemask_t mask; |
2391 | 2337 | ||
2392 | mutex_lock(&callback_mutex); | 2338 | mutex_lock(&callback_mutex); |
2393 | rcu_read_lock(); | 2339 | rcu_read_lock(); |
2394 | mems_cs = effective_nodemask_cpuset(task_cs(tsk)); | 2340 | guarantee_online_mems(task_cs(tsk), &mask); |
2395 | guarantee_online_mems(mems_cs, &mask); | ||
2396 | rcu_read_unlock(); | 2341 | rcu_read_unlock(); |
2397 | mutex_unlock(&callback_mutex); | 2342 | mutex_unlock(&callback_mutex); |
2398 | 2343 | ||