Commit 033fa1c5f5f73833598a0beb022c0048fb769dad
1 parent
2260e7fc1f
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
cgroup, cpuset: remove cgroup_subsys->post_clone()
Currently CGRP_CPUSET_CLONE_CHILDREN triggers ->post_clone(). Now that clone_children is cpuset specific, there's no reason to have this rather odd option activation mechanism in cgroup core. cpuset can check the flag from its ->css_allocate() and take the necessary action. Move cpuset_post_clone() logic to the end of cpuset_css_alloc() and remove cgroup_subsys->post_clone(). Loosely based on Glauber's "generalize post_clone into post_create" patch. Signed-off-by: Tejun Heo <tj@kernel.org> Original-patch-by: Glauber Costa <glommer@parallels.com> Original-patch: <1351686554-22592-2-git-send-email-glommer@parallels.com> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Glauber Costa <glommer@parallels.com>
Showing 4 changed files with 36 additions and 57 deletions Side-by-side Diff
Documentation/cgroups/cgroups.txt
... | ... | @@ -642,14 +642,6 @@ |
642 | 642 | |
643 | 643 | Called during task exit. |
644 | 644 | |
645 | -void post_clone(struct cgroup *cgrp) | |
646 | -(cgroup_mutex held by caller) | |
647 | - | |
648 | -Called during cgroup_create() to do any parameter | |
649 | -initialization which might be required before a task could attach. For | |
650 | -example, in cpusets, no task may attach before 'cpus' and 'mems' are set | |
651 | -up. | |
652 | - | |
653 | 645 | void bind(struct cgroup *root) |
654 | 646 | (cgroup_mutex held by caller) |
655 | 647 |
include/linux/cgroup.h
kernel/cgroup.c
... | ... | @@ -4142,10 +4142,6 @@ |
4142 | 4142 | if (err) |
4143 | 4143 | goto err_free_all; |
4144 | 4144 | } |
4145 | - /* At error, ->css_free() callback has to free assigned ID. */ | |
4146 | - if (test_bit(CGRP_CPUSET_CLONE_CHILDREN, &parent->flags) && | |
4147 | - ss->post_clone) | |
4148 | - ss->post_clone(cgrp); | |
4149 | 4145 | |
4150 | 4146 | if (ss->broken_hierarchy && !ss->warned_broken_hierarchy && |
4151 | 4147 | parent->parent) { |
kernel/cpuset.c
... | ... | @@ -1784,56 +1784,20 @@ |
1784 | 1784 | }; |
1785 | 1785 | |
1786 | 1786 | /* |
1787 | - * post_clone() is called during cgroup_create() when the | |
1788 | - * clone_children mount argument was specified. The cgroup | |
1789 | - * can not yet have any tasks. | |
1790 | - * | |
1791 | - * Currently we refuse to set up the cgroup - thereby | |
1792 | - * refusing the task to be entered, and as a result refusing | |
1793 | - * the sys_unshare() or clone() which initiated it - if any | |
1794 | - * sibling cpusets have exclusive cpus or mem. | |
1795 | - * | |
1796 | - * If this becomes a problem for some users who wish to | |
1797 | - * allow that scenario, then cpuset_post_clone() could be | |
1798 | - * changed to grant parent->cpus_allowed-sibling_cpus_exclusive | |
1799 | - * (and likewise for mems) to the new cgroup. Called with cgroup_mutex | |
1800 | - * held. | |
1801 | - */ | |
1802 | -static void cpuset_post_clone(struct cgroup *cgroup) | |
1803 | -{ | |
1804 | - struct cgroup *parent, *child; | |
1805 | - struct cpuset *cs, *parent_cs; | |
1806 | - | |
1807 | - parent = cgroup->parent; | |
1808 | - list_for_each_entry(child, &parent->children, sibling) { | |
1809 | - cs = cgroup_cs(child); | |
1810 | - if (is_mem_exclusive(cs) || is_cpu_exclusive(cs)) | |
1811 | - return; | |
1812 | - } | |
1813 | - cs = cgroup_cs(cgroup); | |
1814 | - parent_cs = cgroup_cs(parent); | |
1815 | - | |
1816 | - mutex_lock(&callback_mutex); | |
1817 | - cs->mems_allowed = parent_cs->mems_allowed; | |
1818 | - cpumask_copy(cs->cpus_allowed, parent_cs->cpus_allowed); | |
1819 | - mutex_unlock(&callback_mutex); | |
1820 | - return; | |
1821 | -} | |
1822 | - | |
1823 | -/* | |
1824 | 1787 | * cpuset_css_alloc - allocate a cpuset css |
1825 | 1788 | * cont: control group that the new cpuset will be part of |
1826 | 1789 | */ |
1827 | 1790 | |
1828 | 1791 | static struct cgroup_subsys_state *cpuset_css_alloc(struct cgroup *cont) |
1829 | 1792 | { |
1830 | - struct cpuset *cs; | |
1831 | - struct cpuset *parent; | |
1793 | + struct cgroup *parent_cg = cont->parent; | |
1794 | + struct cgroup *tmp_cg; | |
1795 | + struct cpuset *parent, *cs; | |
1832 | 1796 | |
1833 | - if (!cont->parent) { | |
1797 | + if (!parent_cg) | |
1834 | 1798 | return &top_cpuset.css; |
1835 | - } | |
1836 | - parent = cgroup_cs(cont->parent); | |
1799 | + parent = cgroup_cs(parent_cg); | |
1800 | + | |
1837 | 1801 | cs = kmalloc(sizeof(*cs), GFP_KERNEL); |
1838 | 1802 | if (!cs) |
1839 | 1803 | return ERR_PTR(-ENOMEM); |
... | ... | @@ -1855,7 +1819,36 @@ |
1855 | 1819 | |
1856 | 1820 | cs->parent = parent; |
1857 | 1821 | number_of_cpusets++; |
1858 | - return &cs->css ; | |
1822 | + | |
1823 | + if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &cont->flags)) | |
1824 | + goto skip_clone; | |
1825 | + | |
1826 | + /* | |
1827 | + * Clone @parent's configuration if CGRP_CPUSET_CLONE_CHILDREN is | |
1828 | + * set. This flag handling is implemented in cgroup core for | |
1829 | + * histrical reasons - the flag may be specified during mount. | |
1830 | + * | |
1831 | + * Currently, if any sibling cpusets have exclusive cpus or mem, we | |
1832 | + * refuse to clone the configuration - thereby refusing the task to | |
1833 | + * be entered, and as a result refusing the sys_unshare() or | |
1834 | + * clone() which initiated it. If this becomes a problem for some | |
1835 | + * users who wish to allow that scenario, then this could be | |
1836 | + * changed to grant parent->cpus_allowed-sibling_cpus_exclusive | |
1837 | + * (and likewise for mems) to the new cgroup. | |
1838 | + */ | |
1839 | + list_for_each_entry(tmp_cg, &parent_cg->children, sibling) { | |
1840 | + struct cpuset *tmp_cs = cgroup_cs(tmp_cg); | |
1841 | + | |
1842 | + if (is_mem_exclusive(tmp_cs) || is_cpu_exclusive(tmp_cs)) | |
1843 | + goto skip_clone; | |
1844 | + } | |
1845 | + | |
1846 | + mutex_lock(&callback_mutex); | |
1847 | + cs->mems_allowed = parent->mems_allowed; | |
1848 | + cpumask_copy(cs->cpus_allowed, parent->cpus_allowed); | |
1849 | + mutex_unlock(&callback_mutex); | |
1850 | +skip_clone: | |
1851 | + return &cs->css; | |
1859 | 1852 | } |
1860 | 1853 | |
1861 | 1854 | /* |
... | ... | @@ -1882,7 +1875,6 @@ |
1882 | 1875 | .css_free = cpuset_css_free, |
1883 | 1876 | .can_attach = cpuset_can_attach, |
1884 | 1877 | .attach = cpuset_attach, |
1885 | - .post_clone = cpuset_post_clone, | |
1886 | 1878 | .subsys_id = cpuset_subsys_id, |
1887 | 1879 | .base_cftypes = files, |
1888 | 1880 | .early_init = 1, |