cgroup: drop module support and cgroup_root_mutex
Subsystems (12)
Tejun Heo
maintainerPATCH v2 1/1 cgroup: drop module support and cgroup_root_mutex
Hello,
This is the second take. Changes from the last take[L] are
* Updated to reflect changes in fe1217c4f3f7 ("net: net_cls: move cgroupfs classid handling into core").
* Rebased on top of the current linus#master + some cgroup fix patches.
There's only one controller which makes use of the module support - net_prio, which, non-coincidentally, isn't an actual resource controller. It's highly unlikely that the actual resource controlling controllers are gonna be made modular and we aren't gonna add more non-resource controllers either, so the value of module support is strictly restricted to the particular controller.
The controller is fairly simple while module support in cgroup core adds quite a bit of complexity. Building the one controller as module only saves less than half-page in vmlinux, which really can't justify the additional complexity and (minute but existing) runtime overhead.
This patchset makes net_prio config options bool so that it can't be built as modules and drops module support from cgroup core, which in turn facilitates further simplification leading to removal of cgroup_root_mutex by allowing iterating subsystems outside the mutexes.
This patchset contains the following six patches.
0001-cgroup-make-CONFIG_CGROUP_NET_PRIO-bool-and-drop-unn.patch 0002-cgroup-drop-module-support.patch 0003-cgroup-clean-up-cgroup_subsys-names-and-initializati.patch 0004-cgroup-rename-cgroup_subsys-subsys_id-to-id.patch 0005-cgroup-update-locking-in-cgroup_show_options.patch 0006-cgroup-remove-cgroup_root_mutex.patch
0001-0002 drop cgroup module support.
0003-0004 are cleanups.
0005-0006 remove cgroup_root_mutex.
The patchset is on top of
linus#master 54c0a4b46150 ("Merge branch 'akpm' (incoming from Andrew)")
+ [1] [PATCHSET cgroup/for-3.14-fixes] cgroup: four misc fixes
+ [2] [PATCH] arm, pm, vmpressure: add missing slab.h includes
and also available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-simplify
diffstat follows. Thanks.
block/blk-cgroup.c | 9 block/blk-cgroup.h | 2 fs/bio.c | 2 include/linux/cgroup.h | 38 --- include/linux/cgroup_subsys.h | 30 +-- include/linux/hugetlb_cgroup.h | 2 include/linux/memcontrol.h | 2 include/net/cls_cgroup.h | 2 include/net/netprio_cgroup.h | 17 - kernel/cgroup.c | 394 ++++++----------------------------------- kernel/cgroup_freezer.c | 8 kernel/cpuset.c | 10 - kernel/events/core.c | 8 kernel/sched/core.c | 6 kernel/sched/cpuacct.c | 6 mm/hugetlb_cgroup.c | 9 mm/memcontrol.c | 22 +- net/Kconfig | 2 net/core/netclassid_cgroup.c | 13 - net/core/netprio_cgroup.c | 37 --- net/ipv4/tcp_memcontrol.c | 2 security/device_cgroup.c | 8 22 files changed, 128 insertions(+), 501 deletions(-)
Thanks.
--
tejun
[L] http://lkml.kernel.org/g/<1389982317-22225-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
[1] http://lkml.kernel.org/g/<1390923125-4369-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
[2] http://lkml.kernel.org/g/<20140128221922.GC16060-9pTldWuhBndy/[email protected]>
Tejun Heo
maintainerPATCH 1/6 cgroup: make CONFIG_CGROUP_NET_PRIO bool and drop unnecessary init_netclassid_cgroup()
net_prio is the only cgroup which is allowed to be built as a module. The savings from allowing one controller to be built as a module are tiny especially given that cgroup module support itself adds quite a bit of complexity.
Given that none of other controllers has much chance of being made a module and that we're unlikely to add new modular controllers, the added complexity is simply not justifiable.
As a first step to drop cgroup module support, this patch changes the config option to bool from tristate and drops module related code from it.
Also, while an earlier commit fe1217c4f3f7 ("net: net_cls: move cgroupfs classid handling into core") dropped module support from net_cls cgroup, it retained a call to cgroup_load_subsys(), which is noop for built-in controllers. Drop it along with init_netclassid_cgroup().
v2: Removed modular version of task_netprioidx() in
include/net/netprio_cgroup.h as suggested by Li Zefan.
v3: Rebased on top of fe1217c4f3f7 ("net: net_cls: move cgroupfs
classid handling into core"). net_cls cgroup part is mostly dropped except for removal of init_netclassid_cgroup().
--- include/net/netprio_cgroup.h | 15 --------------- net/Kconfig | 2 +- net/core/netclassid_cgroup.c | 6 ------ net/core/netprio_cgroup.c | 32 ++------------------------------ 4 files changed, 3 insertions(+), 52 deletions(-)
include/net/netprio_cgroup.h +0 -15
@@ -27,7 +27,6 @@ struct netprio_map {void sock_update_netprioidx (struct sock *sk); -#if IS_BUILTIN (CONFIG_CGROUP_NET_PRIO )static inline u32 task_netprioidx (struct task_struct *p) {struct cgroup_subsys_state *css;
@@ -39,20 +38,6 @@ static inline u32 task_netprioidx(struct task_struct *p)rcu_read_unlock (); return idx; } -#elif IS_MODULE(CONFIG_CGROUP_NET_PRIO) -static inline u32 task_netprioidx (struct task_struct *p) -{ -struct cgroup_subsys_state *css; -u32 idx =0 ; - -rcu_read_lock (); - css =task_css (p, net_prio_subsys_id); -if (css) - idx = css->cgroup->id; -rcu_read_unlock (); -return idx; -} -#endif #else /* !CONFIG_CGROUP_NET_PRIO */ static inline u32 task_netprioidx (struct task_struct *p) {
net/Kconfig +1 -1
@@ -239,7 +239,7 @@ config XPS default y config CGROUP_NET_PRIO - tristate "Network priority cgroup" + bool "Network priority cgroup" depends on CGROUPS ---help--- Cgroup subsystem for use in assigning processes to network priorities on
net/core/netclassid_cgroup.c +0 -6
@@ -112,9 +112,3 @@ struct cgroup_subsys net_cls_subsys = { .base_cftypes = ss_files, .module = THIS_MODULE, }; - -static int __init init_netclassid_cgroup (void ) -{ -return cgroup_load_subsys (&net_cls_subsys); -} -__initcall (init_netclassid_cgroup);
net/core/netprio_cgroup.c +2 -30
@@ -283,37 +283,9 @@ static struct notifier_block netprio_device_notifier = {static int __init init_cgroup_netprio (void ) { -int ret; - - ret =cgroup_load_subsys (&net_prio_subsys); -if (ret) - goto out; -register_netdevice_notifier (&netprio_device_notifier); - -out: -return ret; -} - -static void __exit exit_cgroup_netprio(void) -{ -struct netprio_map *old; -struct net_device *dev; - -unregister_netdevice_notifier (&netprio_device_notifier); - -cgroup_unload_subsys (&net_prio_subsys); - -rtnl_lock (); -for_each_netdev (&init_net, dev) { - old =rtnl_dereference (dev->priomap); -RCU_INIT_POINTER (dev->priomap,NULL ); -if (old) -kfree_rcu (old, rcu); - } -rtnl_unlock (); +return 0 ; } -module_init (init_cgroup_netprio); -module_exit (exit_cgroup_netprio); +subsys_initcall (init_cgroup_netprio);MODULE_LICENSE ("GPL v2" );
Signature · 1 line
1.8.5.3
Tejun Heo
maintainerPATCH 2/6 cgroup: drop module support
In reply to Tejun HeoWith module supported dropped from net_prio, no controller is using cgroup module support. None of actual resource controllers can be built as a module and we aren't gonna add new controllers which don't control resources. This patch drops module support from cgroup.
* cgroup_[un]load_subsys() and cgroup_subsys->module removed.
* As there's no point in distinguishing IS_BUILTIN() and IS_MODULE(), cgroup_subsys.h now uses IS_ENABLED() directly.
* enum cgroup_subsys_id now exactly matches the list of enabled controllers as ordered in cgroup_subsys.h.
* cgroup_subsys[] is now a contiguously occupied array. Size specification is no longer necessary and dropped.
* for_each_builtin_subsys() is removed and for_each_subsys() is updated to not require any locking.
* module ref handling is removed from rebind_subsystems().
* Module related comments dropped.
v2: Rebased on top of fe1217c4f3f7 ("net: net_cls: move cgroupfs
classid handling into core").
--- block/blk-cgroup.c | 1 - include/linux/cgroup.h | 29 +---- include/linux/cgroup_subsys.h | 24 ++-- kernel/cgroup.c | 287 +++--------------------------------------- net/core/netclassid_cgroup.c | 1 - net/core/netprio_cgroup.c | 1 - 6 files changed, 33 insertions(+), 310 deletions(-)
block/blk-cgroup.c +0 -1
@@ -914,7 +914,6 @@ struct cgroup_subsys blkio_subsys = { .can_attach = blkcg_can_attach, .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, - .module = THIS_MODULE, };EXPORT_SYMBOL_GPL (blkio_subsys);
include/linux/cgroup.h +4 -25
@@ -37,28 +37,13 @@ extern void cgroup_post_fork(struct task_struct *p);extern void cgroup_exit (struct task_struct *p,int run_callbacks);extern int cgroupstats_build (struct cgroupstats *stats,struct dentry *dentry); -extern int cgroup_load_subsys (struct cgroup_subsys *ss); -extern void cgroup_unload_subsys (struct cgroup_subsys *ss);extern int proc_cgroup_show (struct seq_file *,void *); -/* -* Define the enumeration of all cgroup subsystems. -* -* We define ids for builtin subsystems and then modular ones. -*/ +/* define the enumeration of all cgroup subsystems */ #define SUBSYS (_x) _x ## _subsys_id,enum cgroup_subsys_id { -#define IS_SUBSYS_ENABLED(option) IS_BUILTIN(option)#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED -CGROUP_BUILTIN_SUBSYS_COUNT , - - __CGROUP_SUBSYS_TEMP_PLACEHOLDER =CGROUP_BUILTIN_SUBSYS_COUNT -1 , - -#define IS_SUBSYS_ENABLED(option) IS_MODULE(option) -#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED CGROUP_SUBSYS_COUNT, };#undef SUBSYS
@@ -370,10 +355,9 @@ struct css_set {struct list_head cgrp_links;/* -* Set of subsystem states, one for each subsystem. This array -* is immutable after creation apart from the init_css_set -* during subsystem registration (at boot time) and modular subsystem -* loading/unloading. +* Set of subsystem states, one for each subsystem. This array is +* immutable after creation apart from the init_css_set during +* subsystem registration (at boot time). */ struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT ];
@@ -620,15 +604,10 @@ struct cgroup_subsys {/* base cftypes, automatically [de]registered with subsys itself */ struct cftype *base_cftypes;struct cftype_set base_cftset; - -/* should be defined only by modular subsystems */ -struct module *module; };#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys; -#define IS_SUBSYS_ENABLED (option) IS_BUILTIN(option)#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED#undef SUBSYS/**
include/linux/cgroup_subsys.h +12 -12
@@ -3,51 +3,51 @@* * DO NOT ADD ANY SUBSYSTEM WITHOUT EXPLICIT ACKS FROM CGROUP MAINTAINERS. */ -#if IS_SUBSYS_ENABLED (CONFIG_CPUSETS ) +#if IS_ENABLED (CONFIG_CPUSETS ) SUBSYS(cpuset)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_DEBUG ) +#if IS_ENABLED (CONFIG_CGROUP_DEBUG ) SUBSYS(debug)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_SCHED ) +#if IS_ENABLED (CONFIG_CGROUP_SCHED ) SUBSYS(cpu_cgroup)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_CPUACCT ) +#if IS_ENABLED (CONFIG_CGROUP_CPUACCT ) SUBSYS(cpuacct)#endif -#if IS_SUBSYS_ENABLED (CONFIG_MEMCG ) +#if IS_ENABLED (CONFIG_MEMCG ) SUBSYS(mem_cgroup)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_DEVICE ) +#if IS_ENABLED (CONFIG_CGROUP_DEVICE ) SUBSYS(devices)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_FREEZER ) +#if IS_ENABLED (CONFIG_CGROUP_FREEZER ) SUBSYS(freezer)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_CLASSID ) +#if IS_ENABLED (CONFIG_CGROUP_NET_CLASSID ) SUBSYS(net_cls)#endif -#if IS_SUBSYS_ENABLED (CONFIG_BLK_CGROUP ) +#if IS_ENABLED (CONFIG_BLK_CGROUP ) SUBSYS(blkio)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_PERF ) +#if IS_ENABLED (CONFIG_CGROUP_PERF ) SUBSYS(perf)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_PRIO ) +#if IS_ENABLED (CONFIG_CGROUP_NET_PRIO ) SUBSYS(net_prio)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_HUGETLB ) +#if IS_ENABLED (CONFIG_CGROUP_HUGETLB ) SUBSYS(hugetlb)#endif /*
kernel/cgroup.c +17 -270
387 lines not on this page · raw message
net/core/netclassid_cgroup.c +0 -1
@@ -110,5 +110,4 @@ struct cgroup_subsys net_cls_subsys = { .attach = cgrp_attach, .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, - .module = THIS_MODULE, };
net/core/netprio_cgroup.c +0 -1
@@ -252,7 +252,6 @@ struct cgroup_subsys net_prio_subsys = { .attach = net_prio_attach, .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files, - .module = THIS_MODULE, }; static int netprio_device_event(struct notifier_block *unused,
Signature · 1 line
1.8.5.3
Re: [PATCH 2/6] cgroup: drop module support
Quoted 18 lines
/**
- *for_each_subsys- iterate all loaded cgroup subsystems
+ *for_each_subsys- iterate all enabled cgroup subsystems
* @ss: the iteration cursor
* @ssid: the index of @ss,CGROUP_SUBSYS_COUNTafter reaching the end
- *
- * Iterates through all loaded subsystems. Should be called under
- *cgroup_mutexorcgroup_root_mutex.
*/
#definefor_each_subsys(ss, ssid)\kernel/cgroup.c +0
-8-for (({cgroup_assert_mutex_or_root_locked (); (ssid) =0 ; }); \ - (ssid) <CGROUP_SUBSYS_COUNT ; (ssid)++) \ -if (!((ss) = cgroup_subsys[(ssid)])) { } \ -else - -/** -* for_each_builtin_subsys - iterate all built-in cgroup subsystems -* @ss: the iteration cursor
kernel/cgroup.c static int notify_on_release(const struct cgroup *cgrp) · line 260
Quoted 10 lines
kernel/cgroup.c +2
-8-* @i: the index of @ss, CGROUP_BUILTIN_SUBSYS_COUNT after reaching the end -* -* Bulit-in subsystems are always present and iteration itself doesn't -* require any synchronization. -*/ -#define for_each_builtin_subsys (ss, i) \ - for ((i) = 0; (i) < CGROUP_BUILTIN_SUBSYS_COUNT && \ - (((ss) = cgroup_subsys[i]) || true); (i)++) +for ((ssid) =0 ; (ssid) <CGROUP_SUBSYS_COUNT && \ + (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)
Now cgroup_subsys[i] won't be NULL, so we can drop "|| true".
Quoted 7 lines
/* iterate across the active hierarchies */
#definefor_each_active_root(root)\kernel/cgroup.c +0
-0@@ -975,50 +951,24 @@ static void cgroup_d_remove_dir(struct dentry *dentry)remove_dir (dentry); }
...
Quoted 5 lines
kernel/cgroup.c +0
-5-if (need_forkexit_callback) { -/* -* fork/exit callbacks are supported only for builtin -* subsystems, and the builtin section of the subsys -* array is immutable, so we don't need to lock the
kernel/cgroup.c void cgroup_post_fork(struct task_struct *child) · line 5036
Quoted 10 lines
kernel/cgroup.c +2
-6-* subsys array here. On the other hand, modular section -* of the array can be freed at module unload, so we -* can't touch that. -*/ -for_each_builtin_subsys (ss, i) +if (need_forkexit_callback) +for_each_subsys (ss, i)if (ss->fork) ss->fork (child); - }
This looks a bit ugly. How about leaving the parentheses for the outmost if statement?
if (need_forkexit_callback) {
for_each_subsys(ss, i)
if (ss->fork)
ss->fork(child);
}Tejun Heo
maintainerRe: [PATCH 2/6] cgroup: drop module support
Hello, Li.
Quoted 7 lines · Li Zefan
kernel/cgroup.c static int notify_on_release(const struct cgroup *cgrp) · line 260
Quoted 5 lines
kernel/cgroup.c +2
-3-#define for_each_builtin_subsys (ss, i) \ - for ((i) = 0; (i) < CGROUP_BUILTIN_SUBSYS_COUNT && \ - (((ss) = cgroup_subsys[i]) || true); (i)++) +for ((ssid) =0 ; (ssid) <CGROUP_SUBSYS_COUNT && \ + (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)Now cgroup_subsys[i] won't be NULL, so we can drop "|| true".
Hmmm... because the macro is kinda complex, I'd like to avoid changing its implementation in this patch. Also, the "|| true" tells the compiler that it doesn't have to generate conditional branch on the preceding condition.
Now that the array is always consecutive, I'm planning to further simplify the iterators to not require ssid, so that it just becomes for_each_subsys(ss). Let's leave it alone for now.
Quoted 9 lines
kernel/cgroup.c void cgroup_post_fork(struct task_struct *child) · line 5036
Quoted 5 lines
kernel/cgroup.c +2
-1+if (need_forkexit_callback) +for_each_subsys (ss, i)if (ss->fork) ss->fork (child); - }This looks a bit ugly. How about leaving the parentheses for the outmost if statement?
Quoted 5 lines
if (need_forkexit_callback) {
for_each_subsys(ss, i)
if (ss->fork)
ss->fork(child);
}Maybe, I don't know. I tend to aim for the minimum necessary as that usually is the easiest way to achieve consistency. That said certain things are a lot easier on the eye with a bit of extra notations - e.g. "(a & b) && c". Alright, will add the parentheses.
Thanks!
Signature · 1 line
tejun
Tejun Heo
maintainerPATCH v3 2/6 cgroup: drop module support
In reply to Tejun HeoFrom 9eabfa8710f51e6b865b4d6668fa7356656f05d8 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Wed, 29 Jan 2014 11:01:26 -0500
With module supported dropped from net_prio, no controller is using cgroup module support. None of actual resource controllers can be built as a module and we aren't gonna add new controllers which don't control resources. This patch drops module support from cgroup.
* cgroup_[un]load_subsys() and cgroup_subsys->module removed.
* As there's no point in distinguishing IS_BUILTIN() and IS_MODULE(), cgroup_subsys.h now uses IS_ENABLED() directly.
* enum cgroup_subsys_id now exactly matches the list of enabled controllers as ordered in cgroup_subsys.h.
* cgroup_subsys[] is now a contiguously occupied array. Size specification is no longer necessary and dropped.
* for_each_builtin_subsys() is removed and for_each_subsys() is updated to not require any locking.
* module ref handling is removed from rebind_subsystems().
* Module related comments dropped.
v2: Rebased on top of fe1217c4f3f7 ("net: net_cls: move cgroupfs
classid handling into core").
v3: Added {} around the if (need_forkexit_callback) block in
cgroup_post_fork() for readability as suggested by Li.
--- block/blk-cgroup.c | 1 - include/linux/cgroup.h | 29 +---- include/linux/cgroup_subsys.h | 24 ++-- kernel/cgroup.c | 284 +++--------------------------------------- net/core/netclassid_cgroup.c | 1 - net/core/netprio_cgroup.c | 1 - 6 files changed, 32 insertions(+), 308 deletions(-)
block/blk-cgroup.c +0 -1
@@ -914,7 +914,6 @@ struct cgroup_subsys blkio_subsys = { .can_attach = blkcg_can_attach, .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, - .module = THIS_MODULE, };EXPORT_SYMBOL_GPL (blkio_subsys);
include/linux/cgroup.h +4 -25
@@ -37,28 +37,13 @@ extern void cgroup_post_fork(struct task_struct *p);extern void cgroup_exit (struct task_struct *p,int run_callbacks);extern int cgroupstats_build (struct cgroupstats *stats,struct dentry *dentry); -extern int cgroup_load_subsys (struct cgroup_subsys *ss); -extern void cgroup_unload_subsys (struct cgroup_subsys *ss);extern int proc_cgroup_show (struct seq_file *,void *); -/* -* Define the enumeration of all cgroup subsystems. -* -* We define ids for builtin subsystems and then modular ones. -*/ +/* define the enumeration of all cgroup subsystems */ #define SUBSYS (_x) _x ## _subsys_id,enum cgroup_subsys_id { -#define IS_SUBSYS_ENABLED(option) IS_BUILTIN(option)#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED -CGROUP_BUILTIN_SUBSYS_COUNT , - - __CGROUP_SUBSYS_TEMP_PLACEHOLDER =CGROUP_BUILTIN_SUBSYS_COUNT -1 , - -#define IS_SUBSYS_ENABLED(option) IS_MODULE(option) -#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED CGROUP_SUBSYS_COUNT, };#undef SUBSYS
@@ -370,10 +355,9 @@ struct css_set {struct list_head cgrp_links;/* -* Set of subsystem states, one for each subsystem. This array -* is immutable after creation apart from the init_css_set -* during subsystem registration (at boot time) and modular subsystem -* loading/unloading. +* Set of subsystem states, one for each subsystem. This array is +* immutable after creation apart from the init_css_set during +* subsystem registration (at boot time). */ struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT ];
@@ -620,15 +604,10 @@ struct cgroup_subsys {/* base cftypes, automatically [de]registered with subsys itself */ struct cftype *base_cftypes;struct cftype_set base_cftset; - -/* should be defined only by modular subsystems */ -struct module *module; };#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys; -#define IS_SUBSYS_ENABLED (option) IS_BUILTIN(option)#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED#undef SUBSYS/**
include/linux/cgroup_subsys.h +12 -12
@@ -3,51 +3,51 @@* * DO NOT ADD ANY SUBSYSTEM WITHOUT EXPLICIT ACKS FROM CGROUP MAINTAINERS. */ -#if IS_SUBSYS_ENABLED (CONFIG_CPUSETS ) +#if IS_ENABLED (CONFIG_CPUSETS ) SUBSYS(cpuset)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_DEBUG ) +#if IS_ENABLED (CONFIG_CGROUP_DEBUG ) SUBSYS(debug)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_SCHED ) +#if IS_ENABLED (CONFIG_CGROUP_SCHED ) SUBSYS(cpu_cgroup)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_CPUACCT ) +#if IS_ENABLED (CONFIG_CGROUP_CPUACCT ) SUBSYS(cpuacct)#endif -#if IS_SUBSYS_ENABLED (CONFIG_MEMCG ) +#if IS_ENABLED (CONFIG_MEMCG ) SUBSYS(mem_cgroup)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_DEVICE ) +#if IS_ENABLED (CONFIG_CGROUP_DEVICE ) SUBSYS(devices)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_FREEZER ) +#if IS_ENABLED (CONFIG_CGROUP_FREEZER ) SUBSYS(freezer)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_CLASSID ) +#if IS_ENABLED (CONFIG_CGROUP_NET_CLASSID ) SUBSYS(net_cls)#endif -#if IS_SUBSYS_ENABLED (CONFIG_BLK_CGROUP ) +#if IS_ENABLED (CONFIG_BLK_CGROUP ) SUBSYS(blkio)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_PERF ) +#if IS_ENABLED (CONFIG_CGROUP_PERF ) SUBSYS(perf)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_PRIO ) +#if IS_ENABLED (CONFIG_CGROUP_NET_PRIO ) SUBSYS(net_prio)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_HUGETLB ) +#if IS_ENABLED (CONFIG_CGROUP_HUGETLB ) SUBSYS(hugetlb)#endif /*
kernel/cgroup.c +16 -268
384 lines not on this page · raw message
net/core/netclassid_cgroup.c +0 -1
@@ -110,5 +110,4 @@ struct cgroup_subsys net_cls_subsys = { .attach = cgrp_attach, .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, - .module = THIS_MODULE, };
net/core/netprio_cgroup.c +0 -1
@@ -252,7 +252,6 @@ struct cgroup_subsys net_prio_subsys = { .attach = net_prio_attach, .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files, - .module = THIS_MODULE, }; static int netprio_device_event(struct notifier_block *unused,
Signature · 1 line
1.8.5.3
A message that is not in the archive (sent off-list or not yet received): 1390952641-15950-3-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
PATCH v3 2/6 cgroup: drop module support
From 9eabfa8710f51e6b865b4d6668fa7356656f05d8 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Wed, 29 Jan 2014 11:01:26 -0500
With module supported dropped from net_prio, no controller is using cgroup module support. None of actual resource controllers can be built as a module and we aren't gonna add new controllers which don't control resources. This patch drops module support from cgroup.
* cgroup_[un]load_subsys() and cgroup_subsys->module removed.
* As there's no point in distinguishing IS_BUILTIN() and IS_MODULE(), cgroup_subsys.h now uses IS_ENABLED() directly.
* enum cgroup_subsys_id now exactly matches the list of enabled controllers as ordered in cgroup_subsys.h.
* cgroup_subsys[] is now a contiguously occupied array. Size specification is no longer necessary and dropped.
* for_each_builtin_subsys() is removed and for_each_subsys() is updated to not require any locking.
* module ref handling is removed from rebind_subsystems().
* Module related comments dropped.
v2: Rebased on top of fe1217c4f3f7 ("net: net_cls: move cgroupfs
classid handling into core").
v3: Added {} around the if (need_forkexit_callback) block in
cgroup_post_fork() for readability as suggested by Li.
--- block/blk-cgroup.c | 1 - include/linux/cgroup.h | 29 +---- include/linux/cgroup_subsys.h | 24 ++-- kernel/cgroup.c | 284 +++--------------------------------------- net/core/netclassid_cgroup.c | 1 - net/core/netprio_cgroup.c | 1 - 6 files changed, 32 insertions(+), 308 deletions(-)
block/blk-cgroup.c +0 -1
@@ -914,7 +914,6 @@ struct cgroup_subsys blkio_subsys = { .can_attach = blkcg_can_attach, .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, - .module = THIS_MODULE, };EXPORT_SYMBOL_GPL (blkio_subsys);
include/linux/cgroup.h +4 -25
@@ -37,28 +37,13 @@ extern void cgroup_post_fork(struct task_struct *p);extern void cgroup_exit (struct task_struct *p,int run_callbacks);extern int cgroupstats_build (struct cgroupstats *stats,struct dentry *dentry); -extern int cgroup_load_subsys (struct cgroup_subsys *ss); -extern void cgroup_unload_subsys (struct cgroup_subsys *ss);extern int proc_cgroup_show (struct seq_file *,void *); -/* -* Define the enumeration of all cgroup subsystems. -* -* We define ids for builtin subsystems and then modular ones. -*/ +/* define the enumeration of all cgroup subsystems */ #define SUBSYS (_x) _x ## _subsys_id,enum cgroup_subsys_id { -#define IS_SUBSYS_ENABLED(option) IS_BUILTIN(option)#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED -CGROUP_BUILTIN_SUBSYS_COUNT , - - __CGROUP_SUBSYS_TEMP_PLACEHOLDER =CGROUP_BUILTIN_SUBSYS_COUNT -1 , - -#define IS_SUBSYS_ENABLED(option) IS_MODULE(option) -#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED CGROUP_SUBSYS_COUNT, };#undef SUBSYS
@@ -370,10 +355,9 @@ struct css_set {struct list_head cgrp_links;/* -* Set of subsystem states, one for each subsystem. This array -* is immutable after creation apart from the init_css_set -* during subsystem registration (at boot time) and modular subsystem -* loading/unloading. +* Set of subsystem states, one for each subsystem. This array is +* immutable after creation apart from the init_css_set during +* subsystem registration (at boot time). */ struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT ];
@@ -620,15 +604,10 @@ struct cgroup_subsys {/* base cftypes, automatically [de]registered with subsys itself */ struct cftype *base_cftypes;struct cftype_set base_cftset; - -/* should be defined only by modular subsystems */ -struct module *module; };#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys; -#define IS_SUBSYS_ENABLED (option) IS_BUILTIN(option)#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED#undef SUBSYS/**
include/linux/cgroup_subsys.h +12 -12
@@ -3,51 +3,51 @@* * DO NOT ADD ANY SUBSYSTEM WITHOUT EXPLICIT ACKS FROM CGROUP MAINTAINERS. */ -#if IS_SUBSYS_ENABLED (CONFIG_CPUSETS ) +#if IS_ENABLED (CONFIG_CPUSETS ) SUBSYS(cpuset)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_DEBUG ) +#if IS_ENABLED (CONFIG_CGROUP_DEBUG ) SUBSYS(debug)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_SCHED ) +#if IS_ENABLED (CONFIG_CGROUP_SCHED ) SUBSYS(cpu_cgroup)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_CPUACCT ) +#if IS_ENABLED (CONFIG_CGROUP_CPUACCT ) SUBSYS(cpuacct)#endif -#if IS_SUBSYS_ENABLED (CONFIG_MEMCG ) +#if IS_ENABLED (CONFIG_MEMCG ) SUBSYS(mem_cgroup)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_DEVICE ) +#if IS_ENABLED (CONFIG_CGROUP_DEVICE ) SUBSYS(devices)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_FREEZER ) +#if IS_ENABLED (CONFIG_CGROUP_FREEZER ) SUBSYS(freezer)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_CLASSID ) +#if IS_ENABLED (CONFIG_CGROUP_NET_CLASSID ) SUBSYS(net_cls)#endif -#if IS_SUBSYS_ENABLED (CONFIG_BLK_CGROUP ) +#if IS_ENABLED (CONFIG_BLK_CGROUP ) SUBSYS(blkio)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_PERF ) +#if IS_ENABLED (CONFIG_CGROUP_PERF ) SUBSYS(perf)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_PRIO ) +#if IS_ENABLED (CONFIG_CGROUP_NET_PRIO ) SUBSYS(net_prio)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_HUGETLB ) +#if IS_ENABLED (CONFIG_CGROUP_HUGETLB ) SUBSYS(hugetlb)#endif /*
kernel/cgroup.c +16 -268
384 lines not on this page · raw message
net/core/netclassid_cgroup.c +0 -1
@@ -110,5 +110,4 @@ struct cgroup_subsys net_cls_subsys = { .attach = cgrp_attach, .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, - .module = THIS_MODULE, };
net/core/netprio_cgroup.c +0 -1
@@ -252,7 +252,6 @@ struct cgroup_subsys net_prio_subsys = { .attach = net_prio_attach, .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files, - .module = THIS_MODULE, }; static int netprio_device_event(struct notifier_block *unused,
Signature · 1 line
1.8.5.3
A message that is not in the archive (sent off-list or not yet received): 1390952641-15950-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
PATCH 2/6 cgroup: drop module support
With module supported dropped from net_prio, no controller is using cgroup module support. None of actual resource controllers can be built as a module and we aren't gonna add new controllers which don't control resources. This patch drops module support from cgroup.
* cgroup_[un]load_subsys() and cgroup_subsys->module removed.
* As there's no point in distinguishing IS_BUILTIN() and IS_MODULE(), cgroup_subsys.h now uses IS_ENABLED() directly.
* enum cgroup_subsys_id now exactly matches the list of enabled controllers as ordered in cgroup_subsys.h.
* cgroup_subsys[] is now a contiguously occupied array. Size specification is no longer necessary and dropped.
* for_each_builtin_subsys() is removed and for_each_subsys() is updated to not require any locking.
* module ref handling is removed from rebind_subsystems().
* Module related comments dropped.
v2: Rebased on top of fe1217c4f3f7 ("net: net_cls: move cgroupfs
classid handling into core").
--- block/blk-cgroup.c | 1 - include/linux/cgroup.h | 29 +---- include/linux/cgroup_subsys.h | 24 ++-- kernel/cgroup.c | 287 +++--------------------------------------- net/core/netclassid_cgroup.c | 1 - net/core/netprio_cgroup.c | 1 - 6 files changed, 33 insertions(+), 310 deletions(-)
block/blk-cgroup.c +0 -1
@@ -914,7 +914,6 @@ struct cgroup_subsys blkio_subsys = { .can_attach = blkcg_can_attach, .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, - .module = THIS_MODULE, };EXPORT_SYMBOL_GPL (blkio_subsys);
include/linux/cgroup.h +4 -25
@@ -37,28 +37,13 @@ extern void cgroup_post_fork(struct task_struct *p);extern void cgroup_exit (struct task_struct *p,int run_callbacks);extern int cgroupstats_build (struct cgroupstats *stats,struct dentry *dentry); -extern int cgroup_load_subsys (struct cgroup_subsys *ss); -extern void cgroup_unload_subsys (struct cgroup_subsys *ss);extern int proc_cgroup_show (struct seq_file *,void *); -/* -* Define the enumeration of all cgroup subsystems. -* -* We define ids for builtin subsystems and then modular ones. -*/ +/* define the enumeration of all cgroup subsystems */ #define SUBSYS (_x) _x ## _subsys_id,enum cgroup_subsys_id { -#define IS_SUBSYS_ENABLED(option) IS_BUILTIN(option)#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED -CGROUP_BUILTIN_SUBSYS_COUNT , - - __CGROUP_SUBSYS_TEMP_PLACEHOLDER =CGROUP_BUILTIN_SUBSYS_COUNT -1 , - -#define IS_SUBSYS_ENABLED(option) IS_MODULE(option) -#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED CGROUP_SUBSYS_COUNT, };#undef SUBSYS
@@ -370,10 +355,9 @@ struct css_set {struct list_head cgrp_links;/* -* Set of subsystem states, one for each subsystem. This array -* is immutable after creation apart from the init_css_set -* during subsystem registration (at boot time) and modular subsystem -* loading/unloading. +* Set of subsystem states, one for each subsystem. This array is +* immutable after creation apart from the init_css_set during +* subsystem registration (at boot time). */ struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT ];
@@ -620,15 +604,10 @@ struct cgroup_subsys {/* base cftypes, automatically [de]registered with subsys itself */ struct cftype *base_cftypes;struct cftype_set base_cftset; - -/* should be defined only by modular subsystems */ -struct module *module; };#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys; -#define IS_SUBSYS_ENABLED (option) IS_BUILTIN(option)#include <linux/cgroup_subsys.h> -#undef IS_SUBSYS_ENABLED#undef SUBSYS/**
include/linux/cgroup_subsys.h +12 -12
@@ -3,51 +3,51 @@* * DO NOT ADD ANY SUBSYSTEM WITHOUT EXPLICIT ACKS FROM CGROUP MAINTAINERS. */ -#if IS_SUBSYS_ENABLED (CONFIG_CPUSETS ) +#if IS_ENABLED (CONFIG_CPUSETS ) SUBSYS(cpuset)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_DEBUG ) +#if IS_ENABLED (CONFIG_CGROUP_DEBUG ) SUBSYS(debug)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_SCHED ) +#if IS_ENABLED (CONFIG_CGROUP_SCHED ) SUBSYS(cpu_cgroup)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_CPUACCT ) +#if IS_ENABLED (CONFIG_CGROUP_CPUACCT ) SUBSYS(cpuacct)#endif -#if IS_SUBSYS_ENABLED (CONFIG_MEMCG ) +#if IS_ENABLED (CONFIG_MEMCG ) SUBSYS(mem_cgroup)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_DEVICE ) +#if IS_ENABLED (CONFIG_CGROUP_DEVICE ) SUBSYS(devices)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_FREEZER ) +#if IS_ENABLED (CONFIG_CGROUP_FREEZER ) SUBSYS(freezer)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_CLASSID ) +#if IS_ENABLED (CONFIG_CGROUP_NET_CLASSID ) SUBSYS(net_cls)#endif -#if IS_SUBSYS_ENABLED (CONFIG_BLK_CGROUP ) +#if IS_ENABLED (CONFIG_BLK_CGROUP ) SUBSYS(blkio)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_PERF ) +#if IS_ENABLED (CONFIG_CGROUP_PERF ) SUBSYS(perf)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_NET_PRIO ) +#if IS_ENABLED (CONFIG_CGROUP_NET_PRIO ) SUBSYS(net_prio)#endif -#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_HUGETLB ) +#if IS_ENABLED (CONFIG_CGROUP_HUGETLB ) SUBSYS(hugetlb)#endif /*
kernel/cgroup.c +17 -270
387 lines not on this page · raw message
net/core/netclassid_cgroup.c +0 -1
@@ -110,5 +110,4 @@ struct cgroup_subsys net_cls_subsys = { .attach = cgrp_attach, .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, - .module = THIS_MODULE, };
net/core/netprio_cgroup.c +0 -1
@@ -252,7 +252,6 @@ struct cgroup_subsys net_prio_subsys = { .attach = net_prio_attach, .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files, - .module = THIS_MODULE, }; static int netprio_device_event(struct notifier_block *unused,
Signature · 1 line
1.8.5.3
PATCH 6/6 cgroup: remove cgroup_root_mutex
In reply to a message not in the archivecgroup_root_mutex was added to avoid deadlock involving namespace_sem via cgroup_show_options(). It added a lot of overhead for the small purpose of it and, because it's nested under cgroup_mutex, it has very limited usefulness. The previous patch made cgroup_show_options() not use cgroup_root_mutex, so nobody needs it anymore. Remove it.
--- kernel/cgroup.c | 42 +----------------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-)
kernel/cgroup.c +1 -41
@@ -70,18 +70,6 @@/* * cgroup_mutex is the master lock. Any modification to cgroup or its * hierarchy must be performed while holding it. -* -* cgroup_root_mutex nests inside cgroup_mutex and should be held to modify -* cgroupfs_root of any cgroup hierarchy - subsys list, flags, -* release_agent_path and so on. Modifying requires both cgroup_mutex and -* cgroup_root_mutex. Readers can acquire either of the two. This is to -* break the following locking order cycle. -* -* A. cgroup_mutex -> cred_guard_mutex -> s_type->i_mutex_key -> namespace_sem -* B. namespace_sem -> cgroup_mutex -* -* B happens only through cgroup_show_options() and using cgroup_root_mutex -* breaks it. */ #ifdef CONFIG_PROVE_RCU DEFINE_MUTEX (cgroup_mutex);
@@ -90,8 +78,6 @@ EXPORT_SYMBOL_GPL(cgroup_mutex); /* only for lockdep */static DEFINE_MUTEX (cgroup_mutex);#endif -static DEFINE_MUTEX (cgroup_root_mutex); -/* * Protects cgroup_subsys->release_agent_path. Modifying it also requires * cgroup_mutex. Reading requires either cgroup_mutex or this spinlock.
@@ -103,14 +89,6 @@ static DEFINE_SPINLOCK(release_agent_path_lock);lockdep_is_held (&cgroup_mutex), \ "cgroup_mutex or RCU read lock required"); -#ifdef CONFIG_LOCKDEP -#define cgroup_assert_mutex_or_root_locked () \ - WARN_ON_ONCE(debug_locks && (!lockdep_is_held(&cgroup_mutex) && \ - !lockdep_is_held(&cgroup_root_mutex))) -#else -#define cgroup_assert_mutex_or_root_locked () do { } while (0) -#endif -/* * cgroup destruction makes heavy use of work items and there can be a lot * of concurrent destructions. Use a separate workqueue so that cgroup
@@ -154,11 +132,7 @@ static struct cgroup * const cgroup_dummy_top = &cgroup_dummy_root.top_cgroup;static LIST_HEAD (cgroup_roots);static int cgroup_root_count; -/* -* Hierarchy ID allocation and mapping. It follows the same exclusion -* rules as other root ops - both cgroup_mutex and cgroup_root_mutex for -* writes, either for reads. -*/ +/* hierarchy ID allocation and mapping, protected by cgroup_mutex */ static DEFINE_IDR (cgroup_hierarchy_idr);static struct cgroup_name root_cgroup_name = { .name ="/" };
@@ -973,7 +947,6 @@ static int rebind_subsystems(struct cgroupfs_root *root,int i, ret;BUG_ON (!mutex_is_locked (&cgroup_mutex)); -BUG_ON (!mutex_is_locked (&cgroup_root_mutex));/* Check that any added subsystems are currently free */ for_each_subsys (ss, i)
@@ -1246,7 +1219,6 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)mutex_lock (&cgrp->dentry->d_inode->i_mutex);mutex_lock (&cgroup_mutex); -mutex_lock (&cgroup_root_mutex);/* See what subsystems are wanted */ ret =parse_cgroupfs_options (data, &opts);
@@ -1288,7 +1260,6 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data) out_unlock:kfree (opts.release_agent);kfree (opts.name); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);mutex_unlock (&cgrp->dentry->d_inode->i_mutex);return ret;
@@ -1331,7 +1302,6 @@ static int cgroup_init_root_id(struct cgroupfs_root *root, int start, int end)int id;lockdep_assert_held (&cgroup_mutex); -lockdep_assert_held (&cgroup_root_mutex); id =idr_alloc_cyclic (&cgroup_hierarchy_idr, root, start, end,GFP_KERNEL );
@@ -1345,7 +1315,6 @@ static int cgroup_init_root_id(struct cgroupfs_root *root, int start, int end)static void cgroup_exit_root_id (struct cgroupfs_root *root) {lockdep_assert_held (&cgroup_mutex); -lockdep_assert_held (&cgroup_root_mutex);if (root->hierarchy_id) {idr_remove (&cgroup_hierarchy_idr, root->hierarchy_id);
@@ -1517,7 +1486,6 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,mutex_lock (&inode->i_mutex);mutex_lock (&cgroup_mutex); -mutex_lock (&cgroup_root_mutex); ret =idr_alloc (&root->cgroup_idr, root_cgrp,0 ,1 ,GFP_KERNEL );if (ret <0 )
@@ -1590,7 +1558,6 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,BUG_ON (!list_empty (&root_cgrp->children));BUG_ON (root->number_of_cgroups !=1 ); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);mutex_unlock (&inode->i_mutex); }else {
@@ -1621,7 +1588,6 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,revert_creds (cred); unlock_drop:cgroup_exit_root_id (root); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);mutex_unlock (&inode->i_mutex); drop_new_super:
@@ -1646,7 +1612,6 @@ static void cgroup_kill_sb(struct super_block *sb)mutex_lock (&cgrp->dentry->d_inode->i_mutex);mutex_lock (&cgroup_mutex); -mutex_lock (&cgroup_root_mutex);/* Rebind all subsystems back to the default hierarchy */ if (root->flags &CGRP_ROOT_SUBSYS_BOUND ) {
@@ -1675,7 +1640,6 @@ static void cgroup_kill_sb(struct super_block *sb)cgroup_exit_root_id (root); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);mutex_unlock (&cgrp->dentry->d_inode->i_mutex);
@@ -2186,11 +2150,9 @@ static int cgroup_release_agent_write(struct cgroup_subsys_state *css,return -EINVAL ;if (!cgroup_lock_live_group (css->cgroup))return -ENODEV ; -mutex_lock (&cgroup_root_mutex);spin_lock (&release_agent_path_lock);strcpy (css->cgroup->root->release_agent_path, buffer);spin_unlock (&release_agent_path_lock); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);return 0 ; }
@@ -4578,7 +4540,6 @@ int __init cgroup_init(void)/* allocate id for the dummy hierarchy */ mutex_lock (&cgroup_mutex); -mutex_lock (&cgroup_root_mutex);/* Add init_css_set to the hash table */ key =css_set_hash (init_css_set.subsys);
@@ -4590,7 +4551,6 @@ int __init cgroup_init(void) 0, 1, GFP_KERNEL);BUG_ON (err <0 ); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex); cgroup_kobj =kobject_create_and_add ("cgroup" , fs_kobj);
Signature · 1 line
1.8.5.3
Tejun Heo
maintainerPATCH 3/6 cgroup: clean up cgroup_subsys names and initialization
In reply to Tejun Heocgroup_subsys is a bit messier than it needs to be.
* The name of a subsys can be different from its internal identifier defined in cgroup_subsys.h. Most subsystems use the matching name but three - cpu, memory and perf_event - use different ones.
* cgroup_subsys_id enums are postfixed with _subsys_id and each cgroup_subsys is postfixed with _subsys. cgroup.h is widely included throughout various subsystems, it doesn't and shouldn't have claim on such generic names which don't have any qualifier indicating that they belong to cgroup.
* cgroup_subsys->subsys_id should always equal the matching cgroup_subsys_id enum; however, we require each controller to initialize it and then BUG if they don't match, which is a bit silly.
This patch cleans up cgroup_subsys names and initialization by doing the followings.
* cgroup_subsys_id enums are now postfixed with _cgrp_id, and each cgroup_subsys with _cgrp_subsys.
* With the above, renaming subsys identifiers to match the userland visible names doesn't cause any naming conflicts. All non-matching identifiers are renamed to match the official names.
cpu_cgroup -> cpu
mem_cgroup -> memory
perf -> perf_event
* controllers no longer need to initialize ->subsys_id and ->name. They're generated in cgroup core and set automatically during boot.
* Redundant cgroup_subsys declarations removed.
* While updating BUG_ON()s in cgroup_init_early(), convert them to WARN()s. BUGging that early during boot is stupid - the kernel can't print anything, even through serial console and the trap handler doesn't even link stack frame properly for back-tracing.
This patch doesn't introduce any behavior changes.
v2: Rebased on top of fe1217c4f3f7 ("net: net_cls: move cgroupfs
classid handling into core").
--- block/blk-cgroup.c | 8 +++----- block/blk-cgroup.h | 2 +- fs/bio.c | 2 +- include/linux/cgroup.h | 7 ++++--- include/linux/cgroup_subsys.h | 6 +++--- include/linux/hugetlb_cgroup.h | 2 +- include/linux/memcontrol.h | 2 +- include/net/cls_cgroup.h | 2 +- include/net/netprio_cgroup.h | 2 +- kernel/cgroup.c | 34 ++++++++++++++++++++-------------- kernel/cgroup_freezer.c | 8 ++------ kernel/cpuset.c | 10 ++++------ kernel/events/core.c | 8 +++----- kernel/sched/core.c | 6 ++---- kernel/sched/cpuacct.c | 6 ++---- mm/hugetlb_cgroup.c | 9 +++------ mm/memcontrol.c | 22 ++++++++++------------ net/core/netclassid_cgroup.c | 6 ++---- net/core/netprio_cgroup.c | 4 +--- net/ipv4/tcp_memcontrol.c | 2 +- security/device_cgroup.c | 8 ++------ 21 files changed, 68 insertions(+), 88 deletions(-)
block/blk-cgroup.c +3 -5
@@ -906,16 +906,14 @@ static int blkcg_can_attach(struct cgroup_subsys_state *css,return ret; } -struct cgroup_subsys blkio_subsys = { - .name ="blkio" , +struct cgroup_subsys blkio_cgrp_subsys = { .css_alloc = blkcg_css_alloc, .css_offline = blkcg_css_offline, .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, - .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, }; -EXPORT_SYMBOL_GPL (blkio_subsys); +EXPORT_SYMBOL_GPL (blkio_cgrp_subsys);/** * blkcg_activate_policy - activate a blkcg policy on a request_queue
@@ -1105,7 +1103,7 @@ int blkcg_policy_register(struct blkcg_policy *pol)/* everything is in place, add intf files for the new policy */ if (pol->cftypes) -WARN_ON (cgroup_add_cftypes (&blkio_subsys, pol->cftypes)); +WARN_ON (cgroup_add_cftypes (&blkio_cgrp_subsys, pol->cftypes)); ret =0 ; out_unlock:mutex_unlock (&blkcg_pol_mutex);
block/blk-cgroup.h +1 -1
@@ -186,7 +186,7 @@ static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)static inline struct blkcg *task_blkcg (struct task_struct *tsk) { -return css_to_blkcg (task_css (tsk, blkio_subsys_id)); +return css_to_blkcg (task_css (tsk, blkio_cgrp_id)); }static inline struct blkcg *bio_blkcg (struct bio *bio)
fs/bio.c +1 -1
@@ -2002,7 +2002,7 @@ int bio_associate_current(struct bio *bio)/* associate blkcg if exists */ rcu_read_lock (); - css =task_css (current, blkio_subsys_id); + css =task_css (current, blkio_cgrp_id);if (css &&css_tryget (css)) bio->bi_css = css;rcu_read_unlock ();
include/linux/cgroup.h +4 -3
@@ -41,7 +41,7 @@ extern int cgroupstats_build(struct cgroupstats *stats,extern int proc_cgroup_show (struct seq_file *,void *);/* define the enumeration of all cgroup subsystems */ -#define SUBSYS (_x) _x ## _subsys_id, +#define SUBSYS (_x) _x ## _cgrp_id,enum cgroup_subsys_id {#include <linux/cgroup_subsys.h> CGROUP_SUBSYS_COUNT,
@@ -573,7 +573,6 @@ struct cgroup_subsys { struct task_struct *task);void (*bind)(struct cgroup_subsys_state *root_css); -int subsys_id;int disabled;int early_init;
@@ -592,6 +591,8 @@ struct cgroup_subsys {bool broken_hierarchy;bool warned_broken_hierarchy; +/* the following two fields are initialized automtically during boot */ +int subsys_id;#define MAX_CGROUP_TYPE_NAMELEN 32const char *name;
@@ -606,7 +607,7 @@ struct cgroup_subsys {struct cftype_set base_cftset; }; -#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys; +#define SUBSYS (_x) extern struct cgroup_subsys _x ## _cgrp_subsys;#include <linux/cgroup_subsys.h> #undef SUBSYS
include/linux/cgroup_subsys.h +3 -3
@@ -12,7 +12,7 @@ SUBSYS(debug)#endif #if IS_ENABLED (CONFIG_CGROUP_SCHED ) -SUBSYS(cpu_cgroup) +SUBSYS(cpu)#endif #if IS_ENABLED (CONFIG_CGROUP_CPUACCT )
@@ -20,7 +20,7 @@ SUBSYS(cpuacct)#endif #if IS_ENABLED (CONFIG_MEMCG ) -SUBSYS(mem_cgroup) +SUBSYS(memory)#endif #if IS_ENABLED (CONFIG_CGROUP_DEVICE )
@@ -40,7 +40,7 @@ SUBSYS(blkio)#endif #if IS_ENABLED (CONFIG_CGROUP_PERF ) -SUBSYS(perf) +SUBSYS(perf_event)#endif #if IS_ENABLED (CONFIG_CGROUP_NET_PRIO )
include/linux/hugetlb_cgroup.h +1 -1
@@ -49,7 +49,7 @@ int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)static inline bool hugetlb_cgroup_disabled (void ) { -if (hugetlb_subsys.disabled) +if (hugetlb_cgrp_subsys.disabled)return true;return false; }
include/linux/memcontrol.h +1 -1
@@ -162,7 +162,7 @@ extern int do_swap_account;static inline bool mem_cgroup_disabled (void ) { -if (mem_cgroup_subsys.disabled) +if (memory_cgrp_subsys.disabled)return true;return false; }
include/net/cls_cgroup.h +1 -1
@@ -34,7 +34,7 @@ static inline u32 task_cls_classid(struct task_struct *p)return 0 ;rcu_read_lock (); - classid =container_of (task_css (p, net_cls_subsys_id), + classid =container_of (task_css (p, net_cls_cgrp_id), struct cgroup_cls_state, css)->classid;rcu_read_unlock ();
include/net/netprio_cgroup.h +1 -1
@@ -33,7 +33,7 @@ static inline u32 task_netprioidx(struct task_struct *p)u32 idx;rcu_read_lock (); - css =task_css (p, net_prio_subsys_id); + css =task_css (p, net_prio_cgrp_id); idx = css->cgroup->id;rcu_read_unlock ();return idx;
kernel/cgroup.c +20 -14
@@ -120,10 +120,18 @@ static struct workqueue_struct *cgroup_destroy_wq;static struct workqueue_struct *cgroup_pidlist_destroy_wq;/* generate an array of cgroup subsystem pointers */ -#define SUBSYS (_x) [_x ## _subsys_id] = &_x ## _subsys, +#define SUBSYS (_x) [_x ## _cgrp_id] = &_x ## _cgrp_subsys, static struct cgroup_subsys *cgroup_subsys[] = {#include <linux/cgroup_subsys.h> }; +#undef SUBSYS + +/* array of cgroup subsystem names */ +#define SUBSYS (_x) [_x ## _cgrp_id] = #_x, +static const char *cgroup_subsys_name[] = { +#include <linux/cgroup_subsys.h> +}; +#undef SUBSYS/* * The dummy hierarchy, reserved for the subsystems that are otherwise
@@ -1076,7 +1084,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)BUG_ON (!mutex_is_locked (&cgroup_mutex));#ifdef CONFIG_CPUSETS - mask = ~(1UL << cpuset_subsys_id); + mask = ~(1UL << cpuset_cgrp_id);#endif memset (opts,0 ,sizeof (*opts));
@@ -4518,15 +4526,15 @@ int __init cgroup_init_early(void)list_add (&init_cgrp_cset_link.cgrp_link, &init_css_set.cgrp_links);for_each_subsys (ss, i) { -BUG_ON (!ss->name); -BUG_ON (strlen (ss->name) >MAX_CGROUP_TYPE_NAMELEN ); -BUG_ON (!ss->css_alloc); -BUG_ON (!ss->css_free); -if (ss->subsys_id != i) { -printk (KERN_ERR "cgroup: Subsys %s id == %d\n" , - ss->name, ss->subsys_id); -BUG (); - } +WARN (!ss->css_alloc || !ss->css_free || ss->name || ss->subsys_id, +"invalid cgroup_subsys %d:%s css_alloc=%p css_free=%p name:id=%d:%s\n" , + i, cgroup_subsys_name[i], ss->css_alloc, ss->css_free, + ss->subsys_id, ss->name); +WARN (strlen (cgroup_subsys_name[i]) >MAX_CGROUP_TYPE_NAMELEN , +"cgroup_subsys_name %s too long\n" , cgroup_subsys_name[i]); + + ss->subsys_id = i; + ss->name = cgroup_subsys_name[i];if (ss->early_init)cgroup_init_subsys (ss);
@@ -5156,11 +5164,9 @@ static struct cftype debug_files[] = { { } /* terminate */ }; -struct cgroup_subsys debug_subsys = { - .name ="debug" , +struct cgroup_subsys debug_cgrp_subsys = { .css_alloc = debug_css_alloc, .css_free = debug_css_free, - .subsys_id = debug_subsys_id, .base_cftypes = debug_files, };#endif /* CONFIG_CGROUP_DEBUG */
kernel/cgroup_freezer.c +2 -6
@@ -52,7 +52,7 @@ static inline struct freezer *css_freezer(struct cgroup_subsys_state *css)static inline struct freezer *task_freezer (struct task_struct *task) { -return css_freezer (task_css (task, freezer_subsys_id)); +return css_freezer (task_css (task, freezer_cgrp_id)); }static struct freezer *parent_freezer (struct freezer *freezer)
@@ -84,8 +84,6 @@ static const char *freezer_state_strs(unsigned int state)return "THAWED" ; }; -struct cgroup_subsys freezer_subsys; -static struct cgroup_subsys_state *freezer_css_alloc (struct cgroup_subsys_state *parent_css) {
@@ -473,13 +471,11 @@ static struct cftype files[] = { { }/* terminate */ }; -struct cgroup_subsys freezer_subsys = { - .name ="freezer" , +struct cgroup_subsys freezer_cgrp_subsys = { .css_alloc = freezer_css_alloc, .css_online = freezer_css_online, .css_offline = freezer_css_offline, .css_free = freezer_css_free, - .subsys_id = freezer_subsys_id, .attach = freezer_attach, .fork = freezer_fork, .base_cftypes = files,
kernel/cpuset.c +4 -6
@@ -119,7 +119,7 @@ static inline struct cpuset *css_cs(struct cgroup_subsys_state *css)/* Retrieve the cpuset for a task */ static inline struct cpuset *task_cs (struct task_struct *task) { -return css_cs (task_css (task, cpuset_subsys_id)); +return css_cs (task_css (task, cpuset_cgrp_id)); }static inline struct cpuset *parent_cs (struct cpuset *cs)
@@ -1521,7 +1521,7 @@ static void cpuset_attach(struct cgroup_subsys_state *css,struct task_struct *task;struct task_struct *leader =cgroup_taskset_first (tset);struct cgroup_subsys_state *oldcss =cgroup_taskset_cur_css (tset, - cpuset_subsys_id); + cpuset_cgrp_id);struct cpuset *cs =css_cs (css);struct cpuset *oldcs =css_cs (oldcss);struct cpuset *cpus_cs =effective_cpumask_cpuset (cs);
@@ -2024,8 +2024,7 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)kfree (cs); } -struct cgroup_subsys cpuset_subsys = { - .name ="cpuset" , +struct cgroup_subsys cpuset_cgrp_subsys = { .css_alloc = cpuset_css_alloc, .css_online = cpuset_css_online, .css_offline = cpuset_css_offline,
@@ -2033,7 +2032,6 @@ struct cgroup_subsys cpuset_subsys = { .can_attach = cpuset_can_attach, .cancel_attach = cpuset_cancel_attach, .attach = cpuset_attach, - .subsys_id = cpuset_subsys_id, .base_cftypes = files, .early_init = 1, };
@@ -2699,7 +2697,7 @@ int proc_cpuset_show(struct seq_file *m, void *unused_v) goto out_free;rcu_read_lock (); - css =task_css (tsk, cpuset_subsys_id); + css =task_css (tsk, cpuset_cgrp_id); retval =cgroup_path (css->cgroup, buf,PAGE_SIZE );rcu_read_unlock ();if (retval <0 )
kernel/events/core.c +3 -5
@@ -342,7 +342,7 @@ struct perf_cgroup {static inline struct perf_cgroup *perf_cgroup_from_task (struct task_struct *task) { -return container_of (task_css (task, perf_subsys_id), +return container_of (task_css (task, perf_event_cgrp_id), struct perf_cgroup, css); }
@@ -595,7 +595,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,rcu_read_lock (); - css =css_from_dir (f.file->f_dentry, &perf_subsys); + css =css_from_dir (f.file->f_dentry, &perf_event_cgrp_subsys);if (IS_ERR (css)) { ret =PTR_ERR (css); goto out;
@@ -8055,9 +8055,7 @@ static void perf_cgroup_exit(struct cgroup_subsys_state *css,task_function_call (task, __perf_cgroup_move, task); } -struct cgroup_subsys perf_subsys = { - .name ="perf_event" , - .subsys_id = perf_subsys_id, +struct cgroup_subsys perf_event_cgrp_subsys = { .css_alloc = perf_cgroup_css_alloc, .css_free = perf_cgroup_css_free, .exit = perf_cgroup_exit,
kernel/sched/core.c +2 -4
@@ -7174,7 +7174,7 @@ void sched_move_task(struct task_struct *tsk)if (unlikely (running)) tsk->sched_class->put_prev_task (rq, tsk); - tg =container_of (task_css_check (tsk, cpu_cgroup_subsys_id, + tg =container_of (task_css_check (tsk, cpu_cgrp_id,lockdep_is_held (&tsk->sighand->siglock)), struct task_group, css); tg =autogroup_task_group (tsk, tg);
@@ -7955,8 +7955,7 @@ static struct cftype cpu_files[] = { { }/* terminate */ }; -struct cgroup_subsys cpu_cgroup_subsys = { - .name ="cpu" , +struct cgroup_subsys cpu_cgrp_subsys = { .css_alloc = cpu_cgroup_css_alloc, .css_free = cpu_cgroup_css_free, .css_online = cpu_cgroup_css_online,
@@ -7964,7 +7963,6 @@ struct cgroup_subsys cpu_cgroup_subsys = { .can_attach = cpu_cgroup_can_attach, .attach = cpu_cgroup_attach, .exit = cpu_cgroup_exit, - .subsys_id = cpu_cgroup_subsys_id, .base_cftypes = cpu_files, .early_init = 1, };
kernel/sched/cpuacct.c +2 -4
@@ -41,7 +41,7 @@ static inline struct cpuacct *css_ca(struct cgroup_subsys_state *css)/* return cpu accounting group to which this task belongs */ static inline struct cpuacct *task_ca (struct task_struct *tsk) { -return css_ca (task_css (tsk, cpuacct_subsys_id)); +return css_ca (task_css (tsk, cpuacct_cgrp_id)); }static inline struct cpuacct *parent_ca (struct cpuacct *ca)
@@ -275,11 +275,9 @@ void cpuacct_account_field(struct task_struct *p, int index, u64 val)rcu_read_unlock (); } -struct cgroup_subsys cpuacct_subsys = { - .name ="cpuacct" , +struct cgroup_subsys cpuacct_cgrp_subsys = { .css_alloc = cpuacct_css_alloc, .css_free = cpuacct_css_free, - .subsys_id = cpuacct_subsys_id, .base_cftypes = files, .early_init =1 , };
mm/hugetlb_cgroup.c +3 -6
@@ -30,7 +30,6 @@ struct hugetlb_cgroup {#define MEMFILE_IDX (val) (((val) >> 16) & 0xffff)#define MEMFILE_ATTR (val) ((val) & 0xffff) -struct cgroup_subsys hugetlb_subsys__read_mostly ;static struct hugetlb_cgroup *root_h_cgroup__read_mostly ; static inline
@@ -42,7 +41,7 @@ struct hugetlb_cgroup *hugetlb_cgroup_from_css(struct cgroup_subsys_state *s)static inline struct hugetlb_cgroup *hugetlb_cgroup_from_task (struct task_struct *task) { -return hugetlb_cgroup_from_css (task_css (task, hugetlb_subsys_id)); +return hugetlb_cgroup_from_css (task_css (task, hugetlb_cgrp_id)); }static inline bool hugetlb_cgroup_is_root (struct hugetlb_cgroup *h_cg)
@@ -358,7 +357,7 @@ static void __init __hugetlb_cgroup_file_init(int idx) cft = &h->cgroup_files[4 ];memset (cft,0 ,sizeof (*cft)); -WARN_ON (cgroup_add_cftypes (&hugetlb_subsys, h->cgroup_files)); +WARN_ON (cgroup_add_cftypes (&hugetlb_cgrp_subsys, h->cgroup_files));return ; }
@@ -402,10 +401,8 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)return ; } -struct cgroup_subsys hugetlb_subsys = { - .name ="hugetlb" , +struct cgroup_subsys hugetlb_cgrp_subsys = { .css_alloc = hugetlb_cgroup_css_alloc, .css_offline = hugetlb_cgroup_css_offline, .css_free = hugetlb_cgroup_css_free, - .subsys_id = hugetlb_subsys_id, };
mm/memcontrol.c +10 -12
@@ -66,8 +66,8 @@#include <trace/events/vmscan.h> -struct cgroup_subsys mem_cgroup_subsys__read_mostly ; -EXPORT_SYMBOL (mem_cgroup_subsys); +struct cgroup_subsys memory_cgrp_subsys__read_mostly ; +EXPORT_SYMBOL (memory_cgrp_subsys);#define MEM_CGROUP_RECLAIM_RETRIES 5static struct mem_cgroup *root_mem_cgroup__read_mostly ;
@@ -538,7 +538,7 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) {struct cgroup_subsys_state *css; - css =css_from_id (id -1 , &mem_cgroup_subsys); + css =css_from_id (id -1 , &memory_cgrp_subsys);return mem_cgroup_from_css (css); }
@@ -1072,7 +1072,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)if (unlikely (!p))return NULL ; -return mem_cgroup_from_css (task_css (p, mem_cgroup_subsys_id)); +return mem_cgroup_from_css (task_css (p, memory_cgrp_id)); }struct mem_cgroup *try_get_mem_cgroup_from_mm (struct mm_struct *mm)
@@ -1702,7 +1702,7 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)rcu_read_lock (); mem_cgrp = memcg->css.cgroup; - task_cgrp =task_cgroup (p, mem_cgroup_subsys_id); + task_cgrp =task_cgroup (p, memory_cgrp_id); ret =cgroup_path (task_cgrp, memcg_name,PATH_MAX );if (ret <0 ) {
@@ -6188,7 +6188,7 @@ static int memcg_write_event_control(struct cgroup_subsys_state *css, ret = -EINVAL ; cfile_css =css_from_dir (cfile.file->f_dentry->d_parent, - &mem_cgroup_subsys); + &memory_cgrp_subsys);if (cfile_css == css &&css_tryget (css)) ret =0 ;
@@ -6567,11 +6567,11 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)* unfortunate state in our controller. */ if (parent != root_mem_cgroup) - mem_cgroup_subsys.broken_hierarchy = true; + memory_cgrp_subsys.broken_hierarchy = true; }mutex_unlock (&memcg_create_mutex); -return memcg_init_kmem (memcg, &mem_cgroup_subsys); +return memcg_init_kmem (memcg, &memory_cgrp_subsys); }/*
@@ -7265,9 +7265,7 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css)mem_cgroup_from_css (root_css)->use_hierarchy = true; } -struct cgroup_subsys mem_cgroup_subsys = { - .name ="memory" , - .subsys_id = mem_cgroup_subsys_id, +struct cgroup_subsys memory_cgrp_subsys = { .css_alloc = mem_cgroup_css_alloc, .css_online = mem_cgroup_css_online, .css_offline = mem_cgroup_css_offline,
@@ -7293,7 +7291,7 @@ __setup("swapaccount=", enable_swap_account);static void __init memsw_file_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, memsw_cgroup_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, memsw_cgroup_files)); }static void __init enable_swap_cgroup (void )
net/core/netclassid_cgroup.c +2 -4
@@ -23,7 +23,7 @@ static inline struct cgroup_cls_state *css_cls_state(struct cgroup_subsys_statestruct cgroup_cls_state *task_cls_state (struct task_struct *p) { -return css_cls_state (task_css (p, net_cls_subsys_id)); +return css_cls_state (task_css (p, net_cls_cgrp_id)); }EXPORT_SYMBOL_GPL (task_cls_state);
@@ -102,12 +102,10 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_cls_subsys = { - .name ="net_cls" , +struct cgroup_subsys net_cls_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = cgrp_attach, - .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, };
net/core/netprio_cgroup.c +1 -3
@@ -244,13 +244,11 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_prio_subsys = { - .name ="net_prio" , +struct cgroup_subsys net_prio_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = net_prio_attach, - .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files, };
net/ipv4/tcp_memcontrol.c +1 -1
@@ -219,7 +219,7 @@ static struct cftype tcp_files[] = {static int __init tcp_memcontrol_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, tcp_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, tcp_files));return 0 ; }__initcall (tcp_memcontrol_init);
security/device_cgroup.c +2 -6
@@ -58,11 +58,9 @@ static inline struct dev_cgroup *css_to_devcgroup(struct cgroup_subsys_state *s)static inline struct dev_cgroup *task_devcgroup (struct task_struct *task) { -return css_to_devcgroup (task_css (task, devices_subsys_id)); +return css_to_devcgroup (task_css (task, devices_cgrp_id)); } -struct cgroup_subsys devices_subsys; -/* * called under devcgroup_mutex */
@@ -684,13 +682,11 @@ static struct cftype dev_cgroup_files[] = { { }/* terminate */ }; -struct cgroup_subsys devices_subsys = { - .name ="devices" , +struct cgroup_subsys devices_cgrp_subsys = { .css_alloc = devcgroup_css_alloc, .css_free = devcgroup_css_free, .css_online = devcgroup_online, .css_offline = devcgroup_offline, - .subsys_id = devices_subsys_id, .base_cftypes = dev_cgroup_files, };
Signature · 1 line
1.8.5.3
Re: [PATCH 3/6] cgroup: clean up cgroup_subsys names and initialization
Quoted 46 lines · Tejun Heo
cgroup_subsysis a bit messier than it needs to be.* The name of a subsys can be different from its internal identifier defined in
cgroup_subsys.h. Most subsystems use the matching name but three - cpu, memory andperf_event- use different ones.*
cgroup_subsys_idenums are postfixed with_subsys_idand eachcgroup_subsysis postfixed with_subsys.cgroup.his widely included throughout various subsystems, it doesn't and shouldn't have claim on such generic names which don't have any qualifier indicating that they belong to cgroup.*
cgroup_subsys->subsys_idshould always equal the matchingcgroup_subsys_idenum; however, we require each controller to initialize it and then BUG if they don't match, which is a bit silly.This patch cleans up
cgroup_subsysnames and initialization by doing the followings.*
cgroup_subsys_idenums are now postfixed with_cgrp_id, and eachcgroup_subsyswith_cgrp_subsys.* With the above, renaming subsys identifiers to match the userland visible names doesn't cause any naming conflicts. All non-matching identifiers are renamed to match the official names.
cpu_cgroup-> cpu
mem_cgroup-> memory
perf ->perf_event* controllers no longer need to initialize ->subsys_id and ->name. They're generated in cgroup core and set automatically during boot.
* Redundant
cgroup_subsysdeclarations removed.* While updating BUG_ON()s in
cgroup_init_early(), convert them to WARN()s. BUGging that early during boot is stupid - the kernel can't print anything, even through serial console and the trap handler doesn't even link stack frame properly for back-tracing.This patch doesn't introduce any behavior changes.
v2: Rebased on top of
fe1217c4f3f7("net:net_cls: move cgroupfs
classid handling into core").
Quoted 15 lines
Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Li Zefan <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Balbir Singh <[email protected]>Cc KAMEZAWA Hiroyuki <[email protected]>Cc Aristeu Rozanski <[email protected]>Cc Serge E. Hallyn <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Vivek Goyal <[email protected]>Cc Thomas Graf <[email protected]>
for the freezer changes (I guess that's what you need from me).
Thanks!
Quoted 670 lines
--- block/blk-cgroup.c | 8 +++----- block/blk-cgroup.h | 2 +- fs/bio.c | 2 +- include/linux/cgroup.h | 7 ++++--- include/linux/cgroup_subsys.h | 6 +++--- include/linux/hugetlb_cgroup.h | 2 +- include/linux/memcontrol.h | 2 +- include/net/cls_cgroup.h | 2 +- include/net/netprio_cgroup.h | 2 +- kernel/cgroup.c | 34 ++++++++++++++++++++-------------- kernel/cgroup_freezer.c | 8 ++------ kernel/cpuset.c | 10 ++++------ kernel/events/core.c | 8 +++----- kernel/sched/core.c | 6 ++---- kernel/sched/cpuacct.c | 6 ++---- mm/hugetlb_cgroup.c | 9 +++------ mm/memcontrol.c | 22 ++++++++++------------ net/core/netclassid_cgroup.c | 6 ++---- net/core/netprio_cgroup.c | 4 +--- net/ipv4/tcp_memcontrol.c | 2 +- security/device_cgroup.c | 8 ++------ 21 files changed, 68 insertions(+), 88 deletions(-)block/blk-cgroup.c +3
-5@@ -906,16 +906,14 @@ static int blkcg_can_attach(struct cgroup_subsys_state *css,return ret; } -struct cgroup_subsys blkio_subsys = { - .name ="blkio" , +struct cgroup_subsys blkio_cgrp_subsys = { .css_alloc = blkcg_css_alloc, .css_offline = blkcg_css_offline, .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, - .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, }; -EXPORT_SYMBOL_GPL (blkio_subsys); +EXPORT_SYMBOL_GPL (blkio_cgrp_subsys);/** * blkcg_activate_policy - activate a blkcg policy on a request_queue @@ -1105,7 +1103,7 @@ int blkcg_policy_register(struct blkcg_policy *pol)/* everything is in place, add intf files for the new policy */ if (pol->cftypes) -WARN_ON (cgroup_add_cftypes (&blkio_subsys, pol->cftypes)); +WARN_ON (cgroup_add_cftypes (&blkio_cgrp_subsys, pol->cftypes)); ret =0 ; out_unlock:mutex_unlock (&blkcg_pol_mutex);block/blk-cgroup.h +1
-1@@ -186,7 +186,7 @@ static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)static inline struct blkcg *task_blkcg (struct task_struct *tsk) { -return css_to_blkcg (task_css (tsk, blkio_subsys_id)); +return css_to_blkcg (task_css (tsk, blkio_cgrp_id)); }static inline struct blkcg *bio_blkcg (struct bio *bio)fs/bio.c +1
-1@@ -2002,7 +2002,7 @@ int bio_associate_current(struct bio *bio)/* associate blkcg if exists */ rcu_read_lock (); - css =task_css (current, blkio_subsys_id); + css =task_css (current, blkio_cgrp_id);if (css &&css_tryget (css)) bio->bi_css = css;rcu_read_unlock ();include/linux/cgroup.h +4
-3@@ -41,7 +41,7 @@ extern int cgroupstats_build(struct cgroupstats *stats,extern int proc_cgroup_show (struct seq_file *,void *);/* define the enumeration of all cgroup subsystems */ -#define SUBSYS (_x) _x ## _subsys_id, +#define SUBSYS (_x) _x ## _cgrp_id,enum cgroup_subsys_id {#include <linux/cgroup_subsys.h> CGROUP_SUBSYS_COUNT,@@ -573,7 +573,6 @@ struct cgroup_subsys { struct task_struct *task);void (*bind)(struct cgroup_subsys_state *root_css); -int subsys_id;int disabled;int early_init;@@ -592,6 +591,8 @@ struct cgroup_subsys {bool broken_hierarchy;bool warned_broken_hierarchy; +/* the following two fields are initialized automtically during boot */ +int subsys_id;#define MAX_CGROUP_TYPE_NAMELEN 32const char *name;@@ -606,7 +607,7 @@ struct cgroup_subsys {struct cftype_set base_cftset; }; -#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys; +#define SUBSYS (_x) extern struct cgroup_subsys _x ## _cgrp_subsys;#include <linux/cgroup_subsys.h> #undef SUBSYSinclude/linux/cgroup_subsys.h +3
-3@@ -12,7 +12,7 @@ SUBSYS(debug)#endif #if IS_ENABLED (CONFIG_CGROUP_SCHED ) -SUBSYS(cpu_cgroup) +SUBSYS(cpu)#endif #if IS_ENABLED (CONFIG_CGROUP_CPUACCT )@@ -20,7 +20,7 @@ SUBSYS(cpuacct)#endif #if IS_ENABLED (CONFIG_MEMCG ) -SUBSYS(mem_cgroup) +SUBSYS(memory)#endif #if IS_ENABLED (CONFIG_CGROUP_DEVICE )@@ -40,7 +40,7 @@ SUBSYS(blkio)#endif #if IS_ENABLED (CONFIG_CGROUP_PERF ) -SUBSYS(perf) +SUBSYS(perf_event)#endif #if IS_ENABLED (CONFIG_CGROUP_NET_PRIO )include/linux/hugetlb_cgroup.h +1
-1@@ -49,7 +49,7 @@ int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)static inline bool hugetlb_cgroup_disabled (void ) { -if (hugetlb_subsys.disabled) +if (hugetlb_cgrp_subsys.disabled)return true;return false; }include/linux/memcontrol.h +1
-1@@ -162,7 +162,7 @@ extern int do_swap_account;static inline bool mem_cgroup_disabled (void ) { -if (mem_cgroup_subsys.disabled) +if (memory_cgrp_subsys.disabled)return true;return false; }include/net/cls_cgroup.h +1
-1@@ -34,7 +34,7 @@ static inline u32 task_cls_classid(struct task_struct *p)return 0 ;rcu_read_lock (); - classid =container_of (task_css (p, net_cls_subsys_id), + classid =container_of (task_css (p, net_cls_cgrp_id), struct cgroup_cls_state, css)->classid;rcu_read_unlock ();include/net/netprio_cgroup.h +1
-1@@ -33,7 +33,7 @@ static inline u32 task_netprioidx(struct task_struct *p)u32 idx;rcu_read_lock (); - css =task_css (p, net_prio_subsys_id); + css =task_css (p, net_prio_cgrp_id); idx = css->cgroup->id;rcu_read_unlock ();return idx;kernel/cgroup.c +20
-14@@ -120,10 +120,18 @@ static struct workqueue_struct *cgroup_destroy_wq;static struct workqueue_struct *cgroup_pidlist_destroy_wq;/* generate an array of cgroup subsystem pointers */ -#define SUBSYS (_x) [_x ## _subsys_id] = &_x ## _subsys, +#define SUBSYS (_x) [_x ## _cgrp_id] = &_x ## _cgrp_subsys, static struct cgroup_subsys *cgroup_subsys[] = {#include <linux/cgroup_subsys.h> }; +#undef SUBSYS + +/* array of cgroup subsystem names */ +#define SUBSYS (_x) [_x ## _cgrp_id] = #_x, +static const char *cgroup_subsys_name[] = { +#include <linux/cgroup_subsys.h> +}; +#undef SUBSYS/* * The dummy hierarchy, reserved for the subsystems that are otherwise @@ -1076,7 +1084,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)BUG_ON (!mutex_is_locked (&cgroup_mutex));#ifdef CONFIG_CPUSETS - mask = ~(1UL << cpuset_subsys_id); + mask = ~(1UL << cpuset_cgrp_id);#endif memset (opts,0 ,sizeof (*opts));@@ -4518,15 +4526,15 @@ int __init cgroup_init_early(void)list_add (&init_cgrp_cset_link.cgrp_link, &init_css_set.cgrp_links);for_each_subsys (ss, i) { -BUG_ON (!ss->name); -BUG_ON (strlen (ss->name) >MAX_CGROUP_TYPE_NAMELEN ); -BUG_ON (!ss->css_alloc); -BUG_ON (!ss->css_free); -if (ss->subsys_id != i) { -printk (KERN_ERR "cgroup: Subsys %s id == %d\n" , - ss->name, ss->subsys_id); -BUG (); - } +WARN (!ss->css_alloc || !ss->css_free || ss->name || ss->subsys_id, +"invalid cgroup_subsys %d:%s css_alloc=%p css_free=%p name:id=%d:%s\n" , + i, cgroup_subsys_name[i], ss->css_alloc, ss->css_free, + ss->subsys_id, ss->name); +WARN (strlen (cgroup_subsys_name[i]) >MAX_CGROUP_TYPE_NAMELEN , +"cgroup_subsys_name %s too long\n" , cgroup_subsys_name[i]); + + ss->subsys_id = i; + ss->name = cgroup_subsys_name[i];if (ss->early_init)cgroup_init_subsys (ss);@@ -5156,11 +5164,9 @@ static struct cftype debug_files[] = { { } /* terminate */ }; -struct cgroup_subsys debug_subsys = { - .name ="debug" , +struct cgroup_subsys debug_cgrp_subsys = { .css_alloc = debug_css_alloc, .css_free = debug_css_free, - .subsys_id = debug_subsys_id, .base_cftypes = debug_files, };#endif /* CONFIG_CGROUP_DEBUG */ kernel/cgroup_freezer.c +2
-6@@ -52,7 +52,7 @@ static inline struct freezer *css_freezer(struct cgroup_subsys_state *css)static inline struct freezer *task_freezer (struct task_struct *task) { -return css_freezer (task_css (task, freezer_subsys_id)); +return css_freezer (task_css (task, freezer_cgrp_id)); }static struct freezer *parent_freezer (struct freezer *freezer)@@ -84,8 +84,6 @@ static const char *freezer_state_strs(unsigned int state)return "THAWED" ; }; -struct cgroup_subsys freezer_subsys; -static struct cgroup_subsys_state *freezer_css_alloc (struct cgroup_subsys_state *parent_css) {@@ -473,13 +471,11 @@ static struct cftype files[] = { { }/* terminate */ }; -struct cgroup_subsys freezer_subsys = { - .name ="freezer" , +struct cgroup_subsys freezer_cgrp_subsys = { .css_alloc = freezer_css_alloc, .css_online = freezer_css_online, .css_offline = freezer_css_offline, .css_free = freezer_css_free, - .subsys_id = freezer_subsys_id, .attach = freezer_attach, .fork = freezer_fork, .base_cftypes = files,kernel/cpuset.c +4
-6@@ -119,7 +119,7 @@ static inline struct cpuset *css_cs(struct cgroup_subsys_state *css)/* Retrieve the cpuset for a task */ static inline struct cpuset *task_cs (struct task_struct *task) { -return css_cs (task_css (task, cpuset_subsys_id)); +return css_cs (task_css (task, cpuset_cgrp_id)); }static inline struct cpuset *parent_cs (struct cpuset *cs)@@ -1521,7 +1521,7 @@ static void cpuset_attach(struct cgroup_subsys_state *css,struct task_struct *task;struct task_struct *leader =cgroup_taskset_first (tset);struct cgroup_subsys_state *oldcss =cgroup_taskset_cur_css (tset, - cpuset_subsys_id); + cpuset_cgrp_id);struct cpuset *cs =css_cs (css);struct cpuset *oldcs =css_cs (oldcss);struct cpuset *cpus_cs =effective_cpumask_cpuset (cs);@@ -2024,8 +2024,7 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)kfree (cs); } -struct cgroup_subsys cpuset_subsys = { - .name ="cpuset" , +struct cgroup_subsys cpuset_cgrp_subsys = { .css_alloc = cpuset_css_alloc, .css_online = cpuset_css_online, .css_offline = cpuset_css_offline,@@ -2033,7 +2032,6 @@ struct cgroup_subsys cpuset_subsys = { .can_attach = cpuset_can_attach, .cancel_attach = cpuset_cancel_attach, .attach = cpuset_attach, - .subsys_id = cpuset_subsys_id, .base_cftypes = files, .early_init = 1, };@@ -2699,7 +2697,7 @@ int proc_cpuset_show(struct seq_file *m, void *unused_v) goto out_free;rcu_read_lock (); - css =task_css (tsk, cpuset_subsys_id); + css =task_css (tsk, cpuset_cgrp_id); retval =cgroup_path (css->cgroup, buf,PAGE_SIZE );rcu_read_unlock ();if (retval <0 )kernel/events/core.c +3
-5@@ -342,7 +342,7 @@ struct perf_cgroup {static inline struct perf_cgroup *perf_cgroup_from_task (struct task_struct *task) { -return container_of (task_css (task, perf_subsys_id), +return container_of (task_css (task, perf_event_cgrp_id), struct perf_cgroup, css); }@@ -595,7 +595,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,rcu_read_lock (); - css =css_from_dir (f.file->f_dentry, &perf_subsys); + css =css_from_dir (f.file->f_dentry, &perf_event_cgrp_subsys);if (IS_ERR (css)) { ret =PTR_ERR (css); goto out;@@ -8055,9 +8055,7 @@ static void perf_cgroup_exit(struct cgroup_subsys_state *css,task_function_call (task, __perf_cgroup_move, task); } -struct cgroup_subsys perf_subsys = { - .name ="perf_event" , - .subsys_id = perf_subsys_id, +struct cgroup_subsys perf_event_cgrp_subsys = { .css_alloc = perf_cgroup_css_alloc, .css_free = perf_cgroup_css_free, .exit = perf_cgroup_exit,kernel/sched/core.c +2
-4@@ -7174,7 +7174,7 @@ void sched_move_task(struct task_struct *tsk)if (unlikely (running)) tsk->sched_class->put_prev_task (rq, tsk); - tg =container_of (task_css_check (tsk, cpu_cgroup_subsys_id, + tg =container_of (task_css_check (tsk, cpu_cgrp_id,lockdep_is_held (&tsk->sighand->siglock)), struct task_group, css); tg =autogroup_task_group (tsk, tg);@@ -7955,8 +7955,7 @@ static struct cftype cpu_files[] = { { }/* terminate */ }; -struct cgroup_subsys cpu_cgroup_subsys = { - .name ="cpu" , +struct cgroup_subsys cpu_cgrp_subsys = { .css_alloc = cpu_cgroup_css_alloc, .css_free = cpu_cgroup_css_free, .css_online = cpu_cgroup_css_online,@@ -7964,7 +7963,6 @@ struct cgroup_subsys cpu_cgroup_subsys = { .can_attach = cpu_cgroup_can_attach, .attach = cpu_cgroup_attach, .exit = cpu_cgroup_exit, - .subsys_id = cpu_cgroup_subsys_id, .base_cftypes = cpu_files, .early_init = 1, };kernel/sched/cpuacct.c +2
-4@@ -41,7 +41,7 @@ static inline struct cpuacct *css_ca(struct cgroup_subsys_state *css)/* return cpu accounting group to which this task belongs */ static inline struct cpuacct *task_ca (struct task_struct *tsk) { -return css_ca (task_css (tsk, cpuacct_subsys_id)); +return css_ca (task_css (tsk, cpuacct_cgrp_id)); }static inline struct cpuacct *parent_ca (struct cpuacct *ca)@@ -275,11 +275,9 @@ void cpuacct_account_field(struct task_struct *p, int index, u64 val)rcu_read_unlock (); } -struct cgroup_subsys cpuacct_subsys = { - .name ="cpuacct" , +struct cgroup_subsys cpuacct_cgrp_subsys = { .css_alloc = cpuacct_css_alloc, .css_free = cpuacct_css_free, - .subsys_id = cpuacct_subsys_id, .base_cftypes = files, .early_init =1 , };mm/hugetlb_cgroup.c +3
-6@@ -30,7 +30,6 @@ struct hugetlb_cgroup {#define MEMFILE_IDX (val) (((val) >> 16) & 0xffff)#define MEMFILE_ATTR (val) ((val) & 0xffff) -struct cgroup_subsys hugetlb_subsys__read_mostly ;static struct hugetlb_cgroup *root_h_cgroup__read_mostly ; static inline@@ -42,7 +41,7 @@ struct hugetlb_cgroup *hugetlb_cgroup_from_css(struct cgroup_subsys_state *s)static inline struct hugetlb_cgroup *hugetlb_cgroup_from_task (struct task_struct *task) { -return hugetlb_cgroup_from_css (task_css (task, hugetlb_subsys_id)); +return hugetlb_cgroup_from_css (task_css (task, hugetlb_cgrp_id)); }static inline bool hugetlb_cgroup_is_root (struct hugetlb_cgroup *h_cg)@@ -358,7 +357,7 @@ static void __init __hugetlb_cgroup_file_init(int idx) cft = &h->cgroup_files[4 ];memset (cft,0 ,sizeof (*cft)); -WARN_ON (cgroup_add_cftypes (&hugetlb_subsys, h->cgroup_files)); +WARN_ON (cgroup_add_cftypes (&hugetlb_cgrp_subsys, h->cgroup_files));return ; }@@ -402,10 +401,8 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)return ; } -struct cgroup_subsys hugetlb_subsys = { - .name ="hugetlb" , +struct cgroup_subsys hugetlb_cgrp_subsys = { .css_alloc = hugetlb_cgroup_css_alloc, .css_offline = hugetlb_cgroup_css_offline, .css_free = hugetlb_cgroup_css_free, - .subsys_id = hugetlb_subsys_id, };mm/memcontrol.c +10
-12@@ -66,8 +66,8 @@#include <trace/events/vmscan.h> -struct cgroup_subsys mem_cgroup_subsys__read_mostly ; -EXPORT_SYMBOL (mem_cgroup_subsys); +struct cgroup_subsys memory_cgrp_subsys__read_mostly ; +EXPORT_SYMBOL (memory_cgrp_subsys);#define MEM_CGROUP_RECLAIM_RETRIES 5static struct mem_cgroup *root_mem_cgroup__read_mostly ;@@ -538,7 +538,7 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) {struct cgroup_subsys_state *css; - css =css_from_id (id -1 , &mem_cgroup_subsys); + css =css_from_id (id -1 , &memory_cgrp_subsys);return mem_cgroup_from_css (css); }@@ -1072,7 +1072,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)if (unlikely (!p))return NULL ; -return mem_cgroup_from_css (task_css (p, mem_cgroup_subsys_id)); +return mem_cgroup_from_css (task_css (p, memory_cgrp_id)); }struct mem_cgroup *try_get_mem_cgroup_from_mm (struct mm_struct *mm)@@ -1702,7 +1702,7 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)rcu_read_lock (); mem_cgrp = memcg->css.cgroup; - task_cgrp =task_cgroup (p, mem_cgroup_subsys_id); + task_cgrp =task_cgroup (p, memory_cgrp_id); ret =cgroup_path (task_cgrp, memcg_name,PATH_MAX );if (ret <0 ) {@@ -6188,7 +6188,7 @@ static int memcg_write_event_control(struct cgroup_subsys_state *css, ret = -EINVAL ; cfile_css =css_from_dir (cfile.file->f_dentry->d_parent, - &mem_cgroup_subsys); + &memory_cgrp_subsys);if (cfile_css == css &&css_tryget (css)) ret =0 ;@@ -6567,11 +6567,11 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)* unfortunate state in our controller. */ if (parent != root_mem_cgroup) - mem_cgroup_subsys.broken_hierarchy = true; + memory_cgrp_subsys.broken_hierarchy = true; }mutex_unlock (&memcg_create_mutex); -return memcg_init_kmem (memcg, &mem_cgroup_subsys); +return memcg_init_kmem (memcg, &memory_cgrp_subsys); }/* @@ -7265,9 +7265,7 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css)mem_cgroup_from_css (root_css)->use_hierarchy = true; } -struct cgroup_subsys mem_cgroup_subsys = { - .name ="memory" , - .subsys_id = mem_cgroup_subsys_id, +struct cgroup_subsys memory_cgrp_subsys = { .css_alloc = mem_cgroup_css_alloc, .css_online = mem_cgroup_css_online, .css_offline = mem_cgroup_css_offline,@@ -7293,7 +7291,7 @@ __setup("swapaccount=", enable_swap_account);static void __init memsw_file_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, memsw_cgroup_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, memsw_cgroup_files)); }static void __init enable_swap_cgroup (void )net/core/netclassid_cgroup.c +2
-4@@ -23,7 +23,7 @@ static inline struct cgroup_cls_state *css_cls_state(struct cgroup_subsys_statestruct cgroup_cls_state *task_cls_state (struct task_struct *p) { -return css_cls_state (task_css (p, net_cls_subsys_id)); +return css_cls_state (task_css (p, net_cls_cgrp_id)); }EXPORT_SYMBOL_GPL (task_cls_state);@@ -102,12 +102,10 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_cls_subsys = { - .name ="net_cls" , +struct cgroup_subsys net_cls_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = cgrp_attach, - .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, };net/core/netprio_cgroup.c +1
-3@@ -244,13 +244,11 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_prio_subsys = { - .name ="net_prio" , +struct cgroup_subsys net_prio_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = net_prio_attach, - .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files, };net/ipv4/tcp_memcontrol.c +1
-1@@ -219,7 +219,7 @@ static struct cftype tcp_files[] = {static int __init tcp_memcontrol_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, tcp_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, tcp_files));return 0 ; }__initcall (tcp_memcontrol_init);security/device_cgroup.c +2
-6@@ -58,11 +58,9 @@ static inline struct dev_cgroup *css_to_devcgroup(struct cgroup_subsys_state *s)static inline struct dev_cgroup *task_devcgroup (struct task_struct *task) { -return css_to_devcgroup (task_css (task, devices_subsys_id)); +return css_to_devcgroup (task_css (task, devices_cgrp_id)); } -struct cgroup_subsys devices_subsys; -/* * called under devcgroup_mutex */ @@ -684,13 +682,11 @@ static struct cftype dev_cgroup_files[] = { { }/* terminate */ }; -struct cgroup_subsys devices_subsys = { - .name ="devices" , +struct cgroup_subsys devices_cgrp_subsys = { .css_alloc = devcgroup_css_alloc, .css_free = devcgroup_css_free, .css_online = devcgroup_online, .css_offline = devcgroup_offline, - .subsys_id = devices_subsys_id, .base_cftypes = dev_cgroup_files, };
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
A message that is not in the archive (sent off-list or not yet received): 1390952641-15950-4-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Rafael J. Wysocki
Acked-byRe: [PATCH 3/6] cgroup: clean up cgroup_subsys names and initialization
Quoted 46 lines · Tejun Heo
cgroup_subsysis a bit messier than it needs to be.* The name of a subsys can be different from its internal identifier defined in
cgroup_subsys.h. Most subsystems use the matching name but three - cpu, memory andperf_event- use different ones.*
cgroup_subsys_idenums are postfixed with_subsys_idand eachcgroup_subsysis postfixed with_subsys.cgroup.his widely included throughout various subsystems, it doesn't and shouldn't have claim on such generic names which don't have any qualifier indicating that they belong to cgroup.*
cgroup_subsys->subsys_idshould always equal the matchingcgroup_subsys_idenum; however, we require each controller to initialize it and then BUG if they don't match, which is a bit silly.This patch cleans up
cgroup_subsysnames and initialization by doing the followings.*
cgroup_subsys_idenums are now postfixed with_cgrp_id, and eachcgroup_subsyswith_cgrp_subsys.* With the above, renaming subsys identifiers to match the userland visible names doesn't cause any naming conflicts. All non-matching identifiers are renamed to match the official names.
cpu_cgroup-> cpu
mem_cgroup-> memory
perf ->perf_event* controllers no longer need to initialize ->subsys_id and ->name. They're generated in cgroup core and set automatically during boot.
* Redundant
cgroup_subsysdeclarations removed.* While updating BUG_ON()s in
cgroup_init_early(), convert them to WARN()s. BUGging that early during boot is stupid - the kernel can't print anything, even through serial console and the trap handler doesn't even link stack frame properly for back-tracing.This patch doesn't introduce any behavior changes.
v2: Rebased on top of
fe1217c4f3f7("net:net_cls: move cgroupfs
classid handling into core").
Quoted 15 lines
Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Li Zefan <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Balbir Singh <[email protected]>Cc KAMEZAWA Hiroyuki <[email protected]>Cc Aristeu Rozanski <[email protected]>Cc Serge E. Hallyn <serue-r/[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Vivek Goyal <[email protected]>Cc Thomas Graf <tgraf-G/[email protected]>
for the freezer changes (I guess that's what you need from me).
Thanks!
Quoted 670 lines
--- block/blk-cgroup.c | 8 +++----- block/blk-cgroup.h | 2 +- fs/bio.c | 2 +- include/linux/cgroup.h | 7 ++++--- include/linux/cgroup_subsys.h | 6 +++--- include/linux/hugetlb_cgroup.h | 2 +- include/linux/memcontrol.h | 2 +- include/net/cls_cgroup.h | 2 +- include/net/netprio_cgroup.h | 2 +- kernel/cgroup.c | 34 ++++++++++++++++++++-------------- kernel/cgroup_freezer.c | 8 ++------ kernel/cpuset.c | 10 ++++------ kernel/events/core.c | 8 +++----- kernel/sched/core.c | 6 ++---- kernel/sched/cpuacct.c | 6 ++---- mm/hugetlb_cgroup.c | 9 +++------ mm/memcontrol.c | 22 ++++++++++------------ net/core/netclassid_cgroup.c | 6 ++---- net/core/netprio_cgroup.c | 4 +--- net/ipv4/tcp_memcontrol.c | 2 +- security/device_cgroup.c | 8 ++------ 21 files changed, 68 insertions(+), 88 deletions(-)block/blk-cgroup.c +3
-5@@ -906,16 +906,14 @@ static int blkcg_can_attach(struct cgroup_subsys_state *css,return ret; } -struct cgroup_subsys blkio_subsys = { - .name ="blkio" , +struct cgroup_subsys blkio_cgrp_subsys = { .css_alloc = blkcg_css_alloc, .css_offline = blkcg_css_offline, .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, - .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, }; -EXPORT_SYMBOL_GPL (blkio_subsys); +EXPORT_SYMBOL_GPL (blkio_cgrp_subsys);/** * blkcg_activate_policy - activate a blkcg policy on a request_queue @@ -1105,7 +1103,7 @@ int blkcg_policy_register(struct blkcg_policy *pol)/* everything is in place, add intf files for the new policy */ if (pol->cftypes) -WARN_ON (cgroup_add_cftypes (&blkio_subsys, pol->cftypes)); +WARN_ON (cgroup_add_cftypes (&blkio_cgrp_subsys, pol->cftypes)); ret =0 ; out_unlock:mutex_unlock (&blkcg_pol_mutex);block/blk-cgroup.h +1
-1@@ -186,7 +186,7 @@ static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)static inline struct blkcg *task_blkcg (struct task_struct *tsk) { -return css_to_blkcg (task_css (tsk, blkio_subsys_id)); +return css_to_blkcg (task_css (tsk, blkio_cgrp_id)); }static inline struct blkcg *bio_blkcg (struct bio *bio)fs/bio.c +1
-1@@ -2002,7 +2002,7 @@ int bio_associate_current(struct bio *bio)/* associate blkcg if exists */ rcu_read_lock (); - css =task_css (current, blkio_subsys_id); + css =task_css (current, blkio_cgrp_id);if (css &&css_tryget (css)) bio->bi_css = css;rcu_read_unlock ();include/linux/cgroup.h +4
-3@@ -41,7 +41,7 @@ extern int cgroupstats_build(struct cgroupstats *stats,extern int proc_cgroup_show (struct seq_file *,void *);/* define the enumeration of all cgroup subsystems */ -#define SUBSYS (_x) _x ## _subsys_id, +#define SUBSYS (_x) _x ## _cgrp_id,enum cgroup_subsys_id {#include <linux/cgroup_subsys.h> CGROUP_SUBSYS_COUNT,@@ -573,7 +573,6 @@ struct cgroup_subsys { struct task_struct *task);void (*bind)(struct cgroup_subsys_state *root_css); -int subsys_id;int disabled;int early_init;@@ -592,6 +591,8 @@ struct cgroup_subsys {bool broken_hierarchy;bool warned_broken_hierarchy; +/* the following two fields are initialized automtically during boot */ +int subsys_id;#define MAX_CGROUP_TYPE_NAMELEN 32const char *name;@@ -606,7 +607,7 @@ struct cgroup_subsys {struct cftype_set base_cftset; }; -#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys; +#define SUBSYS (_x) extern struct cgroup_subsys _x ## _cgrp_subsys;#include <linux/cgroup_subsys.h> #undef SUBSYSinclude/linux/cgroup_subsys.h +3
-3@@ -12,7 +12,7 @@ SUBSYS(debug)#endif #if IS_ENABLED (CONFIG_CGROUP_SCHED ) -SUBSYS(cpu_cgroup) +SUBSYS(cpu)#endif #if IS_ENABLED (CONFIG_CGROUP_CPUACCT )@@ -20,7 +20,7 @@ SUBSYS(cpuacct)#endif #if IS_ENABLED (CONFIG_MEMCG ) -SUBSYS(mem_cgroup) +SUBSYS(memory)#endif #if IS_ENABLED (CONFIG_CGROUP_DEVICE )@@ -40,7 +40,7 @@ SUBSYS(blkio)#endif #if IS_ENABLED (CONFIG_CGROUP_PERF ) -SUBSYS(perf) +SUBSYS(perf_event)#endif #if IS_ENABLED (CONFIG_CGROUP_NET_PRIO )include/linux/hugetlb_cgroup.h +1
-1@@ -49,7 +49,7 @@ int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)static inline bool hugetlb_cgroup_disabled (void ) { -if (hugetlb_subsys.disabled) +if (hugetlb_cgrp_subsys.disabled)return true;return false; }include/linux/memcontrol.h +1
-1@@ -162,7 +162,7 @@ extern int do_swap_account;static inline bool mem_cgroup_disabled (void ) { -if (mem_cgroup_subsys.disabled) +if (memory_cgrp_subsys.disabled)return true;return false; }include/net/cls_cgroup.h +1
-1@@ -34,7 +34,7 @@ static inline u32 task_cls_classid(struct task_struct *p)return 0 ;rcu_read_lock (); - classid =container_of (task_css (p, net_cls_subsys_id), + classid =container_of (task_css (p, net_cls_cgrp_id), struct cgroup_cls_state, css)->classid;rcu_read_unlock ();include/net/netprio_cgroup.h +1
-1@@ -33,7 +33,7 @@ static inline u32 task_netprioidx(struct task_struct *p)u32 idx;rcu_read_lock (); - css =task_css (p, net_prio_subsys_id); + css =task_css (p, net_prio_cgrp_id); idx = css->cgroup->id;rcu_read_unlock ();return idx;kernel/cgroup.c +20
-14@@ -120,10 +120,18 @@ static struct workqueue_struct *cgroup_destroy_wq;static struct workqueue_struct *cgroup_pidlist_destroy_wq;/* generate an array of cgroup subsystem pointers */ -#define SUBSYS (_x) [_x ## _subsys_id] = &_x ## _subsys, +#define SUBSYS (_x) [_x ## _cgrp_id] = &_x ## _cgrp_subsys, static struct cgroup_subsys *cgroup_subsys[] = {#include <linux/cgroup_subsys.h> }; +#undef SUBSYS + +/* array of cgroup subsystem names */ +#define SUBSYS (_x) [_x ## _cgrp_id] = #_x, +static const char *cgroup_subsys_name[] = { +#include <linux/cgroup_subsys.h> +}; +#undef SUBSYS/* * The dummy hierarchy, reserved for the subsystems that are otherwise @@ -1076,7 +1084,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)BUG_ON (!mutex_is_locked (&cgroup_mutex));#ifdef CONFIG_CPUSETS - mask = ~(1UL << cpuset_subsys_id); + mask = ~(1UL << cpuset_cgrp_id);#endif memset (opts,0 ,sizeof (*opts));@@ -4518,15 +4526,15 @@ int __init cgroup_init_early(void)list_add (&init_cgrp_cset_link.cgrp_link, &init_css_set.cgrp_links);for_each_subsys (ss, i) { -BUG_ON (!ss->name); -BUG_ON (strlen (ss->name) >MAX_CGROUP_TYPE_NAMELEN ); -BUG_ON (!ss->css_alloc); -BUG_ON (!ss->css_free); -if (ss->subsys_id != i) { -printk (KERN_ERR "cgroup: Subsys %s id == %d\n" , - ss->name, ss->subsys_id); -BUG (); - } +WARN (!ss->css_alloc || !ss->css_free || ss->name || ss->subsys_id, +"invalid cgroup_subsys %d:%s css_alloc=%p css_free=%p name:id=%d:%s\n" , + i, cgroup_subsys_name[i], ss->css_alloc, ss->css_free, + ss->subsys_id, ss->name); +WARN (strlen (cgroup_subsys_name[i]) >MAX_CGROUP_TYPE_NAMELEN , +"cgroup_subsys_name %s too long\n" , cgroup_subsys_name[i]); + + ss->subsys_id = i; + ss->name = cgroup_subsys_name[i];if (ss->early_init)cgroup_init_subsys (ss);@@ -5156,11 +5164,9 @@ static struct cftype debug_files[] = { { } /* terminate */ }; -struct cgroup_subsys debug_subsys = { - .name ="debug" , +struct cgroup_subsys debug_cgrp_subsys = { .css_alloc = debug_css_alloc, .css_free = debug_css_free, - .subsys_id = debug_subsys_id, .base_cftypes = debug_files, };#endif /* CONFIG_CGROUP_DEBUG */ kernel/cgroup_freezer.c +2
-6@@ -52,7 +52,7 @@ static inline struct freezer *css_freezer(struct cgroup_subsys_state *css)static inline struct freezer *task_freezer (struct task_struct *task) { -return css_freezer (task_css (task, freezer_subsys_id)); +return css_freezer (task_css (task, freezer_cgrp_id)); }static struct freezer *parent_freezer (struct freezer *freezer)@@ -84,8 +84,6 @@ static const char *freezer_state_strs(unsigned int state)return "THAWED" ; }; -struct cgroup_subsys freezer_subsys; -static struct cgroup_subsys_state *freezer_css_alloc (struct cgroup_subsys_state *parent_css) {@@ -473,13 +471,11 @@ static struct cftype files[] = { { }/* terminate */ }; -struct cgroup_subsys freezer_subsys = { - .name ="freezer" , +struct cgroup_subsys freezer_cgrp_subsys = { .css_alloc = freezer_css_alloc, .css_online = freezer_css_online, .css_offline = freezer_css_offline, .css_free = freezer_css_free, - .subsys_id = freezer_subsys_id, .attach = freezer_attach, .fork = freezer_fork, .base_cftypes = files,kernel/cpuset.c +4
-6@@ -119,7 +119,7 @@ static inline struct cpuset *css_cs(struct cgroup_subsys_state *css)/* Retrieve the cpuset for a task */ static inline struct cpuset *task_cs (struct task_struct *task) { -return css_cs (task_css (task, cpuset_subsys_id)); +return css_cs (task_css (task, cpuset_cgrp_id)); }static inline struct cpuset *parent_cs (struct cpuset *cs)@@ -1521,7 +1521,7 @@ static void cpuset_attach(struct cgroup_subsys_state *css,struct task_struct *task;struct task_struct *leader =cgroup_taskset_first (tset);struct cgroup_subsys_state *oldcss =cgroup_taskset_cur_css (tset, - cpuset_subsys_id); + cpuset_cgrp_id);struct cpuset *cs =css_cs (css);struct cpuset *oldcs =css_cs (oldcss);struct cpuset *cpus_cs =effective_cpumask_cpuset (cs);@@ -2024,8 +2024,7 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)kfree (cs); } -struct cgroup_subsys cpuset_subsys = { - .name ="cpuset" , +struct cgroup_subsys cpuset_cgrp_subsys = { .css_alloc = cpuset_css_alloc, .css_online = cpuset_css_online, .css_offline = cpuset_css_offline,@@ -2033,7 +2032,6 @@ struct cgroup_subsys cpuset_subsys = { .can_attach = cpuset_can_attach, .cancel_attach = cpuset_cancel_attach, .attach = cpuset_attach, - .subsys_id = cpuset_subsys_id, .base_cftypes = files, .early_init = 1, };@@ -2699,7 +2697,7 @@ int proc_cpuset_show(struct seq_file *m, void *unused_v) goto out_free;rcu_read_lock (); - css =task_css (tsk, cpuset_subsys_id); + css =task_css (tsk, cpuset_cgrp_id); retval =cgroup_path (css->cgroup, buf,PAGE_SIZE );rcu_read_unlock ();if (retval <0 )kernel/events/core.c +3
-5@@ -342,7 +342,7 @@ struct perf_cgroup {static inline struct perf_cgroup *perf_cgroup_from_task (struct task_struct *task) { -return container_of (task_css (task, perf_subsys_id), +return container_of (task_css (task, perf_event_cgrp_id), struct perf_cgroup, css); }@@ -595,7 +595,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,rcu_read_lock (); - css =css_from_dir (f.file->f_dentry, &perf_subsys); + css =css_from_dir (f.file->f_dentry, &perf_event_cgrp_subsys);if (IS_ERR (css)) { ret =PTR_ERR (css); goto out;@@ -8055,9 +8055,7 @@ static void perf_cgroup_exit(struct cgroup_subsys_state *css,task_function_call (task, __perf_cgroup_move, task); } -struct cgroup_subsys perf_subsys = { - .name ="perf_event" , - .subsys_id = perf_subsys_id, +struct cgroup_subsys perf_event_cgrp_subsys = { .css_alloc = perf_cgroup_css_alloc, .css_free = perf_cgroup_css_free, .exit = perf_cgroup_exit,kernel/sched/core.c +2
-4@@ -7174,7 +7174,7 @@ void sched_move_task(struct task_struct *tsk)if (unlikely (running)) tsk->sched_class->put_prev_task (rq, tsk); - tg =container_of (task_css_check (tsk, cpu_cgroup_subsys_id, + tg =container_of (task_css_check (tsk, cpu_cgrp_id,lockdep_is_held (&tsk->sighand->siglock)), struct task_group, css); tg =autogroup_task_group (tsk, tg);@@ -7955,8 +7955,7 @@ static struct cftype cpu_files[] = { { }/* terminate */ }; -struct cgroup_subsys cpu_cgroup_subsys = { - .name ="cpu" , +struct cgroup_subsys cpu_cgrp_subsys = { .css_alloc = cpu_cgroup_css_alloc, .css_free = cpu_cgroup_css_free, .css_online = cpu_cgroup_css_online,@@ -7964,7 +7963,6 @@ struct cgroup_subsys cpu_cgroup_subsys = { .can_attach = cpu_cgroup_can_attach, .attach = cpu_cgroup_attach, .exit = cpu_cgroup_exit, - .subsys_id = cpu_cgroup_subsys_id, .base_cftypes = cpu_files, .early_init = 1, };kernel/sched/cpuacct.c +2
-4@@ -41,7 +41,7 @@ static inline struct cpuacct *css_ca(struct cgroup_subsys_state *css)/* return cpu accounting group to which this task belongs */ static inline struct cpuacct *task_ca (struct task_struct *tsk) { -return css_ca (task_css (tsk, cpuacct_subsys_id)); +return css_ca (task_css (tsk, cpuacct_cgrp_id)); }static inline struct cpuacct *parent_ca (struct cpuacct *ca)@@ -275,11 +275,9 @@ void cpuacct_account_field(struct task_struct *p, int index, u64 val)rcu_read_unlock (); } -struct cgroup_subsys cpuacct_subsys = { - .name ="cpuacct" , +struct cgroup_subsys cpuacct_cgrp_subsys = { .css_alloc = cpuacct_css_alloc, .css_free = cpuacct_css_free, - .subsys_id = cpuacct_subsys_id, .base_cftypes = files, .early_init =1 , };mm/hugetlb_cgroup.c +3
-6@@ -30,7 +30,6 @@ struct hugetlb_cgroup {#define MEMFILE_IDX (val) (((val) >> 16) & 0xffff)#define MEMFILE_ATTR (val) ((val) & 0xffff) -struct cgroup_subsys hugetlb_subsys__read_mostly ;static struct hugetlb_cgroup *root_h_cgroup__read_mostly ; static inline@@ -42,7 +41,7 @@ struct hugetlb_cgroup *hugetlb_cgroup_from_css(struct cgroup_subsys_state *s)static inline struct hugetlb_cgroup *hugetlb_cgroup_from_task (struct task_struct *task) { -return hugetlb_cgroup_from_css (task_css (task, hugetlb_subsys_id)); +return hugetlb_cgroup_from_css (task_css (task, hugetlb_cgrp_id)); }static inline bool hugetlb_cgroup_is_root (struct hugetlb_cgroup *h_cg)@@ -358,7 +357,7 @@ static void __init __hugetlb_cgroup_file_init(int idx) cft = &h->cgroup_files[4 ];memset (cft,0 ,sizeof (*cft)); -WARN_ON (cgroup_add_cftypes (&hugetlb_subsys, h->cgroup_files)); +WARN_ON (cgroup_add_cftypes (&hugetlb_cgrp_subsys, h->cgroup_files));return ; }@@ -402,10 +401,8 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)return ; } -struct cgroup_subsys hugetlb_subsys = { - .name ="hugetlb" , +struct cgroup_subsys hugetlb_cgrp_subsys = { .css_alloc = hugetlb_cgroup_css_alloc, .css_offline = hugetlb_cgroup_css_offline, .css_free = hugetlb_cgroup_css_free, - .subsys_id = hugetlb_subsys_id, };mm/memcontrol.c +10
-12@@ -66,8 +66,8 @@#include <trace/events/vmscan.h> -struct cgroup_subsys mem_cgroup_subsys__read_mostly ; -EXPORT_SYMBOL (mem_cgroup_subsys); +struct cgroup_subsys memory_cgrp_subsys__read_mostly ; +EXPORT_SYMBOL (memory_cgrp_subsys);#define MEM_CGROUP_RECLAIM_RETRIES 5static struct mem_cgroup *root_mem_cgroup__read_mostly ;@@ -538,7 +538,7 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) {struct cgroup_subsys_state *css; - css =css_from_id (id -1 , &mem_cgroup_subsys); + css =css_from_id (id -1 , &memory_cgrp_subsys);return mem_cgroup_from_css (css); }@@ -1072,7 +1072,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)if (unlikely (!p))return NULL ; -return mem_cgroup_from_css (task_css (p, mem_cgroup_subsys_id)); +return mem_cgroup_from_css (task_css (p, memory_cgrp_id)); }struct mem_cgroup *try_get_mem_cgroup_from_mm (struct mm_struct *mm)@@ -1702,7 +1702,7 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)rcu_read_lock (); mem_cgrp = memcg->css.cgroup; - task_cgrp =task_cgroup (p, mem_cgroup_subsys_id); + task_cgrp =task_cgroup (p, memory_cgrp_id); ret =cgroup_path (task_cgrp, memcg_name,PATH_MAX );if (ret <0 ) {@@ -6188,7 +6188,7 @@ static int memcg_write_event_control(struct cgroup_subsys_state *css, ret = -EINVAL ; cfile_css =css_from_dir (cfile.file->f_dentry->d_parent, - &mem_cgroup_subsys); + &memory_cgrp_subsys);if (cfile_css == css &&css_tryget (css)) ret =0 ;@@ -6567,11 +6567,11 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)* unfortunate state in our controller. */ if (parent != root_mem_cgroup) - mem_cgroup_subsys.broken_hierarchy = true; + memory_cgrp_subsys.broken_hierarchy = true; }mutex_unlock (&memcg_create_mutex); -return memcg_init_kmem (memcg, &mem_cgroup_subsys); +return memcg_init_kmem (memcg, &memory_cgrp_subsys); }/* @@ -7265,9 +7265,7 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css)mem_cgroup_from_css (root_css)->use_hierarchy = true; } -struct cgroup_subsys mem_cgroup_subsys = { - .name ="memory" , - .subsys_id = mem_cgroup_subsys_id, +struct cgroup_subsys memory_cgrp_subsys = { .css_alloc = mem_cgroup_css_alloc, .css_online = mem_cgroup_css_online, .css_offline = mem_cgroup_css_offline,@@ -7293,7 +7291,7 @@ __setup("swapaccount=", enable_swap_account);static void __init memsw_file_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, memsw_cgroup_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, memsw_cgroup_files)); }static void __init enable_swap_cgroup (void )net/core/netclassid_cgroup.c +2
-4@@ -23,7 +23,7 @@ static inline struct cgroup_cls_state *css_cls_state(struct cgroup_subsys_statestruct cgroup_cls_state *task_cls_state (struct task_struct *p) { -return css_cls_state (task_css (p, net_cls_subsys_id)); +return css_cls_state (task_css (p, net_cls_cgrp_id)); }EXPORT_SYMBOL_GPL (task_cls_state);@@ -102,12 +102,10 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_cls_subsys = { - .name ="net_cls" , +struct cgroup_subsys net_cls_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = cgrp_attach, - .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, };net/core/netprio_cgroup.c +1
-3@@ -244,13 +244,11 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_prio_subsys = { - .name ="net_prio" , +struct cgroup_subsys net_prio_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = net_prio_attach, - .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files, };net/ipv4/tcp_memcontrol.c +1
-1@@ -219,7 +219,7 @@ static struct cftype tcp_files[] = {static int __init tcp_memcontrol_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, tcp_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, tcp_files));return 0 ; }__initcall (tcp_memcontrol_init);security/device_cgroup.c +2
-6@@ -58,11 +58,9 @@ static inline struct dev_cgroup *css_to_devcgroup(struct cgroup_subsys_state *s)static inline struct dev_cgroup *task_devcgroup (struct task_struct *task) { -return css_to_devcgroup (task_css (task, devices_subsys_id)); +return css_to_devcgroup (task_css (task, devices_cgrp_id)); } -struct cgroup_subsys devices_subsys; -/* * called under devcgroup_mutex */ @@ -684,13 +682,11 @@ static struct cftype dev_cgroup_files[] = { { }/* terminate */ }; -struct cgroup_subsys devices_subsys = { - .name ="devices" , +struct cgroup_subsys devices_cgrp_subsys = { .css_alloc = devcgroup_css_alloc, .css_free = devcgroup_css_free, .css_online = devcgroup_online, .css_offline = devcgroup_offline, - .subsys_id = devices_subsys_id, .base_cftypes = dev_cgroup_files, };
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Michal Hocko
Acked-byRe: [PATCH 3/6] cgroup: clean up cgroup_subsys names and initialization
In reply to a message not in the archiveQuoted 46 lines · Tejun Heo
cgroup_subsysis a bit messier than it needs to be.* The name of a subsys can be different from its internal identifier defined in
cgroup_subsys.h. Most subsystems use the matching name but three - cpu, memory andperf_event- use different ones.*
cgroup_subsys_idenums are postfixed with_subsys_idand eachcgroup_subsysis postfixed with_subsys.cgroup.his widely included throughout various subsystems, it doesn't and shouldn't have claim on such generic names which don't have any qualifier indicating that they belong to cgroup.*
cgroup_subsys->subsys_idshould always equal the matchingcgroup_subsys_idenum; however, we require each controller to initialize it and then BUG if they don't match, which is a bit silly.This patch cleans up
cgroup_subsysnames and initialization by doing the followings.*
cgroup_subsys_idenums are now postfixed with_cgrp_id, and eachcgroup_subsyswith_cgrp_subsys.* With the above, renaming subsys identifiers to match the userland visible names doesn't cause any naming conflicts. All non-matching identifiers are renamed to match the official names.
cpu_cgroup-> cpu
mem_cgroup-> memory
perf ->perf_event* controllers no longer need to initialize ->subsys_id and ->name. They're generated in cgroup core and set automatically during boot.
* Redundant
cgroup_subsysdeclarations removed.* While updating BUG_ON()s in
cgroup_init_early(), convert them to WARN()s. BUGging that early during boot is stupid - the kernel can't print anything, even through serial console and the trap handler doesn't even link stack frame properly for back-tracing.This patch doesn't introduce any behavior changes.
v2: Rebased on top of
fe1217c4f3f7("net:net_cls: move cgroupfs
classid handling into core").
Quoted 15 lines
Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Li Zefan <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Balbir Singh <[email protected]>Cc KAMEZAWA Hiroyuki <[email protected]>Cc Aristeu Rozanski <[email protected]>Cc Serge E. Hallyn <serue-r/[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Vivek Goyal <[email protected]>Cc Thomas Graf <tgraf-G/[email protected]>
I thought I have already acked this one. Anyway
Quoted 672 lines
--- block/blk-cgroup.c | 8 +++----- block/blk-cgroup.h | 2 +- fs/bio.c | 2 +- include/linux/cgroup.h | 7 ++++--- include/linux/cgroup_subsys.h | 6 +++--- include/linux/hugetlb_cgroup.h | 2 +- include/linux/memcontrol.h | 2 +- include/net/cls_cgroup.h | 2 +- include/net/netprio_cgroup.h | 2 +- kernel/cgroup.c | 34 ++++++++++++++++++++-------------- kernel/cgroup_freezer.c | 8 ++------ kernel/cpuset.c | 10 ++++------ kernel/events/core.c | 8 +++----- kernel/sched/core.c | 6 ++---- kernel/sched/cpuacct.c | 6 ++---- mm/hugetlb_cgroup.c | 9 +++------ mm/memcontrol.c | 22 ++++++++++------------ net/core/netclassid_cgroup.c | 6 ++---- net/core/netprio_cgroup.c | 4 +--- net/ipv4/tcp_memcontrol.c | 2 +- security/device_cgroup.c | 8 ++------ 21 files changed, 68 insertions(+), 88 deletions(-)block/blk-cgroup.c +3
-5@@ -906,16 +906,14 @@ static int blkcg_can_attach(struct cgroup_subsys_state *css,return ret; } -struct cgroup_subsys blkio_subsys = { - .name ="blkio" , +struct cgroup_subsys blkio_cgrp_subsys = { .css_alloc = blkcg_css_alloc, .css_offline = blkcg_css_offline, .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, - .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, }; -EXPORT_SYMBOL_GPL (blkio_subsys); +EXPORT_SYMBOL_GPL (blkio_cgrp_subsys);/** * blkcg_activate_policy - activate a blkcg policy on a request_queue @@ -1105,7 +1103,7 @@ int blkcg_policy_register(struct blkcg_policy *pol)/* everything is in place, add intf files for the new policy */ if (pol->cftypes) -WARN_ON (cgroup_add_cftypes (&blkio_subsys, pol->cftypes)); +WARN_ON (cgroup_add_cftypes (&blkio_cgrp_subsys, pol->cftypes)); ret =0 ; out_unlock:mutex_unlock (&blkcg_pol_mutex);block/blk-cgroup.h +1
-1@@ -186,7 +186,7 @@ static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)static inline struct blkcg *task_blkcg (struct task_struct *tsk) { -return css_to_blkcg (task_css (tsk, blkio_subsys_id)); +return css_to_blkcg (task_css (tsk, blkio_cgrp_id)); }static inline struct blkcg *bio_blkcg (struct bio *bio)fs/bio.c +1
-1@@ -2002,7 +2002,7 @@ int bio_associate_current(struct bio *bio)/* associate blkcg if exists */ rcu_read_lock (); - css =task_css (current, blkio_subsys_id); + css =task_css (current, blkio_cgrp_id);if (css &&css_tryget (css)) bio->bi_css = css;rcu_read_unlock ();include/linux/cgroup.h +4
-3@@ -41,7 +41,7 @@ extern int cgroupstats_build(struct cgroupstats *stats,extern int proc_cgroup_show (struct seq_file *,void *);/* define the enumeration of all cgroup subsystems */ -#define SUBSYS (_x) _x ## _subsys_id, +#define SUBSYS (_x) _x ## _cgrp_id,enum cgroup_subsys_id {#include <linux/cgroup_subsys.h> CGROUP_SUBSYS_COUNT,@@ -573,7 +573,6 @@ struct cgroup_subsys { struct task_struct *task);void (*bind)(struct cgroup_subsys_state *root_css); -int subsys_id;int disabled;int early_init;@@ -592,6 +591,8 @@ struct cgroup_subsys {bool broken_hierarchy;bool warned_broken_hierarchy; +/* the following two fields are initialized automtically during boot */ +int subsys_id;#define MAX_CGROUP_TYPE_NAMELEN 32const char *name;@@ -606,7 +607,7 @@ struct cgroup_subsys {struct cftype_set base_cftset; }; -#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys; +#define SUBSYS (_x) extern struct cgroup_subsys _x ## _cgrp_subsys;#include <linux/cgroup_subsys.h> #undef SUBSYSinclude/linux/cgroup_subsys.h +3
-3@@ -12,7 +12,7 @@ SUBSYS(debug)#endif #if IS_ENABLED (CONFIG_CGROUP_SCHED ) -SUBSYS(cpu_cgroup) +SUBSYS(cpu)#endif #if IS_ENABLED (CONFIG_CGROUP_CPUACCT )@@ -20,7 +20,7 @@ SUBSYS(cpuacct)#endif #if IS_ENABLED (CONFIG_MEMCG ) -SUBSYS(mem_cgroup) +SUBSYS(memory)#endif #if IS_ENABLED (CONFIG_CGROUP_DEVICE )@@ -40,7 +40,7 @@ SUBSYS(blkio)#endif #if IS_ENABLED (CONFIG_CGROUP_PERF ) -SUBSYS(perf) +SUBSYS(perf_event)#endif #if IS_ENABLED (CONFIG_CGROUP_NET_PRIO )include/linux/hugetlb_cgroup.h +1
-1@@ -49,7 +49,7 @@ int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)static inline bool hugetlb_cgroup_disabled (void ) { -if (hugetlb_subsys.disabled) +if (hugetlb_cgrp_subsys.disabled)return true;return false; }include/linux/memcontrol.h +1
-1@@ -162,7 +162,7 @@ extern int do_swap_account;static inline bool mem_cgroup_disabled (void ) { -if (mem_cgroup_subsys.disabled) +if (memory_cgrp_subsys.disabled)return true;return false; }include/net/cls_cgroup.h +1
-1@@ -34,7 +34,7 @@ static inline u32 task_cls_classid(struct task_struct *p)return 0 ;rcu_read_lock (); - classid =container_of (task_css (p, net_cls_subsys_id), + classid =container_of (task_css (p, net_cls_cgrp_id), struct cgroup_cls_state, css)->classid;rcu_read_unlock ();include/net/netprio_cgroup.h +1
-1@@ -33,7 +33,7 @@ static inline u32 task_netprioidx(struct task_struct *p)u32 idx;rcu_read_lock (); - css =task_css (p, net_prio_subsys_id); + css =task_css (p, net_prio_cgrp_id); idx = css->cgroup->id;rcu_read_unlock ();return idx;kernel/cgroup.c +20
-14@@ -120,10 +120,18 @@ static struct workqueue_struct *cgroup_destroy_wq;static struct workqueue_struct *cgroup_pidlist_destroy_wq;/* generate an array of cgroup subsystem pointers */ -#define SUBSYS (_x) [_x ## _subsys_id] = &_x ## _subsys, +#define SUBSYS (_x) [_x ## _cgrp_id] = &_x ## _cgrp_subsys, static struct cgroup_subsys *cgroup_subsys[] = {#include <linux/cgroup_subsys.h> }; +#undef SUBSYS + +/* array of cgroup subsystem names */ +#define SUBSYS (_x) [_x ## _cgrp_id] = #_x, +static const char *cgroup_subsys_name[] = { +#include <linux/cgroup_subsys.h> +}; +#undef SUBSYS/* * The dummy hierarchy, reserved for the subsystems that are otherwise @@ -1076,7 +1084,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)BUG_ON (!mutex_is_locked (&cgroup_mutex));#ifdef CONFIG_CPUSETS - mask = ~(1UL << cpuset_subsys_id); + mask = ~(1UL << cpuset_cgrp_id);#endif memset (opts,0 ,sizeof (*opts));@@ -4518,15 +4526,15 @@ int __init cgroup_init_early(void)list_add (&init_cgrp_cset_link.cgrp_link, &init_css_set.cgrp_links);for_each_subsys (ss, i) { -BUG_ON (!ss->name); -BUG_ON (strlen (ss->name) >MAX_CGROUP_TYPE_NAMELEN ); -BUG_ON (!ss->css_alloc); -BUG_ON (!ss->css_free); -if (ss->subsys_id != i) { -printk (KERN_ERR "cgroup: Subsys %s id == %d\n" , - ss->name, ss->subsys_id); -BUG (); - } +WARN (!ss->css_alloc || !ss->css_free || ss->name || ss->subsys_id, +"invalid cgroup_subsys %d:%s css_alloc=%p css_free=%p name:id=%d:%s\n" , + i, cgroup_subsys_name[i], ss->css_alloc, ss->css_free, + ss->subsys_id, ss->name); +WARN (strlen (cgroup_subsys_name[i]) >MAX_CGROUP_TYPE_NAMELEN , +"cgroup_subsys_name %s too long\n" , cgroup_subsys_name[i]); + + ss->subsys_id = i; + ss->name = cgroup_subsys_name[i];if (ss->early_init)cgroup_init_subsys (ss);@@ -5156,11 +5164,9 @@ static struct cftype debug_files[] = { { } /* terminate */ }; -struct cgroup_subsys debug_subsys = { - .name ="debug" , +struct cgroup_subsys debug_cgrp_subsys = { .css_alloc = debug_css_alloc, .css_free = debug_css_free, - .subsys_id = debug_subsys_id, .base_cftypes = debug_files, };#endif /* CONFIG_CGROUP_DEBUG */ kernel/cgroup_freezer.c +2
-6@@ -52,7 +52,7 @@ static inline struct freezer *css_freezer(struct cgroup_subsys_state *css)static inline struct freezer *task_freezer (struct task_struct *task) { -return css_freezer (task_css (task, freezer_subsys_id)); +return css_freezer (task_css (task, freezer_cgrp_id)); }static struct freezer *parent_freezer (struct freezer *freezer)@@ -84,8 +84,6 @@ static const char *freezer_state_strs(unsigned int state)return "THAWED" ; }; -struct cgroup_subsys freezer_subsys; -static struct cgroup_subsys_state *freezer_css_alloc (struct cgroup_subsys_state *parent_css) {@@ -473,13 +471,11 @@ static struct cftype files[] = { { }/* terminate */ }; -struct cgroup_subsys freezer_subsys = { - .name ="freezer" , +struct cgroup_subsys freezer_cgrp_subsys = { .css_alloc = freezer_css_alloc, .css_online = freezer_css_online, .css_offline = freezer_css_offline, .css_free = freezer_css_free, - .subsys_id = freezer_subsys_id, .attach = freezer_attach, .fork = freezer_fork, .base_cftypes = files,kernel/cpuset.c +4
-6@@ -119,7 +119,7 @@ static inline struct cpuset *css_cs(struct cgroup_subsys_state *css)/* Retrieve the cpuset for a task */ static inline struct cpuset *task_cs (struct task_struct *task) { -return css_cs (task_css (task, cpuset_subsys_id)); +return css_cs (task_css (task, cpuset_cgrp_id)); }static inline struct cpuset *parent_cs (struct cpuset *cs)@@ -1521,7 +1521,7 @@ static void cpuset_attach(struct cgroup_subsys_state *css,struct task_struct *task;struct task_struct *leader =cgroup_taskset_first (tset);struct cgroup_subsys_state *oldcss =cgroup_taskset_cur_css (tset, - cpuset_subsys_id); + cpuset_cgrp_id);struct cpuset *cs =css_cs (css);struct cpuset *oldcs =css_cs (oldcss);struct cpuset *cpus_cs =effective_cpumask_cpuset (cs);@@ -2024,8 +2024,7 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)kfree (cs); } -struct cgroup_subsys cpuset_subsys = { - .name ="cpuset" , +struct cgroup_subsys cpuset_cgrp_subsys = { .css_alloc = cpuset_css_alloc, .css_online = cpuset_css_online, .css_offline = cpuset_css_offline,@@ -2033,7 +2032,6 @@ struct cgroup_subsys cpuset_subsys = { .can_attach = cpuset_can_attach, .cancel_attach = cpuset_cancel_attach, .attach = cpuset_attach, - .subsys_id = cpuset_subsys_id, .base_cftypes = files, .early_init = 1, };@@ -2699,7 +2697,7 @@ int proc_cpuset_show(struct seq_file *m, void *unused_v) goto out_free;rcu_read_lock (); - css =task_css (tsk, cpuset_subsys_id); + css =task_css (tsk, cpuset_cgrp_id); retval =cgroup_path (css->cgroup, buf,PAGE_SIZE );rcu_read_unlock ();if (retval <0 )kernel/events/core.c +3
-5@@ -342,7 +342,7 @@ struct perf_cgroup {static inline struct perf_cgroup *perf_cgroup_from_task (struct task_struct *task) { -return container_of (task_css (task, perf_subsys_id), +return container_of (task_css (task, perf_event_cgrp_id), struct perf_cgroup, css); }@@ -595,7 +595,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,rcu_read_lock (); - css =css_from_dir (f.file->f_dentry, &perf_subsys); + css =css_from_dir (f.file->f_dentry, &perf_event_cgrp_subsys);if (IS_ERR (css)) { ret =PTR_ERR (css); goto out;@@ -8055,9 +8055,7 @@ static void perf_cgroup_exit(struct cgroup_subsys_state *css,task_function_call (task, __perf_cgroup_move, task); } -struct cgroup_subsys perf_subsys = { - .name ="perf_event" , - .subsys_id = perf_subsys_id, +struct cgroup_subsys perf_event_cgrp_subsys = { .css_alloc = perf_cgroup_css_alloc, .css_free = perf_cgroup_css_free, .exit = perf_cgroup_exit,kernel/sched/core.c +2
-4@@ -7174,7 +7174,7 @@ void sched_move_task(struct task_struct *tsk)if (unlikely (running)) tsk->sched_class->put_prev_task (rq, tsk); - tg =container_of (task_css_check (tsk, cpu_cgroup_subsys_id, + tg =container_of (task_css_check (tsk, cpu_cgrp_id,lockdep_is_held (&tsk->sighand->siglock)), struct task_group, css); tg =autogroup_task_group (tsk, tg);@@ -7955,8 +7955,7 @@ static struct cftype cpu_files[] = { { }/* terminate */ }; -struct cgroup_subsys cpu_cgroup_subsys = { - .name ="cpu" , +struct cgroup_subsys cpu_cgrp_subsys = { .css_alloc = cpu_cgroup_css_alloc, .css_free = cpu_cgroup_css_free, .css_online = cpu_cgroup_css_online,@@ -7964,7 +7963,6 @@ struct cgroup_subsys cpu_cgroup_subsys = { .can_attach = cpu_cgroup_can_attach, .attach = cpu_cgroup_attach, .exit = cpu_cgroup_exit, - .subsys_id = cpu_cgroup_subsys_id, .base_cftypes = cpu_files, .early_init = 1, };kernel/sched/cpuacct.c +2
-4@@ -41,7 +41,7 @@ static inline struct cpuacct *css_ca(struct cgroup_subsys_state *css)/* return cpu accounting group to which this task belongs */ static inline struct cpuacct *task_ca (struct task_struct *tsk) { -return css_ca (task_css (tsk, cpuacct_subsys_id)); +return css_ca (task_css (tsk, cpuacct_cgrp_id)); }static inline struct cpuacct *parent_ca (struct cpuacct *ca)@@ -275,11 +275,9 @@ void cpuacct_account_field(struct task_struct *p, int index, u64 val)rcu_read_unlock (); } -struct cgroup_subsys cpuacct_subsys = { - .name ="cpuacct" , +struct cgroup_subsys cpuacct_cgrp_subsys = { .css_alloc = cpuacct_css_alloc, .css_free = cpuacct_css_free, - .subsys_id = cpuacct_subsys_id, .base_cftypes = files, .early_init =1 , };mm/hugetlb_cgroup.c +3
-6@@ -30,7 +30,6 @@ struct hugetlb_cgroup {#define MEMFILE_IDX (val) (((val) >> 16) & 0xffff)#define MEMFILE_ATTR (val) ((val) & 0xffff) -struct cgroup_subsys hugetlb_subsys__read_mostly ;static struct hugetlb_cgroup *root_h_cgroup__read_mostly ; static inline@@ -42,7 +41,7 @@ struct hugetlb_cgroup *hugetlb_cgroup_from_css(struct cgroup_subsys_state *s)static inline struct hugetlb_cgroup *hugetlb_cgroup_from_task (struct task_struct *task) { -return hugetlb_cgroup_from_css (task_css (task, hugetlb_subsys_id)); +return hugetlb_cgroup_from_css (task_css (task, hugetlb_cgrp_id)); }static inline bool hugetlb_cgroup_is_root (struct hugetlb_cgroup *h_cg)@@ -358,7 +357,7 @@ static void __init __hugetlb_cgroup_file_init(int idx) cft = &h->cgroup_files[4 ];memset (cft,0 ,sizeof (*cft)); -WARN_ON (cgroup_add_cftypes (&hugetlb_subsys, h->cgroup_files)); +WARN_ON (cgroup_add_cftypes (&hugetlb_cgrp_subsys, h->cgroup_files));return ; }@@ -402,10 +401,8 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)return ; } -struct cgroup_subsys hugetlb_subsys = { - .name ="hugetlb" , +struct cgroup_subsys hugetlb_cgrp_subsys = { .css_alloc = hugetlb_cgroup_css_alloc, .css_offline = hugetlb_cgroup_css_offline, .css_free = hugetlb_cgroup_css_free, - .subsys_id = hugetlb_subsys_id, };mm/memcontrol.c +10
-12@@ -66,8 +66,8 @@#include <trace/events/vmscan.h> -struct cgroup_subsys mem_cgroup_subsys__read_mostly ; -EXPORT_SYMBOL (mem_cgroup_subsys); +struct cgroup_subsys memory_cgrp_subsys__read_mostly ; +EXPORT_SYMBOL (memory_cgrp_subsys);#define MEM_CGROUP_RECLAIM_RETRIES 5static struct mem_cgroup *root_mem_cgroup__read_mostly ;@@ -538,7 +538,7 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) {struct cgroup_subsys_state *css; - css =css_from_id (id -1 , &mem_cgroup_subsys); + css =css_from_id (id -1 , &memory_cgrp_subsys);return mem_cgroup_from_css (css); }@@ -1072,7 +1072,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)if (unlikely (!p))return NULL ; -return mem_cgroup_from_css (task_css (p, mem_cgroup_subsys_id)); +return mem_cgroup_from_css (task_css (p, memory_cgrp_id)); }struct mem_cgroup *try_get_mem_cgroup_from_mm (struct mm_struct *mm)@@ -1702,7 +1702,7 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)rcu_read_lock (); mem_cgrp = memcg->css.cgroup; - task_cgrp =task_cgroup (p, mem_cgroup_subsys_id); + task_cgrp =task_cgroup (p, memory_cgrp_id); ret =cgroup_path (task_cgrp, memcg_name,PATH_MAX );if (ret <0 ) {@@ -6188,7 +6188,7 @@ static int memcg_write_event_control(struct cgroup_subsys_state *css, ret = -EINVAL ; cfile_css =css_from_dir (cfile.file->f_dentry->d_parent, - &mem_cgroup_subsys); + &memory_cgrp_subsys);if (cfile_css == css &&css_tryget (css)) ret =0 ;@@ -6567,11 +6567,11 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)* unfortunate state in our controller. */ if (parent != root_mem_cgroup) - mem_cgroup_subsys.broken_hierarchy = true; + memory_cgrp_subsys.broken_hierarchy = true; }mutex_unlock (&memcg_create_mutex); -return memcg_init_kmem (memcg, &mem_cgroup_subsys); +return memcg_init_kmem (memcg, &memory_cgrp_subsys); }/* @@ -7265,9 +7265,7 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css)mem_cgroup_from_css (root_css)->use_hierarchy = true; } -struct cgroup_subsys mem_cgroup_subsys = { - .name ="memory" , - .subsys_id = mem_cgroup_subsys_id, +struct cgroup_subsys memory_cgrp_subsys = { .css_alloc = mem_cgroup_css_alloc, .css_online = mem_cgroup_css_online, .css_offline = mem_cgroup_css_offline,@@ -7293,7 +7291,7 @@ __setup("swapaccount=", enable_swap_account);static void __init memsw_file_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, memsw_cgroup_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, memsw_cgroup_files)); }static void __init enable_swap_cgroup (void )net/core/netclassid_cgroup.c +2
-4@@ -23,7 +23,7 @@ static inline struct cgroup_cls_state *css_cls_state(struct cgroup_subsys_statestruct cgroup_cls_state *task_cls_state (struct task_struct *p) { -return css_cls_state (task_css (p, net_cls_subsys_id)); +return css_cls_state (task_css (p, net_cls_cgrp_id)); }EXPORT_SYMBOL_GPL (task_cls_state);@@ -102,12 +102,10 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_cls_subsys = { - .name ="net_cls" , +struct cgroup_subsys net_cls_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = cgrp_attach, - .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, };net/core/netprio_cgroup.c +1
-3@@ -244,13 +244,11 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_prio_subsys = { - .name ="net_prio" , +struct cgroup_subsys net_prio_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = net_prio_attach, - .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files, };net/ipv4/tcp_memcontrol.c +1
-1@@ -219,7 +219,7 @@ static struct cftype tcp_files[] = {static int __init tcp_memcontrol_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, tcp_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, tcp_files));return 0 ; }__initcall (tcp_memcontrol_init);security/device_cgroup.c +2
-6@@ -58,11 +58,9 @@ static inline struct dev_cgroup *css_to_devcgroup(struct cgroup_subsys_state *s)static inline struct dev_cgroup *task_devcgroup (struct task_struct *task) { -return css_to_devcgroup (task_css (task, devices_subsys_id)); +return css_to_devcgroup (task_css (task, devices_cgrp_id)); } -struct cgroup_subsys devices_subsys; -/* * called under devcgroup_mutex */ @@ -684,13 +682,11 @@ static struct cftype dev_cgroup_files[] = { { }/* terminate */ }; -struct cgroup_subsys devices_subsys = { - .name ="devices" , +struct cgroup_subsys devices_cgrp_subsys = { .css_alloc = devcgroup_css_alloc, .css_free = devcgroup_css_free, .css_online = devcgroup_online, .css_offline = devcgroup_offline, - .subsys_id = devices_subsys_id, .base_cftypes = dev_cgroup_files, };Signature · 1 line
1.8.5.3
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH 3/6] cgroup: clean up cgroup_subsys names and initialization
In reply to Tejun HeoQuoted 46 lines · Tejun Heo
cgroup_subsysis a bit messier than it needs to be.* The name of a subsys can be different from its internal identifier defined in
cgroup_subsys.h. Most subsystems use the matching name but three - cpu, memory andperf_event- use different ones.*
cgroup_subsys_idenums are postfixed with_subsys_idand eachcgroup_subsysis postfixed with_subsys.cgroup.his widely included throughout various subsystems, it doesn't and shouldn't have claim on such generic names which don't have any qualifier indicating that they belong to cgroup.*
cgroup_subsys->subsys_idshould always equal the matchingcgroup_subsys_idenum; however, we require each controller to initialize it and then BUG if they don't match, which is a bit silly.This patch cleans up
cgroup_subsysnames and initialization by doing the followings.*
cgroup_subsys_idenums are now postfixed with_cgrp_id, and eachcgroup_subsyswith_cgrp_subsys.* With the above, renaming subsys identifiers to match the userland visible names doesn't cause any naming conflicts. All non-matching identifiers are renamed to match the official names.
cpu_cgroup-> cpu
mem_cgroup-> memory
perf ->perf_event* controllers no longer need to initialize ->subsys_id and ->name. They're generated in cgroup core and set automatically during boot.
* Redundant
cgroup_subsysdeclarations removed.* While updating BUG_ON()s in
cgroup_init_early(), convert them to WARN()s. BUGging that early during boot is stupid - the kernel can't print anything, even through serial console and the trap handler doesn't even link stack frame properly for back-tracing.This patch doesn't introduce any behavior changes.
v2: Rebased on top of
fe1217c4f3f7("net:net_cls: move cgroupfs
classid handling into core").
Quoted 15 lines
Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Li Zefan <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Balbir Singh <[email protected]>Cc KAMEZAWA Hiroyuki <[email protected]>Cc Aristeu Rozanski <[email protected]>Cc Serge E. Hallyn <serue-r/[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Vivek Goyal <[email protected]>Cc Thomas Graf <tgraf-G/[email protected]>
I thought I have already acked this one. Anyway
Quoted 672 lines
--- block/blk-cgroup.c | 8 +++----- block/blk-cgroup.h | 2 +- fs/bio.c | 2 +- include/linux/cgroup.h | 7 ++++--- include/linux/cgroup_subsys.h | 6 +++--- include/linux/hugetlb_cgroup.h | 2 +- include/linux/memcontrol.h | 2 +- include/net/cls_cgroup.h | 2 +- include/net/netprio_cgroup.h | 2 +- kernel/cgroup.c | 34 ++++++++++++++++++++-------------- kernel/cgroup_freezer.c | 8 ++------ kernel/cpuset.c | 10 ++++------ kernel/events/core.c | 8 +++----- kernel/sched/core.c | 6 ++---- kernel/sched/cpuacct.c | 6 ++---- mm/hugetlb_cgroup.c | 9 +++------ mm/memcontrol.c | 22 ++++++++++------------ net/core/netclassid_cgroup.c | 6 ++---- net/core/netprio_cgroup.c | 4 +--- net/ipv4/tcp_memcontrol.c | 2 +- security/device_cgroup.c | 8 ++------ 21 files changed, 68 insertions(+), 88 deletions(-)block/blk-cgroup.c +3
-5@@ -906,16 +906,14 @@ static int blkcg_can_attach(struct cgroup_subsys_state *css,return ret; } -struct cgroup_subsys blkio_subsys = { - .name ="blkio" , +struct cgroup_subsys blkio_cgrp_subsys = { .css_alloc = blkcg_css_alloc, .css_offline = blkcg_css_offline, .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, - .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, }; -EXPORT_SYMBOL_GPL (blkio_subsys); +EXPORT_SYMBOL_GPL (blkio_cgrp_subsys);/** * blkcg_activate_policy - activate a blkcg policy on a request_queue @@ -1105,7 +1103,7 @@ int blkcg_policy_register(struct blkcg_policy *pol)/* everything is in place, add intf files for the new policy */ if (pol->cftypes) -WARN_ON (cgroup_add_cftypes (&blkio_subsys, pol->cftypes)); +WARN_ON (cgroup_add_cftypes (&blkio_cgrp_subsys, pol->cftypes)); ret =0 ; out_unlock:mutex_unlock (&blkcg_pol_mutex);block/blk-cgroup.h +1
-1@@ -186,7 +186,7 @@ static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)static inline struct blkcg *task_blkcg (struct task_struct *tsk) { -return css_to_blkcg (task_css (tsk, blkio_subsys_id)); +return css_to_blkcg (task_css (tsk, blkio_cgrp_id)); }static inline struct blkcg *bio_blkcg (struct bio *bio)fs/bio.c +1
-1@@ -2002,7 +2002,7 @@ int bio_associate_current(struct bio *bio)/* associate blkcg if exists */ rcu_read_lock (); - css =task_css (current, blkio_subsys_id); + css =task_css (current, blkio_cgrp_id);if (css &&css_tryget (css)) bio->bi_css = css;rcu_read_unlock ();include/linux/cgroup.h +4
-3@@ -41,7 +41,7 @@ extern int cgroupstats_build(struct cgroupstats *stats,extern int proc_cgroup_show (struct seq_file *,void *);/* define the enumeration of all cgroup subsystems */ -#define SUBSYS (_x) _x ## _subsys_id, +#define SUBSYS (_x) _x ## _cgrp_id,enum cgroup_subsys_id {#include <linux/cgroup_subsys.h> CGROUP_SUBSYS_COUNT,@@ -573,7 +573,6 @@ struct cgroup_subsys { struct task_struct *task);void (*bind)(struct cgroup_subsys_state *root_css); -int subsys_id;int disabled;int early_init;@@ -592,6 +591,8 @@ struct cgroup_subsys {bool broken_hierarchy;bool warned_broken_hierarchy; +/* the following two fields are initialized automtically during boot */ +int subsys_id;#define MAX_CGROUP_TYPE_NAMELEN 32const char *name;@@ -606,7 +607,7 @@ struct cgroup_subsys {struct cftype_set base_cftset; }; -#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys; +#define SUBSYS (_x) extern struct cgroup_subsys _x ## _cgrp_subsys;#include <linux/cgroup_subsys.h> #undef SUBSYSinclude/linux/cgroup_subsys.h +3
-3@@ -12,7 +12,7 @@ SUBSYS(debug)#endif #if IS_ENABLED (CONFIG_CGROUP_SCHED ) -SUBSYS(cpu_cgroup) +SUBSYS(cpu)#endif #if IS_ENABLED (CONFIG_CGROUP_CPUACCT )@@ -20,7 +20,7 @@ SUBSYS(cpuacct)#endif #if IS_ENABLED (CONFIG_MEMCG ) -SUBSYS(mem_cgroup) +SUBSYS(memory)#endif #if IS_ENABLED (CONFIG_CGROUP_DEVICE )@@ -40,7 +40,7 @@ SUBSYS(blkio)#endif #if IS_ENABLED (CONFIG_CGROUP_PERF ) -SUBSYS(perf) +SUBSYS(perf_event)#endif #if IS_ENABLED (CONFIG_CGROUP_NET_PRIO )include/linux/hugetlb_cgroup.h +1
-1@@ -49,7 +49,7 @@ int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)static inline bool hugetlb_cgroup_disabled (void ) { -if (hugetlb_subsys.disabled) +if (hugetlb_cgrp_subsys.disabled)return true;return false; }include/linux/memcontrol.h +1
-1@@ -162,7 +162,7 @@ extern int do_swap_account;static inline bool mem_cgroup_disabled (void ) { -if (mem_cgroup_subsys.disabled) +if (memory_cgrp_subsys.disabled)return true;return false; }include/net/cls_cgroup.h +1
-1@@ -34,7 +34,7 @@ static inline u32 task_cls_classid(struct task_struct *p)return 0 ;rcu_read_lock (); - classid =container_of (task_css (p, net_cls_subsys_id), + classid =container_of (task_css (p, net_cls_cgrp_id), struct cgroup_cls_state, css)->classid;rcu_read_unlock ();include/net/netprio_cgroup.h +1
-1@@ -33,7 +33,7 @@ static inline u32 task_netprioidx(struct task_struct *p)u32 idx;rcu_read_lock (); - css =task_css (p, net_prio_subsys_id); + css =task_css (p, net_prio_cgrp_id); idx = css->cgroup->id;rcu_read_unlock ();return idx;kernel/cgroup.c +20
-14@@ -120,10 +120,18 @@ static struct workqueue_struct *cgroup_destroy_wq;static struct workqueue_struct *cgroup_pidlist_destroy_wq;/* generate an array of cgroup subsystem pointers */ -#define SUBSYS (_x) [_x ## _subsys_id] = &_x ## _subsys, +#define SUBSYS (_x) [_x ## _cgrp_id] = &_x ## _cgrp_subsys, static struct cgroup_subsys *cgroup_subsys[] = {#include <linux/cgroup_subsys.h> }; +#undef SUBSYS + +/* array of cgroup subsystem names */ +#define SUBSYS (_x) [_x ## _cgrp_id] = #_x, +static const char *cgroup_subsys_name[] = { +#include <linux/cgroup_subsys.h> +}; +#undef SUBSYS/* * The dummy hierarchy, reserved for the subsystems that are otherwise @@ -1076,7 +1084,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)BUG_ON (!mutex_is_locked (&cgroup_mutex));#ifdef CONFIG_CPUSETS - mask = ~(1UL << cpuset_subsys_id); + mask = ~(1UL << cpuset_cgrp_id);#endif memset (opts,0 ,sizeof (*opts));@@ -4518,15 +4526,15 @@ int __init cgroup_init_early(void)list_add (&init_cgrp_cset_link.cgrp_link, &init_css_set.cgrp_links);for_each_subsys (ss, i) { -BUG_ON (!ss->name); -BUG_ON (strlen (ss->name) >MAX_CGROUP_TYPE_NAMELEN ); -BUG_ON (!ss->css_alloc); -BUG_ON (!ss->css_free); -if (ss->subsys_id != i) { -printk (KERN_ERR "cgroup: Subsys %s id == %d\n" , - ss->name, ss->subsys_id); -BUG (); - } +WARN (!ss->css_alloc || !ss->css_free || ss->name || ss->subsys_id, +"invalid cgroup_subsys %d:%s css_alloc=%p css_free=%p name:id=%d:%s\n" , + i, cgroup_subsys_name[i], ss->css_alloc, ss->css_free, + ss->subsys_id, ss->name); +WARN (strlen (cgroup_subsys_name[i]) >MAX_CGROUP_TYPE_NAMELEN , +"cgroup_subsys_name %s too long\n" , cgroup_subsys_name[i]); + + ss->subsys_id = i; + ss->name = cgroup_subsys_name[i];if (ss->early_init)cgroup_init_subsys (ss);@@ -5156,11 +5164,9 @@ static struct cftype debug_files[] = { { } /* terminate */ }; -struct cgroup_subsys debug_subsys = { - .name ="debug" , +struct cgroup_subsys debug_cgrp_subsys = { .css_alloc = debug_css_alloc, .css_free = debug_css_free, - .subsys_id = debug_subsys_id, .base_cftypes = debug_files, };#endif /* CONFIG_CGROUP_DEBUG */ kernel/cgroup_freezer.c +2
-6@@ -52,7 +52,7 @@ static inline struct freezer *css_freezer(struct cgroup_subsys_state *css)static inline struct freezer *task_freezer (struct task_struct *task) { -return css_freezer (task_css (task, freezer_subsys_id)); +return css_freezer (task_css (task, freezer_cgrp_id)); }static struct freezer *parent_freezer (struct freezer *freezer)@@ -84,8 +84,6 @@ static const char *freezer_state_strs(unsigned int state)return "THAWED" ; }; -struct cgroup_subsys freezer_subsys; -static struct cgroup_subsys_state *freezer_css_alloc (struct cgroup_subsys_state *parent_css) {@@ -473,13 +471,11 @@ static struct cftype files[] = { { }/* terminate */ }; -struct cgroup_subsys freezer_subsys = { - .name ="freezer" , +struct cgroup_subsys freezer_cgrp_subsys = { .css_alloc = freezer_css_alloc, .css_online = freezer_css_online, .css_offline = freezer_css_offline, .css_free = freezer_css_free, - .subsys_id = freezer_subsys_id, .attach = freezer_attach, .fork = freezer_fork, .base_cftypes = files,kernel/cpuset.c +4
-6@@ -119,7 +119,7 @@ static inline struct cpuset *css_cs(struct cgroup_subsys_state *css)/* Retrieve the cpuset for a task */ static inline struct cpuset *task_cs (struct task_struct *task) { -return css_cs (task_css (task, cpuset_subsys_id)); +return css_cs (task_css (task, cpuset_cgrp_id)); }static inline struct cpuset *parent_cs (struct cpuset *cs)@@ -1521,7 +1521,7 @@ static void cpuset_attach(struct cgroup_subsys_state *css,struct task_struct *task;struct task_struct *leader =cgroup_taskset_first (tset);struct cgroup_subsys_state *oldcss =cgroup_taskset_cur_css (tset, - cpuset_subsys_id); + cpuset_cgrp_id);struct cpuset *cs =css_cs (css);struct cpuset *oldcs =css_cs (oldcss);struct cpuset *cpus_cs =effective_cpumask_cpuset (cs);@@ -2024,8 +2024,7 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)kfree (cs); } -struct cgroup_subsys cpuset_subsys = { - .name ="cpuset" , +struct cgroup_subsys cpuset_cgrp_subsys = { .css_alloc = cpuset_css_alloc, .css_online = cpuset_css_online, .css_offline = cpuset_css_offline,@@ -2033,7 +2032,6 @@ struct cgroup_subsys cpuset_subsys = { .can_attach = cpuset_can_attach, .cancel_attach = cpuset_cancel_attach, .attach = cpuset_attach, - .subsys_id = cpuset_subsys_id, .base_cftypes = files, .early_init = 1, };@@ -2699,7 +2697,7 @@ int proc_cpuset_show(struct seq_file *m, void *unused_v) goto out_free;rcu_read_lock (); - css =task_css (tsk, cpuset_subsys_id); + css =task_css (tsk, cpuset_cgrp_id); retval =cgroup_path (css->cgroup, buf,PAGE_SIZE );rcu_read_unlock ();if (retval <0 )kernel/events/core.c +3
-5@@ -342,7 +342,7 @@ struct perf_cgroup {static inline struct perf_cgroup *perf_cgroup_from_task (struct task_struct *task) { -return container_of (task_css (task, perf_subsys_id), +return container_of (task_css (task, perf_event_cgrp_id), struct perf_cgroup, css); }@@ -595,7 +595,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,rcu_read_lock (); - css =css_from_dir (f.file->f_dentry, &perf_subsys); + css =css_from_dir (f.file->f_dentry, &perf_event_cgrp_subsys);if (IS_ERR (css)) { ret =PTR_ERR (css); goto out;@@ -8055,9 +8055,7 @@ static void perf_cgroup_exit(struct cgroup_subsys_state *css,task_function_call (task, __perf_cgroup_move, task); } -struct cgroup_subsys perf_subsys = { - .name ="perf_event" , - .subsys_id = perf_subsys_id, +struct cgroup_subsys perf_event_cgrp_subsys = { .css_alloc = perf_cgroup_css_alloc, .css_free = perf_cgroup_css_free, .exit = perf_cgroup_exit,kernel/sched/core.c +2
-4@@ -7174,7 +7174,7 @@ void sched_move_task(struct task_struct *tsk)if (unlikely (running)) tsk->sched_class->put_prev_task (rq, tsk); - tg =container_of (task_css_check (tsk, cpu_cgroup_subsys_id, + tg =container_of (task_css_check (tsk, cpu_cgrp_id,lockdep_is_held (&tsk->sighand->siglock)), struct task_group, css); tg =autogroup_task_group (tsk, tg);@@ -7955,8 +7955,7 @@ static struct cftype cpu_files[] = { { }/* terminate */ }; -struct cgroup_subsys cpu_cgroup_subsys = { - .name ="cpu" , +struct cgroup_subsys cpu_cgrp_subsys = { .css_alloc = cpu_cgroup_css_alloc, .css_free = cpu_cgroup_css_free, .css_online = cpu_cgroup_css_online,@@ -7964,7 +7963,6 @@ struct cgroup_subsys cpu_cgroup_subsys = { .can_attach = cpu_cgroup_can_attach, .attach = cpu_cgroup_attach, .exit = cpu_cgroup_exit, - .subsys_id = cpu_cgroup_subsys_id, .base_cftypes = cpu_files, .early_init = 1, };kernel/sched/cpuacct.c +2
-4@@ -41,7 +41,7 @@ static inline struct cpuacct *css_ca(struct cgroup_subsys_state *css)/* return cpu accounting group to which this task belongs */ static inline struct cpuacct *task_ca (struct task_struct *tsk) { -return css_ca (task_css (tsk, cpuacct_subsys_id)); +return css_ca (task_css (tsk, cpuacct_cgrp_id)); }static inline struct cpuacct *parent_ca (struct cpuacct *ca)@@ -275,11 +275,9 @@ void cpuacct_account_field(struct task_struct *p, int index, u64 val)rcu_read_unlock (); } -struct cgroup_subsys cpuacct_subsys = { - .name ="cpuacct" , +struct cgroup_subsys cpuacct_cgrp_subsys = { .css_alloc = cpuacct_css_alloc, .css_free = cpuacct_css_free, - .subsys_id = cpuacct_subsys_id, .base_cftypes = files, .early_init =1 , };mm/hugetlb_cgroup.c +3
-6@@ -30,7 +30,6 @@ struct hugetlb_cgroup {#define MEMFILE_IDX (val) (((val) >> 16) & 0xffff)#define MEMFILE_ATTR (val) ((val) & 0xffff) -struct cgroup_subsys hugetlb_subsys__read_mostly ;static struct hugetlb_cgroup *root_h_cgroup__read_mostly ; static inline@@ -42,7 +41,7 @@ struct hugetlb_cgroup *hugetlb_cgroup_from_css(struct cgroup_subsys_state *s)static inline struct hugetlb_cgroup *hugetlb_cgroup_from_task (struct task_struct *task) { -return hugetlb_cgroup_from_css (task_css (task, hugetlb_subsys_id)); +return hugetlb_cgroup_from_css (task_css (task, hugetlb_cgrp_id)); }static inline bool hugetlb_cgroup_is_root (struct hugetlb_cgroup *h_cg)@@ -358,7 +357,7 @@ static void __init __hugetlb_cgroup_file_init(int idx) cft = &h->cgroup_files[4 ];memset (cft,0 ,sizeof (*cft)); -WARN_ON (cgroup_add_cftypes (&hugetlb_subsys, h->cgroup_files)); +WARN_ON (cgroup_add_cftypes (&hugetlb_cgrp_subsys, h->cgroup_files));return ; }@@ -402,10 +401,8 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)return ; } -struct cgroup_subsys hugetlb_subsys = { - .name ="hugetlb" , +struct cgroup_subsys hugetlb_cgrp_subsys = { .css_alloc = hugetlb_cgroup_css_alloc, .css_offline = hugetlb_cgroup_css_offline, .css_free = hugetlb_cgroup_css_free, - .subsys_id = hugetlb_subsys_id, };mm/memcontrol.c +10
-12@@ -66,8 +66,8 @@#include <trace/events/vmscan.h> -struct cgroup_subsys mem_cgroup_subsys__read_mostly ; -EXPORT_SYMBOL (mem_cgroup_subsys); +struct cgroup_subsys memory_cgrp_subsys__read_mostly ; +EXPORT_SYMBOL (memory_cgrp_subsys);#define MEM_CGROUP_RECLAIM_RETRIES 5static struct mem_cgroup *root_mem_cgroup__read_mostly ;@@ -538,7 +538,7 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) {struct cgroup_subsys_state *css; - css =css_from_id (id -1 , &mem_cgroup_subsys); + css =css_from_id (id -1 , &memory_cgrp_subsys);return mem_cgroup_from_css (css); }@@ -1072,7 +1072,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)if (unlikely (!p))return NULL ; -return mem_cgroup_from_css (task_css (p, mem_cgroup_subsys_id)); +return mem_cgroup_from_css (task_css (p, memory_cgrp_id)); }struct mem_cgroup *try_get_mem_cgroup_from_mm (struct mm_struct *mm)@@ -1702,7 +1702,7 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)rcu_read_lock (); mem_cgrp = memcg->css.cgroup; - task_cgrp =task_cgroup (p, mem_cgroup_subsys_id); + task_cgrp =task_cgroup (p, memory_cgrp_id); ret =cgroup_path (task_cgrp, memcg_name,PATH_MAX );if (ret <0 ) {@@ -6188,7 +6188,7 @@ static int memcg_write_event_control(struct cgroup_subsys_state *css, ret = -EINVAL ; cfile_css =css_from_dir (cfile.file->f_dentry->d_parent, - &mem_cgroup_subsys); + &memory_cgrp_subsys);if (cfile_css == css &&css_tryget (css)) ret =0 ;@@ -6567,11 +6567,11 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)* unfortunate state in our controller. */ if (parent != root_mem_cgroup) - mem_cgroup_subsys.broken_hierarchy = true; + memory_cgrp_subsys.broken_hierarchy = true; }mutex_unlock (&memcg_create_mutex); -return memcg_init_kmem (memcg, &mem_cgroup_subsys); +return memcg_init_kmem (memcg, &memory_cgrp_subsys); }/* @@ -7265,9 +7265,7 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css)mem_cgroup_from_css (root_css)->use_hierarchy = true; } -struct cgroup_subsys mem_cgroup_subsys = { - .name ="memory" , - .subsys_id = mem_cgroup_subsys_id, +struct cgroup_subsys memory_cgrp_subsys = { .css_alloc = mem_cgroup_css_alloc, .css_online = mem_cgroup_css_online, .css_offline = mem_cgroup_css_offline,@@ -7293,7 +7291,7 @@ __setup("swapaccount=", enable_swap_account);static void __init memsw_file_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, memsw_cgroup_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, memsw_cgroup_files)); }static void __init enable_swap_cgroup (void )net/core/netclassid_cgroup.c +2
-4@@ -23,7 +23,7 @@ static inline struct cgroup_cls_state *css_cls_state(struct cgroup_subsys_statestruct cgroup_cls_state *task_cls_state (struct task_struct *p) { -return css_cls_state (task_css (p, net_cls_subsys_id)); +return css_cls_state (task_css (p, net_cls_cgrp_id)); }EXPORT_SYMBOL_GPL (task_cls_state);@@ -102,12 +102,10 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_cls_subsys = { - .name ="net_cls" , +struct cgroup_subsys net_cls_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = cgrp_attach, - .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, };net/core/netprio_cgroup.c +1
-3@@ -244,13 +244,11 @@ static struct cftype ss_files[] = { { }/* terminate */ }; -struct cgroup_subsys net_prio_subsys = { - .name ="net_prio" , +struct cgroup_subsys net_prio_cgrp_subsys = { .css_alloc = cgrp_css_alloc, .css_online = cgrp_css_online, .css_free = cgrp_css_free, .attach = net_prio_attach, - .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files, };net/ipv4/tcp_memcontrol.c +1
-1@@ -219,7 +219,7 @@ static struct cftype tcp_files[] = {static int __init tcp_memcontrol_init (void ) { -WARN_ON (cgroup_add_cftypes (&mem_cgroup_subsys, tcp_files)); +WARN_ON (cgroup_add_cftypes (&memory_cgrp_subsys, tcp_files));return 0 ; }__initcall (tcp_memcontrol_init);security/device_cgroup.c +2
-6@@ -58,11 +58,9 @@ static inline struct dev_cgroup *css_to_devcgroup(struct cgroup_subsys_state *s)static inline struct dev_cgroup *task_devcgroup (struct task_struct *task) { -return css_to_devcgroup (task_css (task, devices_subsys_id)); +return css_to_devcgroup (task_css (task, devices_cgrp_id)); } -struct cgroup_subsys devices_subsys; -/* * called under devcgroup_mutex */ @@ -684,13 +682,11 @@ static struct cftype dev_cgroup_files[] = { { }/* terminate */ }; -struct cgroup_subsys devices_subsys = { - .name ="devices" , +struct cgroup_subsys devices_cgrp_subsys = { .css_alloc = devcgroup_css_alloc, .css_free = devcgroup_css_free, .css_online = devcgroup_online, .css_offline = devcgroup_offline, - .subsys_id = devices_subsys_id, .base_cftypes = dev_cgroup_files, };Signature · 1 line
1.8.5.3
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH 3/6] cgroup: clean up cgroup_subsys names and initialization
In reply to Tejun HeoQuoted 8 lines · Tejun Heo
* With the above, renaming subsys identifiers to match the userland visible names doesn't cause any naming conflicts. All non-matching identifiers are renamed to match the official names.
cpu_cgroup-> cpu
perf ->perf_eventCc Ingo Molnar <[email protected]>
Ingo Molnar
Acked-byRe: [PATCH 3/6] cgroup: clean up cgroup_subsys names and initialization
Quoted 10 lines · Peter Zijlstra
Quoted 8 lines · Tejun Heo
* With the above, renaming subsys identifiers to match the userland visible names doesn't cause any naming conflicts. All non-matching identifiers are renamed to match the official names.
cpu_cgroup-> cpu
perf ->perf_eventCc Ingo Molnar <[email protected]>Acked-by Peter Zijlstra <[email protected]>
Thanks,
Ingo
A message that is not in the archive (sent off-list or not yet received): 20140129104648.GC9636-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org
Ingo Molnar
Acked-byRe: [PATCH 3/6] cgroup: clean up cgroup_subsys names and initialization
Quoted 10 lines · Peter Zijlstra
Quoted 8 lines · Tejun Heo
* With the above, renaming subsys identifiers to match the userland visible names doesn't cause any naming conflicts. All non-matching identifiers are renamed to match the official names.
cpu_cgroup-> cpu
perf ->perf_eventCc Ingo Molnar <[email protected]>Acked-by Peter Zijlstra <[email protected]>
Thanks,
Ingo
Re: [PATCH 3/6] cgroup: clean up cgroup_subsys names and initialization
In reply to Tejun HeoQuoted 19 lines
security/device_cgroup.c +1
-3@@ -58,11 +58,9 @@ static inline struct dev_cgroup *css_to_devcgroup(struct cgroup_subsys_state *s)static inline struct dev_cgroup *task_devcgroup (struct task_struct *task) { -return css_to_devcgroup (task_css (task, devices_subsys_id)); +return css_to_devcgroup (task_css (task, devices_cgrp_id)); } -struct cgroup_subsys devices_subsys; -/* * called under devcgroup_mutex */ @@ -684,13 +682,11 @@ static struct cftype dev_cgroup_files[] = { { }/* terminate */ };
security/device_cgroup.c static struct cftype dev_cgroup_files[] = { · line 691
Quoted 10 lines
security/device_cgroup.c +1
-3-struct cgroup_subsys devices_subsys = { - .name ="devices" , +struct cgroup_subsys devices_cgrp_subsys = { .css_alloc = devcgroup_css_alloc, .css_free = devcgroup_css_free, .css_online = devcgroup_online, .css_offline = devcgroup_offline, - .subsys_id = devices_subsys_id, .base_cftypes = dev_cgroup_files, };
ACK
Signature · 1 line
Aristeu
Tejun Heo
maintainerPATCH 4/6 cgroup: rename cgroup_subsys->subsys_id to ->id
In reply to Tejun HeoIt's no longer referenced outside cgroup core, so renaming is easy. Let's rename it for consistency & brevity.
This patch is pure rename.
--- include/linux/cgroup.h | 4 ++-- kernel/cgroup.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-)
include/linux/cgroup.h +2 -2
@@ -548,7 +548,7 @@ int cgroup_taskset_size(struct cgroup_taskset *tset); (task) = cgroup_taskset_next((tset))) \if (!(skip_css) || \cgroup_taskset_cur_css ((tset), \ - (skip_css)->ss->subsys_id) != (skip_css)) + (skip_css)->ss->id) != (skip_css))/* * Control Group subsystem type.
@@ -592,7 +592,7 @@ struct cgroup_subsys {bool warned_broken_hierarchy;/* the following two fields are initialized automtically during boot */ -int subsys_id; +int id;#define MAX_CGROUP_TYPE_NAMELEN 32const char *name;
kernel/cgroup.c +10 -10
@@ -198,7 +198,7 @@ static struct cgroup_subsys_state *cgroup_css(struct cgroup *cgrp, struct cgroup_subsys *ss) {if (ss) -return rcu_dereference_check (cgrp->subsys[ss->subsys_id], +return rcu_dereference_check (cgrp->subsys[ss->id],lockdep_is_held (&cgroup_mutex));else return &cgrp->dummy_css;
@@ -3968,7 +3968,7 @@ static void css_release(struct percpu_ref *ref)struct cgroup_subsys_state *css = container_of(ref, struct cgroup_subsys_state, refcnt); -rcu_assign_pointer (css->cgroup->subsys[css->ss->subsys_id],NULL ); +rcu_assign_pointer (css->cgroup->subsys[css->ss->id],NULL );call_rcu (&css->rcu_head, css_free_rcu_fn); }
@@ -4000,7 +4000,7 @@ static int online_css(struct cgroup_subsys_state *css)if (!ret) { css->flags |=CSS_ONLINE ; css->cgroup->nr_css++; -rcu_assign_pointer (css->cgroup->subsys[ss->subsys_id], css); +rcu_assign_pointer (css->cgroup->subsys[ss->id], css); }return ret; }
@@ -4020,7 +4020,7 @@ static void offline_css(struct cgroup_subsys_state *css) css->flags &= ~CSS_ONLINE ; css->cgroup->nr_css--; -RCU_INIT_POINTER (css->cgroup->subsys[ss->subsys_id], css); +RCU_INIT_POINTER (css->cgroup->subsys[ss->id], css); }/**
@@ -4051,7 +4051,7 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)init_css (css, ss, cgrp); - err =cgroup_populate_dir (cgrp,1 << ss->subsys_id); + err =cgroup_populate_dir (cgrp,1 << ss->id);if (err) goto err_free;
@@ -4282,7 +4282,7 @@ static void css_killed_ref_fn(struct percpu_ref *ref)*/ static void kill_css (struct cgroup_subsys_state *css) { -cgroup_clear_dir (css->cgroup,1 << css->ss->subsys_id); +cgroup_clear_dir (css->cgroup,1 << css->ss->id);/* * Killing would put the base ref, but we need to keep it alive
@@ -4486,7 +4486,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)* pointer to this state - since the subsystem is * newly registered, all tasks and hence the * init_css_set is in the subsystem's top cgroup. */ - init_css_set.subsys[ss->subsys_id] = css; + init_css_set.subsys[ss->id] = css; need_forkexit_callback |= ss->fork || ss->exit;
@@ -4526,14 +4526,14 @@ int __init cgroup_init_early(void)list_add (&init_cgrp_cset_link.cgrp_link, &init_css_set.cgrp_links);for_each_subsys (ss, i) { -WARN (!ss->css_alloc || !ss->css_free || ss->name || ss->subsys_id, +WARN (!ss->css_alloc || !ss->css_free || ss->name || ss->id,"invalid cgroup_subsys %d:%s css_alloc=%p css_free=%p name:id=%d:%s\n" , i, cgroup_subsys_name[i], ss->css_alloc, ss->css_free, - ss->subsys_id, ss->name); + ss->id, ss->name);WARN (strlen (cgroup_subsys_name[i]) >MAX_CGROUP_TYPE_NAMELEN ,"cgroup_subsys_name %s too long\n" , cgroup_subsys_name[i]); - ss->subsys_id = i; + ss->id = i; ss->name = cgroup_subsys_name[i];if (ss->early_init)
Signature · 1 line
1.8.5.3
Tejun Heo
maintainerPATCH 5/6 cgroup: update locking in cgroup_show_options()
In reply to Tejun Heocgroup_show_options() grabs cgroup_root_mutex to protect the options changing while printing; however, holding root_mutex or not doesn't really make much difference for the function. subsys_mask can be atomically tested and most of the options aren't allowed to change anyway once mounted.
The only field which needs synchronization is ->release_agent_path. This patch introduces a dedicated spinlock to synchronize accesses to the field and drops cgroup_root_mutex locking from cgroup_show_options(). The next patch will remove cgroup_root_mutex.
--- kernel/cgroup.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
kernel/cgroup.c +16 -3
@@ -92,6 +92,12 @@ static DEFINE_MUTEX(cgroup_mutex);static DEFINE_MUTEX (cgroup_root_mutex); +/* +* Protects cgroup_subsys->release_agent_path. Modifying it also requires +* cgroup_mutex. Reading requires either cgroup_mutex or this spinlock. +*/ +static DEFINE_SPINLOCK (release_agent_path_lock); +#define cgroup_assert_mutex_or_rcu_locked () \ rcu_lockdep_assert(rcu_read_lock_held() || \ lockdep_is_held(&cgroup_mutex), \
@@ -1034,7 +1040,6 @@ static int cgroup_show_options(struct seq_file *seq, struct dentry *dentry)struct cgroup_subsys *ss;int ssid; -mutex_lock (&cgroup_root_mutex);for_each_subsys (ss, ssid)if (root->subsys_mask & (1 << ssid))seq_printf (seq,",%s" , ss->name);
@@ -1044,13 +1049,16 @@ static int cgroup_show_options(struct seq_file *seq, struct dentry *dentry)seq_puts (seq,",noprefix" );if (root->flags &CGRP_ROOT_XATTR )seq_puts (seq,",xattr" ); + +spin_lock (&release_agent_path_lock);if (strlen (root->release_agent_path))seq_printf (seq,",release_agent=%s" , root->release_agent_path); +spin_unlock (&release_agent_path_lock); +if (test_bit (CGRP_CPUSET_CLONE_CHILDREN , &root->top_cgroup.flags))seq_puts (seq,",clone_children" );if (strlen (root->name))seq_printf (seq,",name=%s" , root->name); -mutex_unlock (&cgroup_root_mutex);return 0 ; }
@@ -1272,8 +1280,11 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)if (ret) goto out_unlock; -if (opts.release_agent) +if (opts.release_agent) { +spin_lock (&release_agent_path_lock);strcpy (root->release_agent_path, opts.release_agent); +spin_unlock (&release_agent_path_lock); + } out_unlock:kfree (opts.release_agent);kfree (opts.name);
@@ -2176,7 +2187,9 @@ static int cgroup_release_agent_write(struct cgroup_subsys_state *css,if (!cgroup_lock_live_group (css->cgroup))return -ENODEV ;mutex_lock (&cgroup_root_mutex); +spin_lock (&release_agent_path_lock);strcpy (css->cgroup->root->release_agent_path, buffer); +spin_unlock (&release_agent_path_lock);mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);return 0 ;
Signature · 1 line
1.8.5.3
Tejun Heo
maintainerPATCH 6/6 cgroup: remove cgroup_root_mutex
In reply to Tejun Heocgroup_root_mutex was added to avoid deadlock involving namespace_sem via cgroup_show_options(). It added a lot of overhead for the small purpose of it and, because it's nested under cgroup_mutex, it has very limited usefulness. The previous patch made cgroup_show_options() not use cgroup_root_mutex, so nobody needs it anymore. Remove it.
--- kernel/cgroup.c | 42 +----------------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-)
kernel/cgroup.c +1 -41
@@ -70,18 +70,6 @@/* * cgroup_mutex is the master lock. Any modification to cgroup or its * hierarchy must be performed while holding it. -* -* cgroup_root_mutex nests inside cgroup_mutex and should be held to modify -* cgroupfs_root of any cgroup hierarchy - subsys list, flags, -* release_agent_path and so on. Modifying requires both cgroup_mutex and -* cgroup_root_mutex. Readers can acquire either of the two. This is to -* break the following locking order cycle. -* -* A. cgroup_mutex -> cred_guard_mutex -> s_type->i_mutex_key -> namespace_sem -* B. namespace_sem -> cgroup_mutex -* -* B happens only through cgroup_show_options() and using cgroup_root_mutex -* breaks it. */ #ifdef CONFIG_PROVE_RCU DEFINE_MUTEX (cgroup_mutex);
@@ -90,8 +78,6 @@ EXPORT_SYMBOL_GPL(cgroup_mutex); /* only for lockdep */static DEFINE_MUTEX (cgroup_mutex);#endif -static DEFINE_MUTEX (cgroup_root_mutex); -/* * Protects cgroup_subsys->release_agent_path. Modifying it also requires * cgroup_mutex. Reading requires either cgroup_mutex or this spinlock.
@@ -103,14 +89,6 @@ static DEFINE_SPINLOCK(release_agent_path_lock);lockdep_is_held (&cgroup_mutex), \ "cgroup_mutex or RCU read lock required"); -#ifdef CONFIG_LOCKDEP -#define cgroup_assert_mutex_or_root_locked () \ - WARN_ON_ONCE(debug_locks && (!lockdep_is_held(&cgroup_mutex) && \ - !lockdep_is_held(&cgroup_root_mutex))) -#else -#define cgroup_assert_mutex_or_root_locked () do { } while (0) -#endif -/* * cgroup destruction makes heavy use of work items and there can be a lot * of concurrent destructions. Use a separate workqueue so that cgroup
@@ -154,11 +132,7 @@ static struct cgroup * const cgroup_dummy_top = &cgroup_dummy_root.top_cgroup;static LIST_HEAD (cgroup_roots);static int cgroup_root_count; -/* -* Hierarchy ID allocation and mapping. It follows the same exclusion -* rules as other root ops - both cgroup_mutex and cgroup_root_mutex for -* writes, either for reads. -*/ +/* hierarchy ID allocation and mapping, protected by cgroup_mutex */ static DEFINE_IDR (cgroup_hierarchy_idr);static struct cgroup_name root_cgroup_name = { .name ="/" };
@@ -973,7 +947,6 @@ static int rebind_subsystems(struct cgroupfs_root *root,int i, ret;BUG_ON (!mutex_is_locked (&cgroup_mutex)); -BUG_ON (!mutex_is_locked (&cgroup_root_mutex));/* Check that any added subsystems are currently free */ for_each_subsys (ss, i)
@@ -1246,7 +1219,6 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)mutex_lock (&cgrp->dentry->d_inode->i_mutex);mutex_lock (&cgroup_mutex); -mutex_lock (&cgroup_root_mutex);/* See what subsystems are wanted */ ret =parse_cgroupfs_options (data, &opts);
@@ -1288,7 +1260,6 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data) out_unlock:kfree (opts.release_agent);kfree (opts.name); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);mutex_unlock (&cgrp->dentry->d_inode->i_mutex);return ret;
@@ -1331,7 +1302,6 @@ static int cgroup_init_root_id(struct cgroupfs_root *root, int start, int end)int id;lockdep_assert_held (&cgroup_mutex); -lockdep_assert_held (&cgroup_root_mutex); id =idr_alloc_cyclic (&cgroup_hierarchy_idr, root, start, end,GFP_KERNEL );
@@ -1345,7 +1315,6 @@ static int cgroup_init_root_id(struct cgroupfs_root *root, int start, int end)static void cgroup_exit_root_id (struct cgroupfs_root *root) {lockdep_assert_held (&cgroup_mutex); -lockdep_assert_held (&cgroup_root_mutex);if (root->hierarchy_id) {idr_remove (&cgroup_hierarchy_idr, root->hierarchy_id);
@@ -1517,7 +1486,6 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,mutex_lock (&inode->i_mutex);mutex_lock (&cgroup_mutex); -mutex_lock (&cgroup_root_mutex); ret =idr_alloc (&root->cgroup_idr, root_cgrp,0 ,1 ,GFP_KERNEL );if (ret <0 )
@@ -1590,7 +1558,6 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,BUG_ON (!list_empty (&root_cgrp->children));BUG_ON (root->number_of_cgroups !=1 ); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);mutex_unlock (&inode->i_mutex); }else {
@@ -1621,7 +1588,6 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,revert_creds (cred); unlock_drop:cgroup_exit_root_id (root); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);mutex_unlock (&inode->i_mutex); drop_new_super:
@@ -1646,7 +1612,6 @@ static void cgroup_kill_sb(struct super_block *sb)mutex_lock (&cgrp->dentry->d_inode->i_mutex);mutex_lock (&cgroup_mutex); -mutex_lock (&cgroup_root_mutex);/* Rebind all subsystems back to the default hierarchy */ if (root->flags &CGRP_ROOT_SUBSYS_BOUND ) {
@@ -1675,7 +1640,6 @@ static void cgroup_kill_sb(struct super_block *sb)cgroup_exit_root_id (root); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);mutex_unlock (&cgrp->dentry->d_inode->i_mutex);
@@ -2186,11 +2150,9 @@ static int cgroup_release_agent_write(struct cgroup_subsys_state *css,return -EINVAL ;if (!cgroup_lock_live_group (css->cgroup))return -ENODEV ; -mutex_lock (&cgroup_root_mutex);spin_lock (&release_agent_path_lock);strcpy (css->cgroup->root->release_agent_path, buffer);spin_unlock (&release_agent_path_lock); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex);return 0 ; }
@@ -4578,7 +4540,6 @@ int __init cgroup_init(void)/* allocate id for the dummy hierarchy */ mutex_lock (&cgroup_mutex); -mutex_lock (&cgroup_root_mutex);/* Add init_css_set to the hash table */ key =css_set_hash (init_css_set.subsys);
@@ -4590,7 +4551,6 @@ int __init cgroup_init(void) 0, 1, GFP_KERNEL);BUG_ON (err <0 ); -mutex_unlock (&cgroup_root_mutex);mutex_unlock (&cgroup_mutex); cgroup_kobj =kobject_create_and_add ("cgroup" , fs_kobj);
Signature · 1 line
1.8.5.3
Quoted 37 lines · Tejun Heo
Hello,
This is the second take. Changes from the last take[L] are
* Updated to reflect changes in
fe1217c4f3f7("net:net_cls: move cgroupfs classid handling into core").* Rebased on top of the current linus#master + some cgroup fix patches.
There's only one controller which makes use of the module support -
net_prio, which, non-coincidentally, isn't an actual resource controller. It's highly unlikely that the actual resource controlling controllers are gonna be made modular and we aren't gonna add more non-resource controllers either, so the value of module support is strictly restricted to the particular controller.The controller is fairly simple while module support in cgroup core adds quite a bit of complexity. Building the one controller as module only saves less than half-page in vmlinux, which really can't justify the additional complexity and (minute but existing) runtime overhead.
This patchset makes
net_prioconfig options bool so that it can't be built as modules and drops module support from cgroup core, which in turn facilitates further simplification leading to removal ofcgroup_root_mutexby allowing iterating subsystems outside the mutexes.This patchset contains the following six patches.
0001-cgroup-make-CONFIG_CGROUP_NET_PRIO-bool-and-drop-unn.patch 0002-cgroup-drop-module-support.patch 0003-cgroup-clean-up-cgroup_subsys-names-and-initializati.patch 0004-cgroup-rename-cgroup_subsys-subsys_id-to-id.patch 0005-cgroup-update-locking-in-cgroup_show_options.patch 0006-cgroup-remove-cgroup_root_mutex.patch
Quoted 6 lines
0001-0002 drop cgroup module support.
0003-0004 are cleanups.
0005-0006 remove
cgroup_root_mutex.
Tejun Heo
maintainerQuoted 6 lines · Tejun Heo
0001-cgroup-make-CONFIG_CGROUP_NET_PRIO-bool-and-drop-unn.patch 0002-cgroup-drop-module-support.patch 0003-cgroup-clean-up-cgroup_subsys-names-and-initializati.patch 0004-cgroup-rename-cgroup_subsys-subsys_id-to-id.patch 0005-cgroup-update-locking-in-cgroup_show_options.patch 0006-cgroup-remove-cgroup_root_mutex.patch
0001-0006 applied to cgroup/for-3.15.
Thanks.
Signature · 1 line
tejun