cgroups: support for module-loadable subsystems
Subsystems (5)
cover cgroups: support for module-loadable subsystems
[This is a revision of http://lkml.org/lkml/2009/12/4/53 ]
This patch series implements support for building, loading, and unloading subsystems as modules, both within and outside the kernel source tree. It provides an interface cgroup_load_subsys() and cgroup_unload_subsys() which modular subsystems can use to register and depart during runtime. The net_cls classifier subsystem serves as the example for a subsystem which can be converted into a module using these changes.
Patch #1 sets up the subsys[] array so its contents can be dynamic as modules appear and (eventually) disappear. Iterations over the array are modified to handle when subsystems are absent, and the dynamic section of the array is protected by cgroup_mutex.
Patch #2 implements an interface for modules to load subsystems, called cgroup_load_subsys, similar to cgroup_init_subsys, and adds a module pointer in struct cgroup_subsys.
Patch #3 modifies the net_cls subsystem, which already had some module declarations, to be configurable as a module, which also serves as a simple proof-of-concept.
Patch #4 adds a mechanism for unloading modular subsystems, which includes a more advanced rework of the rudimentary reference counting introduced in patch 2. It also modifies the exitcall of net_cls to use this interface.
Part of implementing patches 2 and 4 involved updating css pointers in each css_set when the module appears or leaves. In doing this, it was discovered that css_sets always remain linked to the dummy cgroup, regardless of whether or not any subsystems are actually bound to it (i.e., not mounted on an actual hierarchy). The subsystem loading and unloading code therefore should keep in mind the special cases where the added subsystem is the only one in the dummy cgroup (and therefore all css_sets need to be linked back into it) and where the removed subsys was the only one in the dummy cgroup (and therefore all css_sets should be unlinked from it) - however, as all css_sets always stay attached to the dummy cgroup anyway, these cases are ignored. Any fix that addresses this issue should also make sure these cases are addressed in the subsystem loading and unloading code.
-- bblum
---
Documentation/cgroups/cgroups.txt | 6 include/linux/cgroup.h | 16 + kernel/cgroup.c | 337 +++++++++++++++++++++++++++++++++----- net/sched/Kconfig | 5 net/sched/cls_cgroup.c | 40 +++- 5 files changed, 350 insertions(+), 54 deletions(-)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/4 cgroups: revamp subsys array
Make subsys[] able to be dynamically populated to support modular subsystems
From: Ben Blum <[email protected]>
This patch reworks the way the subsys[] array is used so that subsystems can register themselves after boot time, and enables the internals of cgroups to be able to handle when subsystems are not present or may appear/disappear.
---
include/linux/cgroup.h | 8 ++++- kernel/cgroup.c | 77 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 68 insertions(+), 17 deletions(-)
include/linux/cgroup.h +6 -2
@@ -41,13 +41,17 @@ extern int cgroupstats_build(struct cgroupstats *stats,extern struct file_operations proc_cgroup_operations; -/* Define the enumeration of all cgroup subsystems */ +/* Define the enumeration of all builtin cgroup subsystems */ #define SUBSYS (_x) _x ## _subsys_id,enum cgroup_subsys_id {#include <linux/cgroup_subsys.h> - CGROUP_SUBSYS_COUNT + CGROUP_BUILTIN_SUBSYS_COUNT };#undef SUBSYS +/* This define indicates the maximum number of subsystems that can be loaded +* at once. We limit to this many since cgroupfs_root has subsys_bits to keep +* track of all of them. */ +#define CGROUP_SUBSYS_COUNT (BITS_PER_BYTE*sizeof(unsigned long))/* Per-subsystem/per-cgroup state maintained by the system. */ struct cgroup_subsys_state {
kernel/cgroup.c +62 -15
219 lines not on this page · raw message
PATCH 2/4 cgroups: subsystem module loading interface
In reply to a message not in the archiveAdd interface between cgroups subsystem management and module loading
From: Ben Blum <[email protected]>
This patch implements rudimentary module-loading support for cgroups - namely, a cgroup_load_subsys (similar to cgroup_init_subsys) for use as a module initcall, and a struct module pointer in struct cgroup_subsys.
Several functions that might be wanted by modules have had EXPORT_SYMBOL added to them, but it's unclear exactly which functions want it and which won't.
---
Documentation/cgroups/cgroups.txt | 3 + include/linux/cgroup.h | 4 + kernel/cgroup.c | 114 +++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 0 deletions(-)
Documentation/cgroups/cgroups.txt +3 -0
@@ -492,6 +492,9 @@ Each subsystem should: - add an entry in linux/cgroup_subsys.h - define a cgroup_subsys object called <name>_subsys +If a subsystem can be compiled as a module, it should also have in its +module initcall a call to cgroup_load_subsys(). + Each subsystem may export the following methods. The only mandatory methods are create/destroy. Any others that are null are presumed to be successful no-ops.
include/linux/cgroup.h +4 -0
@@ -38,6 +38,7 @@ extern void cgroup_fork_failed(struct task_struct *p, int run_callbacks, unsigned long clone_flags);extern int cgroupstats_build (struct cgroupstats *stats,struct dentry *dentry); +extern int cgroup_load_subsys (struct cgroup_subsys *ss);extern struct file_operations proc_cgroup_operations;
@@ -477,6 +478,9 @@ struct cgroup_subsys {/* used when use_id == true */ struct idr idr;spinlock_t id_lock; + +/* should be defined only by modular subsystems */ +struct module *module; };#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys;
kernel/cgroup.c +114 -0
133 lines not on this page · raw message
PATCH 3/4 cgroups: net_cls as module
In reply to a message not in the archiveAllows the net_cls cgroup subsystem to be compiled as a module
From: Ben Blum <[email protected]>
This patch modifies net/sched/cls_cgroup.c to allow the net_cls subsystem to be optionally compiled as a module instead of builtin. The cgroup_subsys struct is moved around a bit to allow the subsys_id to be either declared as a compile-time constant by the cgroup_subsys.h include in cgroup.h, or, if it's a module, initialized within the struct by cgroup_load_subsys.
---
net/sched/Kconfig | 5 ++++- net/sched/cls_cgroup.c | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 10 deletions(-)
net/sched/Kconfig +4 -1
@@ -328,13 +328,16 @@ config NET_CLS_FLOW module will be called cls_flow. config NET_CLS_CGROUP - bool "Control Group Classifier" + tristate "Control Group Classifier" select NET_CLS depends on CGROUPS ---help--- Say Y here if you want to classify packets based on the control cgroup of their process. + To compile this code as a module, choose M here: the + module will be called cls_cgroup. + config NET_EMATCH bool "Extended Matches" select NET_CLS
net/sched/cls_cgroup.c +28 -9
@@ -24,6 +24,25 @@ struct cgroup_cls_stateu32 classid; }; +static struct cgroup_subsys_state *cgrp_create (struct cgroup_subsys *ss, +struct cgroup *cgrp); +static void cgrp_destroy (struct cgroup_subsys *ss,struct cgroup *cgrp); +static int cgrp_populate (struct cgroup_subsys *ss,struct cgroup *cgrp); + +struct cgroup_subsys net_cls_subsys = { + .name ="net_cls" , + .create = cgrp_create, + .destroy = cgrp_destroy, + .populate = cgrp_populate, +#ifdef CONFIG_NET_CLS_CGROUP + .subsys_id = net_cls_subsys_id, +#else +#define net_cls_subsys_id net_cls_subsys.subsys_id +#endif + .module =THIS_MODULE , +}; + +static inline struct cgroup_cls_state *cgrp_cls_state (struct cgroup *cgrp) { return container_of(cgroup_subsys_state(cgrp, net_cls_subsys_id),
@@ -79,14 +98,6 @@ static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)return cgroup_add_files (cgrp, ss, ss_files,ARRAY_SIZE (ss_files)); } -struct cgroup_subsys net_cls_subsys = { - .name ="net_cls" , - .create = cgrp_create, - .destroy = cgrp_destroy, - .populate = cgrp_populate, - .subsys_id = net_cls_subsys_id, -}; -struct cls_cgroup_head {u32 handle;
@@ -277,12 +288,20 @@ static struct tcf_proto_ops cls_cgroup_ops __read_mostly = {static int __init init_cgroup_cls (void ) { -return register_tcf_proto_ops (&cls_cgroup_ops); +int ret =register_tcf_proto_ops (&cls_cgroup_ops); +if (ret) +return ret; + ret =cgroup_load_subsys (&net_cls_subsys); +if (ret) +unregister_tcf_proto_ops (&cls_cgroup_ops); +return ret; } static void __exit exit_cgroup_cls(void) {unregister_tcf_proto_ops (&cls_cgroup_ops); +/* TODO: unload subsystem. for now, the try_module_get in load_subsys +* prevents us from getting here. */ }module_init (init_cgroup_cls);
PATCH 4/4 cgroups: subsystem module unloading
In reply to a message not in the archiveProvides support for unloading modular subsystems.
From: Ben Blum <[email protected]>
This patch adds a new function cgroup_unload_subsys which is to be used for removing a loaded subsystem during module deletion. Reference counting of the subsystems' modules is moved from once (at load time) to once per attached hierarchy (in parse_cgroupfs_options and rebind_subsystems) (i.e., 0 or 1).
It also adds a proper module_delete call in net/sched/cls_cgroup.c.
---
Documentation/cgroups/cgroups.txt | 3 + include/linux/cgroup.h | 4 + kernel/cgroup.c | 146 +++++++++++++++++++++++++++++++------ net/sched/cls_cgroup.c | 3 - 4 files changed, 129 insertions(+), 27 deletions(-)
Documentation/cgroups/cgroups.txt +2 -1
@@ -493,7 +493,8 @@ Each subsystem should: - define a cgroup_subsys object called <name>_subsys If a subsystem can be compiled as a module, it should also have in its -module initcall a call to cgroup_load_subsys(). +module initcall a call to cgroup_load_subsys(), and in its exitcall a +call to cgroup_unload_subsys(). Each subsystem may export the following methods. The only mandatory methods are create/destroy. Any others that are null are presumed to
include/linux/cgroup.h +3 -1
@@ -39,6 +39,7 @@ extern void cgroup_fork_failed(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 struct file_operations proc_cgroup_operations;
@@ -264,7 +265,8 @@ struct css_set {/* * 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). +* during subsystem registration (at boot time) and modular subsystem +* loading/unloading. */ struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT ];
kernel/cgroup.c +123 -23
259 lines not on this page · raw message
net/sched/cls_cgroup.c +1 -2
@@ -300,8 +300,7 @@ static int __init init_cgroup_cls(void) static void __exit exit_cgroup_cls(void) {unregister_tcf_proto_ops (&cls_cgroup_ops); -/* TODO: unload subsystem. for now, the try_module_get in load_subsys -* prevents us from getting here. */ +cgroup_unload_subsys (&net_cls_subsys); }module_init (init_cgroup_cls);
PATCH 1/4 cgroups: revamp subsys array
In reply to Ben BlumMake subsys[] able to be dynamically populated to support modular subsystems
From: Ben Blum <[email protected]>
This patch reworks the way the subsys[] array is used so that subsystems can register themselves after boot time, and enables the internals of cgroups to be able to handle when subsystems are not present or may appear/disappear.
---
include/linux/cgroup.h | 8 ++++- kernel/cgroup.c | 77 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 68 insertions(+), 17 deletions(-)
include/linux/cgroup.h +6 -2
@@ -41,13 +41,17 @@ extern int cgroupstats_build(struct cgroupstats *stats,extern struct file_operations proc_cgroup_operations; -/* Define the enumeration of all cgroup subsystems */ +/* Define the enumeration of all builtin cgroup subsystems */ #define SUBSYS (_x) _x ## _subsys_id,enum cgroup_subsys_id {#include <linux/cgroup_subsys.h> - CGROUP_SUBSYS_COUNT + CGROUP_BUILTIN_SUBSYS_COUNT };#undef SUBSYS +/* This define indicates the maximum number of subsystems that can be loaded +* at once. We limit to this many since cgroupfs_root has subsys_bits to keep +* track of all of them. */ +#define CGROUP_SUBSYS_COUNT (BITS_PER_BYTE*sizeof(unsigned long))/* Per-subsystem/per-cgroup state maintained by the system. */ struct cgroup_subsys_state {
kernel/cgroup.c +62 -15
219 lines not on this page · raw message
Re: [PATCH 1/4] cgroups: revamp subsys array
Quoted 9 lines
Make subsys[] able to be dynamically populated to support modular subsystems
From: Ben Blum <[email protected]>
This patch reworks the way the subsys[] array is used so that subsystems can register themselves after boot time, and enables the internals of cgroups to be able to handle when subsystems are not present or may appear/disappear.
Signed-off-by Ben Blum <[email protected]>
...
A small nitpick:
Quoted 3 lines
+/* This define indicates the maximum number of subsystems that can be loaded
+ * at once. We limit to this many sincecgroupfs_roothassubsys_bitsto keep
+ * track of all of them. */
Please always use this style:
/*
* xxx
* xxx
*/
PATCH 2/4 cgroups: subsystem module loading interface
In reply to Ben BlumAdd interface between cgroups subsystem management and module loading
From: Ben Blum <[email protected]>
This patch implements rudimentary module-loading support for cgroups - namely, a cgroup_load_subsys (similar to cgroup_init_subsys) for use as a module initcall, and a struct module pointer in struct cgroup_subsys.
Several functions that might be wanted by modules have had EXPORT_SYMBOL added to them, but it's unclear exactly which functions want it and which won't.
---
Documentation/cgroups/cgroups.txt | 3 + include/linux/cgroup.h | 4 + kernel/cgroup.c | 114 +++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 0 deletions(-)
Documentation/cgroups/cgroups.txt +3 -0
@@ -492,6 +492,9 @@ Each subsystem should: - add an entry in linux/cgroup_subsys.h - define a cgroup_subsys object called <name>_subsys +If a subsystem can be compiled as a module, it should also have in its +module initcall a call to cgroup_load_subsys(). + Each subsystem may export the following methods. The only mandatory methods are create/destroy. Any others that are null are presumed to be successful no-ops.
include/linux/cgroup.h +4 -0
@@ -38,6 +38,7 @@ extern void cgroup_fork_failed(struct task_struct *p, int run_callbacks, unsigned long clone_flags);extern int cgroupstats_build (struct cgroupstats *stats,struct dentry *dentry); +extern int cgroup_load_subsys (struct cgroup_subsys *ss);extern struct file_operations proc_cgroup_operations;
@@ -477,6 +478,9 @@ struct cgroup_subsys {/* used when use_id == true */ struct idr idr;spinlock_t id_lock; + +/* should be defined only by modular subsystems */ +struct module *module; };#define SUBSYS (_x) extern struct cgroup_subsys _x ## _subsys;
kernel/cgroup.c +114 -0
133 lines not on this page · raw message
A message that is not in the archive (sent off-list or not yet received): [email protected]
Li Zefan
Acked-byRe: [PATCH 2/4] cgroups: subsystem module loading interface
Quoted 4 lines
Add interface between cgroups subsystem management and module loading
From: Ben Blum <[email protected]>
Quoted 8 lines
This patch implements rudimentary module-loading support for cgroups - namely, a
cgroup_load_subsys(similar tocgroup_init_subsys) for use as a module initcall, and a struct module pointer in structcgroup_subsys.Several functions that might be wanted by modules have had
EXPORT_SYMBOLadded to them, but it's unclear exactly which functions want it and which won't.Signed-off-by Ben Blum <[email protected]>
Some small nitpicks:
kernel/cgroup.c int cgroup_add_file(struct cgroup *cgrp, · line 2480
Quoted 7 lines
kernel/cgroup.c +1
-0@@ -2477,6 +2477,7 @@ int cgroup_add_file(struct cgroup *cgrp, error =PTR_ERR (dentry);return error; } +EXPORT_SYMBOL_GPL (cgroup_add_file);
I got compile errors, because you forgot to include <linux/module.h>
...
kernel/cgroup.c static void __init cgroup_init_subsys(struct cgroup_subsys *ss) · line 3726
Quoted 5 lines
kernel/cgroup.c +5
-0+write_lock (&css_set_lock); +for (i =0 ; i <CSS_SET_TABLE_SIZE ; i++) { +struct css_set *cg; +struct hlist_node *node, *tmp; +struct hlist_head *bucket = &css_set_table[i], *new_bucket;
Please add a blank line between variable declaration and other code.
And elsewhere in this patchset.
Quoted 14 lines
kernel/cgroup.c +14
-0+hlist_for_each_entry_safe (cg, node, tmp, bucket, hlist) { +/* skip entries that we already rehashed */ +if (cg->subsys[ss->subsys_id]) +continue ; +/* remove existing entry */ +hlist_del (&cg->hlist); +/* set new value */ + cg->subsys[ss->subsys_id] = css; +/* recompute hash and restore entry */ + new_bucket =css_set_hash (cg->subsys); +hlist_add_head (&cg->hlist, new_bucket); + } + } +write_unlock (&css_set_lock);
Re: [PATCH 2/4] cgroups: subsystem module loading interface
In reply to Ben BlumQuoted 4 lines
Add interface between cgroups subsystem management and module loading
From: Ben Blum <[email protected]>
Quoted 8 lines
This patch implements rudimentary module-loading support for cgroups - namely, a
cgroup_load_subsys(similar tocgroup_init_subsys) for use as a module initcall, and a struct module pointer in structcgroup_subsys.Several functions that might be wanted by modules have had
EXPORT_SYMBOLadded to them, but it's unclear exactly which functions want it and which won't.Signed-off-by Ben Blum <[email protected]>
Some small nitpicks:
kernel/cgroup.c int cgroup_add_file(struct cgroup *cgrp, · line 2480
Quoted 7 lines
kernel/cgroup.c +1
-0@@ -2477,6 +2477,7 @@ int cgroup_add_file(struct cgroup *cgrp, error =PTR_ERR (dentry);return error; } +EXPORT_SYMBOL_GPL (cgroup_add_file);
I got compile errors, because you forgot to include <linux/module.h>
...
kernel/cgroup.c static void __init cgroup_init_subsys(struct cgroup_subsys *ss) · line 3726
Quoted 5 lines
kernel/cgroup.c +5
-0+write_lock (&css_set_lock); +for (i =0 ; i <CSS_SET_TABLE_SIZE ; i++) { +struct css_set *cg; +struct hlist_node *node, *tmp; +struct hlist_head *bucket = &css_set_table[i], *new_bucket;
Please add a blank line between variable declaration and other code.
And elsewhere in this patchset.
Quoted 14 lines
kernel/cgroup.c +14
-0+hlist_for_each_entry_safe (cg, node, tmp, bucket, hlist) { +/* skip entries that we already rehashed */ +if (cg->subsys[ss->subsys_id]) +continue ; +/* remove existing entry */ +hlist_del (&cg->hlist); +/* set new value */ + cg->subsys[ss->subsys_id] = css; +/* recompute hash and restore entry */ + new_bucket =css_set_hash (cg->subsys); +hlist_add_head (&cg->hlist, new_bucket); + } + } +write_unlock (&css_set_lock);
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/4] cgroups: subsystem module loading interface
Quoted 36 lines · Li Zefan
Quoted 4 lines
Add interface between cgroups subsystem management and module loading
From: Ben Blum <[email protected]>
Quoted 8 lines
This patch implements rudimentary module-loading support for cgroups - namely, a
cgroup_load_subsys(similar tocgroup_init_subsys) for use as a module initcall, and a struct module pointer in structcgroup_subsys.Several functions that might be wanted by modules have had
EXPORT_SYMBOLadded to them, but it's unclear exactly which functions want it and which won't.Signed-off-by Ben Blum <[email protected]>Acked-by Li Zefan <[email protected]>Some small nitpicks:
kernel/cgroup.c int cgroup_add_file(struct cgroup *cgrp, · line 2480
Quoted 7 lines
kernel/cgroup.c +1
-0@@ -2477,6 +2477,7 @@ int cgroup_add_file(struct cgroup *cgrp, error =PTR_ERR (dentry);return error; } +EXPORT_SYMBOL_GPL (cgroup_add_file);I got compile errors, because you forgot to include <
linux/module.h>...
kernel/cgroup.c static void __init cgroup_init_subsys(struct cgroup_subsys *ss) · line 3726
Quoted 5 lines
kernel/cgroup.c +5
-0+write_lock (&css_set_lock); +for (i =0 ; i <CSS_SET_TABLE_SIZE ; i++) { +struct css_set *cg; +struct hlist_node *node, *tmp; +struct hlist_head *bucket = &css_set_table[i], *new_bucket;Please add a blank line between variable declaration and other code.
Quoted 2 lines
And elsewhere in this patchset.
checkpatch.pl didn't trip on this [and the more screenspace-intensive comment style]; are they cgroups-specific style requirements or from somewhere higher up?
Quoted 17 lines
Quoted 14 lines
kernel/cgroup.c +14
-0+hlist_for_each_entry_safe (cg, node, tmp, bucket, hlist) { +/* skip entries that we already rehashed */ +if (cg->subsys[ss->subsys_id]) +continue ; +/* remove existing entry */ +hlist_del (&cg->hlist); +/* set new value */ + cg->subsys[ss->subsys_id] = css; +/* recompute hash and restore entry */ + new_bucket =css_set_hash (cg->subsys); +hlist_add_head (&cg->hlist, new_bucket); + } + } +write_unlock (&css_set_lock);
Re: [PATCH 2/4] cgroups: subsystem module loading interface
In reply to Li ZefanQuoted 36 lines · Li Zefan
Quoted 4 lines
Add interface between cgroups subsystem management and module loading
From: Ben Blum <[email protected]>
Quoted 8 lines
This patch implements rudimentary module-loading support for cgroups - namely, a
cgroup_load_subsys(similar tocgroup_init_subsys) for use as a module initcall, and a struct module pointer in structcgroup_subsys.Several functions that might be wanted by modules have had
EXPORT_SYMBOLadded to them, but it's unclear exactly which functions want it and which won't.Signed-off-by Ben Blum <[email protected]>Acked-by Li Zefan <[email protected]>Some small nitpicks:
kernel/cgroup.c int cgroup_add_file(struct cgroup *cgrp, · line 2480
Quoted 7 lines
kernel/cgroup.c +1
-0@@ -2477,6 +2477,7 @@ int cgroup_add_file(struct cgroup *cgrp, error =PTR_ERR (dentry);return error; } +EXPORT_SYMBOL_GPL (cgroup_add_file);I got compile errors, because you forgot to include <
linux/module.h>...
kernel/cgroup.c static void __init cgroup_init_subsys(struct cgroup_subsys *ss) · line 3726
Quoted 5 lines
kernel/cgroup.c +5
-0+write_lock (&css_set_lock); +for (i =0 ; i <CSS_SET_TABLE_SIZE ; i++) { +struct css_set *cg; +struct hlist_node *node, *tmp; +struct hlist_head *bucket = &css_set_table[i], *new_bucket;Please add a blank line between variable declaration and other code.
Quoted 2 lines
And elsewhere in this patchset.
checkpatch.pl didn't trip on this [and the more screenspace-intensive comment style]; are they cgroups-specific style requirements or from somewhere higher up?
Quoted 17 lines
Quoted 14 lines
kernel/cgroup.c +14
-0+hlist_for_each_entry_safe (cg, node, tmp, bucket, hlist) { +/* skip entries that we already rehashed */ +if (cg->subsys[ss->subsys_id]) +continue ; +/* remove existing entry */ +hlist_del (&cg->hlist); +/* set new value */ + cg->subsys[ss->subsys_id] = css; +/* recompute hash and restore entry */ + new_bucket =css_set_hash (cg->subsys); +hlist_add_head (&cg->hlist, new_bucket); + } + } +write_unlock (&css_set_lock);
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/4] cgroups: subsystem module loading interface
Quoted 7 lines
Quoted 7 lines
kernel/cgroup.c static void __init cgroup_init_subsys(struct cgroup_subsys *ss) · line 3726
Quoted 5 lines
kernel/cgroup.c +5
-0+write_lock (&css_set_lock); +for (i =0 ; i <CSS_SET_TABLE_SIZE ; i++) { +struct css_set *cg; +struct hlist_node *node, *tmp; +struct hlist_head *bucket = &css_set_table[i], *new_bucket;Please add a blank line between variable declaration and other code.
Quoted 7 lines
Quoted 2 lines
And elsewhere in this patchset.
checkpatch.pl didn't trip on this [and the more screenspace-intensive comment style]; are they cgroups-specific style requirements or from somewhere higher up?
You'll find the comment style in Documentation/CodingStyle:
==============
The preferred style for long (multi-line) comments is:
/*
* This is the preferred style for multi-line
* comments in the Linux kernel source code.
* Please use it consistently.
*
* Description: A column of asterisks on the left side,
* with beginning and ending almost-blank lines. */
==============
Though the other coding style is not documented, I think it's well accepted.
You'll hardly find code that breaks this style, say in kernel/* and mm/*. And you can see that people pointed out this when they were reviewing patches.
And the fact is it does make the code more readable.
Re: [PATCH 2/4] cgroups: subsystem module loading interface
In reply to Ben BlumQuoted 7 lines
Quoted 7 lines
kernel/cgroup.c static void __init cgroup_init_subsys(struct cgroup_subsys *ss) · line 3726
Quoted 5 lines
kernel/cgroup.c +5
-0+write_lock (&css_set_lock); +for (i =0 ; i <CSS_SET_TABLE_SIZE ; i++) { +struct css_set *cg; +struct hlist_node *node, *tmp; +struct hlist_head *bucket = &css_set_table[i], *new_bucket;Please add a blank line between variable declaration and other code.
Quoted 7 lines
Quoted 2 lines
And elsewhere in this patchset.
checkpatch.pl didn't trip on this [and the more screenspace-intensive comment style]; are they cgroups-specific style requirements or from somewhere higher up?
You'll find the comment style in Documentation/CodingStyle:
==============
The preferred style for long (multi-line) comments is:
/*
* This is the preferred style for multi-line
* comments in the Linux kernel source code.
* Please use it consistently.
*
* Description: A column of asterisks on the left side,
* with beginning and ending almost-blank lines. */
==============
Though the other coding style is not documented, I think it's well accepted.
You'll hardly find code that breaks this style, say in kernel/* and mm/*. And you can see that people pointed out this when they were reviewing patches.
And the fact is it does make the code more readable.
PATCH 3/4 cgroups: net_cls as module
In reply to Ben BlumAllows the net_cls cgroup subsystem to be compiled as a module
From: Ben Blum <[email protected]>
This patch modifies net/sched/cls_cgroup.c to allow the net_cls subsystem to be optionally compiled as a module instead of builtin. The cgroup_subsys struct is moved around a bit to allow the subsys_id to be either declared as a compile-time constant by the cgroup_subsys.h include in cgroup.h, or, if it's a module, initialized within the struct by cgroup_load_subsys.
---
net/sched/Kconfig | 5 ++++- net/sched/cls_cgroup.c | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 10 deletions(-)
net/sched/Kconfig +4 -1
@@ -328,13 +328,16 @@ config NET_CLS_FLOW module will be called cls_flow. config NET_CLS_CGROUP - bool "Control Group Classifier" + tristate "Control Group Classifier" select NET_CLS depends on CGROUPS ---help--- Say Y here if you want to classify packets based on the control cgroup of their process. + To compile this code as a module, choose M here: the + module will be called cls_cgroup. + config NET_EMATCH bool "Extended Matches" select NET_CLS
net/sched/cls_cgroup.c +28 -9
@@ -24,6 +24,25 @@ struct cgroup_cls_stateu32 classid; }; +static struct cgroup_subsys_state *cgrp_create (struct cgroup_subsys *ss, +struct cgroup *cgrp); +static void cgrp_destroy (struct cgroup_subsys *ss,struct cgroup *cgrp); +static int cgrp_populate (struct cgroup_subsys *ss,struct cgroup *cgrp); + +struct cgroup_subsys net_cls_subsys = { + .name ="net_cls" , + .create = cgrp_create, + .destroy = cgrp_destroy, + .populate = cgrp_populate, +#ifdef CONFIG_NET_CLS_CGROUP + .subsys_id = net_cls_subsys_id, +#else +#define net_cls_subsys_id net_cls_subsys.subsys_id +#endif + .module =THIS_MODULE , +}; + +static inline struct cgroup_cls_state *cgrp_cls_state (struct cgroup *cgrp) { return container_of(cgroup_subsys_state(cgrp, net_cls_subsys_id),
@@ -79,14 +98,6 @@ static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)return cgroup_add_files (cgrp, ss, ss_files,ARRAY_SIZE (ss_files)); } -struct cgroup_subsys net_cls_subsys = { - .name ="net_cls" , - .create = cgrp_create, - .destroy = cgrp_destroy, - .populate = cgrp_populate, - .subsys_id = net_cls_subsys_id, -}; -struct cls_cgroup_head {u32 handle;
@@ -277,12 +288,20 @@ static struct tcf_proto_ops cls_cgroup_ops __read_mostly = {static int __init init_cgroup_cls (void ) { -return register_tcf_proto_ops (&cls_cgroup_ops); +int ret =register_tcf_proto_ops (&cls_cgroup_ops); +if (ret) +return ret; + ret =cgroup_load_subsys (&net_cls_subsys); +if (ret) +unregister_tcf_proto_ops (&cls_cgroup_ops); +return ret; } static void __exit exit_cgroup_cls(void) {unregister_tcf_proto_ops (&cls_cgroup_ops); +/* TODO: unload subsystem. for now, the try_module_get in load_subsys +* prevents us from getting here. */ }module_init (init_cgroup_cls);
A message that is not in the archive (sent off-list or not yet received): [email protected]
Li Zefan
Acked-byRe: [PATCH 3/4] cgroups: net_cls as module
Quoted 11 lines
Allows the
net_clscgroup subsystem to be compiled as a moduleFrom: Ben Blum <[email protected]>
This patch modifies
net/sched/cls_cgroup.cto allow thenet_clssubsystem to be optionally compiled as a module instead of builtin. Thecgroup_subsysstruct is moved around a bit to allow thesubsys_idto be either declared as a compile-time constant by thecgroup_subsys.hinclude incgroup.h, or, if it's a module, initialized within the struct bycgroup_load_subsys.Signed-off-by Ben Blum <[email protected]>
But can we reorder this patch as the last patch?
Re: [PATCH 3/4] cgroups: net_cls as module
In reply to Ben BlumQuoted 11 lines
Allows the
net_clscgroup subsystem to be compiled as a moduleFrom: Ben Blum <[email protected]>
This patch modifies
net/sched/cls_cgroup.cto allow thenet_clssubsystem to be optionally compiled as a module instead of builtin. Thecgroup_subsysstruct is moved around a bit to allow thesubsys_idto be either declared as a compile-time constant by thecgroup_subsys.hinclude incgroup.h, or, if it's a module, initialized within the struct bycgroup_load_subsys.Signed-off-by Ben Blum <[email protected]>
But can we reorder this patch as the last patch?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/4] cgroups: net_cls as module
Quoted 10 lines · Li Zefan
Quoted 10 lines
Allows the
net_clscgroup subsystem to be compiled as a moduleFrom: Ben Blum <[email protected]>
This patch modifies
net/sched/cls_cgroup.cto allow thenet_clssubsystem to be optionally compiled as a module instead of builtin. Thecgroup_subsysstruct is moved around a bit to allow thesubsys_idto be either declared as a compile-time constant by thecgroup_subsys.hinclude incgroup.h, or, if it's a module, initialized within the struct bycgroup_load_subsys.
Quoted 5 lines
Quoted 1 line
Signed-off-by Ben Blum <[email protected]>Acked-by Li Zefan <[email protected]>But can we reorder this patch as the last patch?
that does make a bit more sense, saving the unloading patch from having to touch cls_cgroup.c to add an unload_subsys() call. will do.
Re: [PATCH 3/4] cgroups: net_cls as module
In reply to Li ZefanQuoted 10 lines · Li Zefan
Quoted 10 lines
Allows the
net_clscgroup subsystem to be compiled as a moduleFrom: Ben Blum <[email protected]>
This patch modifies
net/sched/cls_cgroup.cto allow thenet_clssubsystem to be optionally compiled as a module instead of builtin. Thecgroup_subsysstruct is moved around a bit to allow thesubsys_idto be either declared as a compile-time constant by thecgroup_subsys.hinclude incgroup.h, or, if it's a module, initialized within the struct bycgroup_load_subsys.
Quoted 5 lines
Quoted 1 line
Signed-off-by Ben Blum <[email protected]>Acked-by Li Zefan <[email protected]>But can we reorder this patch as the last patch?
that does make a bit more sense, saving the unloading patch from having to touch cls_cgroup.c to add an unload_subsys() call. will do.
PATCH 4/4 cgroups: subsystem module unloading
In reply to Ben BlumProvides support for unloading modular subsystems.
From: Ben Blum <[email protected]>
This patch adds a new function cgroup_unload_subsys which is to be used for removing a loaded subsystem during module deletion. Reference counting of the subsystems' modules is moved from once (at load time) to once per attached hierarchy (in parse_cgroupfs_options and rebind_subsystems) (i.e., 0 or 1).
It also adds a proper module_delete call in net/sched/cls_cgroup.c.
---
Documentation/cgroups/cgroups.txt | 3 + include/linux/cgroup.h | 4 + kernel/cgroup.c | 146 +++++++++++++++++++++++++++++++------ net/sched/cls_cgroup.c | 3 - 4 files changed, 129 insertions(+), 27 deletions(-)
Documentation/cgroups/cgroups.txt +2 -1
@@ -493,7 +493,8 @@ Each subsystem should: - define a cgroup_subsys object called <name>_subsys If a subsystem can be compiled as a module, it should also have in its -module initcall a call to cgroup_load_subsys(). +module initcall a call to cgroup_load_subsys(), and in its exitcall a +call to cgroup_unload_subsys(). Each subsystem may export the following methods. The only mandatory methods are create/destroy. Any others that are null are presumed to
include/linux/cgroup.h +3 -1
@@ -39,6 +39,7 @@ extern void cgroup_fork_failed(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 struct file_operations proc_cgroup_operations;
@@ -264,7 +265,8 @@ struct css_set {/* * 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). +* during subsystem registration (at boot time) and modular subsystem +* loading/unloading. */ struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT ];
kernel/cgroup.c +123 -23
259 lines not on this page · raw message
net/sched/cls_cgroup.c +1 -2
@@ -300,8 +300,7 @@ static int __init init_cgroup_cls(void) static void __exit exit_cgroup_cls(void) {unregister_tcf_proto_ops (&cls_cgroup_ops); -/* TODO: unload subsystem. for now, the try_module_get in load_subsys -* prevents us from getting here. */ +cgroup_unload_subsys (&net_cls_subsys); }module_init (init_cgroup_cls);
Re: [PATCH 4/4] cgroups: subsystem module unloading
Quoted 4 lines
Provides support for unloading modular subsystems.
From: Ben Blum <[email protected]>
Quoted 8 lines
This patch adds a new function
cgroup_unload_subsyswhich is to be used for removing a loaded subsystem during module deletion. Reference counting of the subsystems' modules is moved from once (at load time) to once per attached hierarchy (inparse_cgroupfs_optionsandrebind_subsystems) (i.e., 0 or 1).It also adds a proper
module_deletecall innet/sched/cls_cgroup.c.Signed-off-by Ben Blum <[email protected]>
Also please fix comment style and add some blank lines properly.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Li Zefan
Acked-byRe: [PATCH 4/4] cgroups: subsystem module unloading
Quoted 4 lines
Provides support for unloading modular subsystems.
From: Ben Blum <[email protected]>
Quoted 8 lines
This patch adds a new function
cgroup_unload_subsyswhich is to be used for removing a loaded subsystem during module deletion. Reference counting of the subsystems' modules is moved from once (at load time) to once per attached hierarchy (inparse_cgroupfs_optionsandrebind_subsystems) (i.e., 0 or 1).It also adds a proper
module_deletecall innet/sched/cls_cgroup.c.Signed-off-by Ben Blum <[email protected]>
Also please fix comment style and add some blank lines properly.