diff options
author | Li Zefan <lizefan@huawei.com> | 2014-07-09 04:47:03 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-07-09 15:56:15 -0400 |
commit | e2b9a3d7d8f4ab2f3491b8ed2ac6af692a2269b2 (patch) | |
tree | 6c1b8cdb9ef14fe60c42ef0567598343491368c6 /kernel/cpuset.c | |
parent | 7b9a6ba56e9519ed5413a002dc0b0f01aa598bb5 (diff) |
cpuset: add cs->effective_cpus and cs->effective_mems
We're going to have separate user-configured masks and effective ones.
Eventually configured masks can only be changed by writing cpuset.cpus
and cpuset.mems, and they won't be restricted by parent cpuset. While
effective masks reflect cpu/memory hotplug and hierachical restriction,
and these are the real masks that apply to the tasks in the cpuset.
We calculate effective mask this way:
- top cpuset's effective_mask == online_mask, otherwise
- cpuset's effective_mask == configured_mask & parent effective_mask,
if the result is empty, it inherits parent effective mask.
Those behavior changes are for default hierarchy only. For legacy
hierachy, effective_mask and configured_mask are the same, so we won't
break old interfaces.
This patch adds the effective masks to struct cpuset and initializes
them. The effective masks of the top cpuset is the same with configured
masks, and a child cpuset inherits its parent's effective masks.
This won't introduce behavior change.
v2:
- s/real_{mems,cpus}_allowed/effective_{mems,cpus}, suggested by Tejun.
- don't init effective masks in cpuset_css_online() if !cgroup_on_dfl.
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 | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index f9d4807c869f..ef0974c73b4b 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -76,8 +76,14 @@ 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 | /* user-configured CPUs and Memory Nodes allow to tasks */ |
81 | cpumask_var_t cpus_allowed; | ||
82 | nodemask_t mems_allowed; | ||
83 | |||
84 | /* effective CPUs and Memory Nodes allow to tasks */ | ||
85 | cpumask_var_t effective_cpus; | ||
86 | nodemask_t effective_mems; | ||
81 | 87 | ||
82 | /* | 88 | /* |
83 | * This is old Memory Nodes tasks took on. | 89 | * This is old Memory Nodes tasks took on. |
@@ -376,13 +382,20 @@ static struct cpuset *alloc_trial_cpuset(struct cpuset *cs) | |||
376 | if (!trial) | 382 | if (!trial) |
377 | return NULL; | 383 | return NULL; |
378 | 384 | ||
379 | if (!alloc_cpumask_var(&trial->cpus_allowed, GFP_KERNEL)) { | 385 | if (!alloc_cpumask_var(&trial->cpus_allowed, GFP_KERNEL)) |
380 | kfree(trial); | 386 | goto free_cs; |
381 | return NULL; | 387 | if (!alloc_cpumask_var(&trial->effective_cpus, GFP_KERNEL)) |
382 | } | 388 | goto free_cpus; |
383 | cpumask_copy(trial->cpus_allowed, cs->cpus_allowed); | ||
384 | 389 | ||
390 | cpumask_copy(trial->cpus_allowed, cs->cpus_allowed); | ||
391 | cpumask_copy(trial->effective_cpus, cs->effective_cpus); | ||
385 | return trial; | 392 | return trial; |
393 | |||
394 | free_cpus: | ||
395 | free_cpumask_var(trial->cpus_allowed); | ||
396 | free_cs: | ||
397 | kfree(trial); | ||
398 | return NULL; | ||
386 | } | 399 | } |
387 | 400 | ||
388 | /** | 401 | /** |
@@ -391,6 +404,7 @@ static struct cpuset *alloc_trial_cpuset(struct cpuset *cs) | |||
391 | */ | 404 | */ |
392 | static void free_trial_cpuset(struct cpuset *trial) | 405 | static void free_trial_cpuset(struct cpuset *trial) |
393 | { | 406 | { |
407 | free_cpumask_var(trial->effective_cpus); | ||
394 | free_cpumask_var(trial->cpus_allowed); | 408 | free_cpumask_var(trial->cpus_allowed); |
395 | kfree(trial); | 409 | kfree(trial); |
396 | } | 410 | } |
@@ -1848,18 +1862,26 @@ cpuset_css_alloc(struct cgroup_subsys_state *parent_css) | |||
1848 | cs = kzalloc(sizeof(*cs), GFP_KERNEL); | 1862 | cs = kzalloc(sizeof(*cs), GFP_KERNEL); |
1849 | if (!cs) | 1863 | if (!cs) |
1850 | return ERR_PTR(-ENOMEM); | 1864 | return ERR_PTR(-ENOMEM); |
1851 | if (!alloc_cpumask_var(&cs->cpus_allowed, GFP_KERNEL)) { | 1865 | if (!alloc_cpumask_var(&cs->cpus_allowed, GFP_KERNEL)) |
1852 | kfree(cs); | 1866 | goto free_cs; |
1853 | return ERR_PTR(-ENOMEM); | 1867 | if (!alloc_cpumask_var(&cs->effective_cpus, GFP_KERNEL)) |
1854 | } | 1868 | goto free_cpus; |
1855 | 1869 | ||
1856 | set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags); | 1870 | set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags); |
1857 | cpumask_clear(cs->cpus_allowed); | 1871 | cpumask_clear(cs->cpus_allowed); |
1858 | nodes_clear(cs->mems_allowed); | 1872 | nodes_clear(cs->mems_allowed); |
1873 | cpumask_clear(cs->effective_cpus); | ||
1874 | nodes_clear(cs->effective_mems); | ||
1859 | fmeter_init(&cs->fmeter); | 1875 | fmeter_init(&cs->fmeter); |
1860 | cs->relax_domain_level = -1; | 1876 | cs->relax_domain_level = -1; |
1861 | 1877 | ||
1862 | return &cs->css; | 1878 | return &cs->css; |
1879 | |||
1880 | free_cpus: | ||
1881 | free_cpumask_var(cs->cpus_allowed); | ||
1882 | free_cs: | ||
1883 | kfree(cs); | ||
1884 | return ERR_PTR(-ENOMEM); | ||
1863 | } | 1885 | } |
1864 | 1886 | ||
1865 | static int cpuset_css_online(struct cgroup_subsys_state *css) | 1887 | static int cpuset_css_online(struct cgroup_subsys_state *css) |
@@ -1882,6 +1904,13 @@ static int cpuset_css_online(struct cgroup_subsys_state *css) | |||
1882 | 1904 | ||
1883 | cpuset_inc(); | 1905 | cpuset_inc(); |
1884 | 1906 | ||
1907 | mutex_lock(&callback_mutex); | ||
1908 | if (cgroup_on_dfl(cs->css.cgroup)) { | ||
1909 | cpumask_copy(cs->effective_cpus, parent->effective_cpus); | ||
1910 | cs->effective_mems = parent->effective_mems; | ||
1911 | } | ||
1912 | mutex_unlock(&callback_mutex); | ||
1913 | |||
1885 | if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags)) | 1914 | if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags)) |
1886 | goto out_unlock; | 1915 | goto out_unlock; |
1887 | 1916 | ||
@@ -1941,6 +1970,7 @@ static void cpuset_css_free(struct cgroup_subsys_state *css) | |||
1941 | { | 1970 | { |
1942 | struct cpuset *cs = css_cs(css); | 1971 | struct cpuset *cs = css_cs(css); |
1943 | 1972 | ||
1973 | free_cpumask_var(cs->effective_cpus); | ||
1944 | free_cpumask_var(cs->cpus_allowed); | 1974 | free_cpumask_var(cs->cpus_allowed); |
1945 | kfree(cs); | 1975 | kfree(cs); |
1946 | } | 1976 | } |
@@ -1969,9 +1999,13 @@ int __init cpuset_init(void) | |||
1969 | 1999 | ||
1970 | if (!alloc_cpumask_var(&top_cpuset.cpus_allowed, GFP_KERNEL)) | 2000 | if (!alloc_cpumask_var(&top_cpuset.cpus_allowed, GFP_KERNEL)) |
1971 | BUG(); | 2001 | BUG(); |
2002 | if (!alloc_cpumask_var(&top_cpuset.effective_cpus, GFP_KERNEL)) | ||
2003 | BUG(); | ||
1972 | 2004 | ||
1973 | cpumask_setall(top_cpuset.cpus_allowed); | 2005 | cpumask_setall(top_cpuset.cpus_allowed); |
1974 | nodes_setall(top_cpuset.mems_allowed); | 2006 | nodes_setall(top_cpuset.mems_allowed); |
2007 | cpumask_setall(top_cpuset.effective_cpus); | ||
2008 | nodes_setall(top_cpuset.effective_mems); | ||
1975 | 2009 | ||
1976 | fmeter_init(&top_cpuset.fmeter); | 2010 | fmeter_init(&top_cpuset.fmeter); |
1977 | set_bit(CS_SCHED_LOAD_BALANCE, &top_cpuset.flags); | 2011 | set_bit(CS_SCHED_LOAD_BALANCE, &top_cpuset.flags); |
@@ -2207,6 +2241,9 @@ void __init cpuset_init_smp(void) | |||
2207 | top_cpuset.mems_allowed = node_states[N_MEMORY]; | 2241 | top_cpuset.mems_allowed = node_states[N_MEMORY]; |
2208 | top_cpuset.old_mems_allowed = top_cpuset.mems_allowed; | 2242 | top_cpuset.old_mems_allowed = top_cpuset.mems_allowed; |
2209 | 2243 | ||
2244 | cpumask_copy(top_cpuset.effective_cpus, cpu_active_mask); | ||
2245 | top_cpuset.effective_mems = node_states[N_MEMORY]; | ||
2246 | |||
2210 | register_hotmemory_notifier(&cpuset_track_online_nodes_nb); | 2247 | register_hotmemory_notifier(&cpuset_track_online_nodes_nb); |
2211 | } | 2248 | } |
2212 | 2249 | ||