Commit 67523c48aa74d5637848edeccf285af1c60bf14a

Authored by Ben Blum
Committed by Linus Torvalds
1 parent 8ca712ea84

cgroups: blkio subsystem as module

Modify the Block I/O cgroup subsystem to be able to be built as a module.
As the CFQ disk scheduler optionally depends on blk-cgroup, config options
in block/Kconfig, block/Kconfig.iosched, and block/blk-cgroup.h are
enhanced to support the new module dependency.

Signed-off-by: Ben Blum <bblum@andrew.cmu.edu>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Paul Menage <menage@google.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 6 changed files with 61 additions and 17 deletions Side-by-side Diff

... ... @@ -78,7 +78,7 @@
78 78 Protection. If in doubt, say N.
79 79  
80 80 config BLK_CGROUP
81   - bool
  81 + tristate
82 82 depends on CGROUPS
83 83 default n
84 84 ---help---
block/Kconfig.iosched
... ... @@ -23,6 +23,7 @@
23 23  
24 24 config IOSCHED_CFQ
25 25 tristate "CFQ I/O scheduler"
  26 + select BLK_CGROUP if CFQ_GROUP_IOSCHED
26 27 default y
27 28 ---help---
28 29 The CFQ I/O scheduler tries to distribute bandwidth equally
... ... @@ -35,7 +36,6 @@
35 36 config CFQ_GROUP_IOSCHED
36 37 bool "CFQ Group Scheduling support"
37 38 depends on IOSCHED_CFQ && CGROUPS
38   - select BLK_CGROUP
39 39 default n
40 40 ---help---
41 41 Enable group IO scheduling in CFQ.
... ... @@ -23,6 +23,31 @@
23 23 struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
24 24 EXPORT_SYMBOL_GPL(blkio_root_cgroup);
25 25  
  26 +static struct cgroup_subsys_state *blkiocg_create(struct cgroup_subsys *,
  27 + struct cgroup *);
  28 +static int blkiocg_can_attach(struct cgroup_subsys *, struct cgroup *,
  29 + struct task_struct *, bool);
  30 +static void blkiocg_attach(struct cgroup_subsys *, struct cgroup *,
  31 + struct cgroup *, struct task_struct *, bool);
  32 +static void blkiocg_destroy(struct cgroup_subsys *, struct cgroup *);
  33 +static int blkiocg_populate(struct cgroup_subsys *, struct cgroup *);
  34 +
  35 +struct cgroup_subsys blkio_subsys = {
  36 + .name = "blkio",
  37 + .create = blkiocg_create,
  38 + .can_attach = blkiocg_can_attach,
  39 + .attach = blkiocg_attach,
  40 + .destroy = blkiocg_destroy,
  41 + .populate = blkiocg_populate,
  42 +#ifdef CONFIG_BLK_CGROUP
  43 + /* note: blkio_subsys_id is otherwise defined in blk-cgroup.h */
  44 + .subsys_id = blkio_subsys_id,
  45 +#endif
  46 + .use_id = 1,
  47 + .module = THIS_MODULE,
  48 +};
  49 +EXPORT_SYMBOL_GPL(blkio_subsys);
  50 +
26 51 struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)
27 52 {
28 53 return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id),
... ... @@ -253,7 +278,8 @@
253 278 done:
254 279 free_css_id(&blkio_subsys, &blkcg->css);
255 280 rcu_read_unlock();
256   - kfree(blkcg);
  281 + if (blkcg != &blkio_root_cgroup)
  282 + kfree(blkcg);
257 283 }
258 284  
259 285 static struct cgroup_subsys_state *
... ... @@ -319,17 +345,6 @@
319 345 task_unlock(tsk);
320 346 }
321 347  
322   -struct cgroup_subsys blkio_subsys = {
323   - .name = "blkio",
324   - .create = blkiocg_create,
325   - .can_attach = blkiocg_can_attach,
326   - .attach = blkiocg_attach,
327   - .destroy = blkiocg_destroy,
328   - .populate = blkiocg_populate,
329   - .subsys_id = blkio_subsys_id,
330   - .use_id = 1,
331   -};
332   -
333 348 void blkio_policy_register(struct blkio_policy_type *blkiop)
334 349 {
335 350 spin_lock(&blkio_list_lock);
... ... @@ -345,4 +360,18 @@
345 360 spin_unlock(&blkio_list_lock);
346 361 }
347 362 EXPORT_SYMBOL_GPL(blkio_policy_unregister);
  363 +
  364 +static int __init init_cgroup_blkio(void)
  365 +{
  366 + return cgroup_load_subsys(&blkio_subsys);
  367 +}
  368 +
  369 +static void __exit exit_cgroup_blkio(void)
  370 +{
  371 + cgroup_unload_subsys(&blkio_subsys);
  372 +}
  373 +
  374 +module_init(init_cgroup_blkio);
  375 +module_exit(exit_cgroup_blkio);
  376 +MODULE_LICENSE("GPL");
... ... @@ -15,8 +15,14 @@
15 15  
16 16 #include <linux/cgroup.h>
17 17  
18   -#ifdef CONFIG_BLK_CGROUP
  18 +#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
19 19  
  20 +#ifndef CONFIG_BLK_CGROUP
  21 +/* When blk-cgroup is a module, its subsys_id isn't a compile-time constant */
  22 +extern struct cgroup_subsys blkio_subsys;
  23 +#define blkio_subsys_id blkio_subsys.subsys_id
  24 +#endif
  25 +
20 26 struct blkio_cgroup {
21 27 struct cgroup_subsys_state css;
22 28 unsigned int weight;
... ... @@ -91,7 +97,7 @@
91 97 struct blkio_group *blkg, unsigned long dequeue) {}
92 98 #endif
93 99  
94   -#ifdef CONFIG_BLK_CGROUP
  100 +#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
95 101 extern struct blkio_cgroup blkio_root_cgroup;
96 102 extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
97 103 extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
include/linux/iocontext.h
... ... @@ -42,7 +42,7 @@
42 42 unsigned short ioprio;
43 43 unsigned short ioprio_changed;
44 44  
45   -#ifdef CONFIG_BLK_CGROUP
  45 +#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
46 46 unsigned short cgroup_changed;
47 47 #endif
48 48  
... ... @@ -705,6 +705,7 @@
705 705 {
706 706 mutex_lock(&cgroup_mutex);
707 707 }
  708 +EXPORT_SYMBOL_GPL(cgroup_lock);
708 709  
709 710 /**
710 711 * cgroup_unlock - release lock on cgroup changes
... ... @@ -715,6 +716,7 @@
715 716 {
716 717 mutex_unlock(&cgroup_mutex);
717 718 }
  719 +EXPORT_SYMBOL_GPL(cgroup_unlock);
718 720  
719 721 /*
720 722 * A couple of forward declarations required, due to cyclic reference loop:
... ... @@ -1639,6 +1641,7 @@
1639 1641 memmove(buf, start, buf + buflen - start);
1640 1642 return 0;
1641 1643 }
  1644 +EXPORT_SYMBOL_GPL(cgroup_path);
1642 1645  
1643 1646 /**
1644 1647 * cgroup_attach_task - attach task 'tsk' to cgroup 'cgrp'
... ... @@ -1805,6 +1808,7 @@
1805 1808 }
1806 1809 return true;
1807 1810 }
  1811 +EXPORT_SYMBOL_GPL(cgroup_lock_live_group);
1808 1812  
1809 1813 static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
1810 1814 const char *buffer)
... ... @@ -4082,6 +4086,7 @@
4082 4086 rcu_read_unlock();
4083 4087 WARN_ON_ONCE(val < 1);
4084 4088 }
  4089 +EXPORT_SYMBOL_GPL(__css_put);
4085 4090  
4086 4091 /*
4087 4092 * Notify userspace when a cgroup is released, by running the
... ... @@ -4197,6 +4202,7 @@
4197 4202 return cssid->id;
4198 4203 return 0;
4199 4204 }
  4205 +EXPORT_SYMBOL_GPL(css_id);
4200 4206  
4201 4207 unsigned short css_depth(struct cgroup_subsys_state *css)
4202 4208 {
... ... @@ -4206,6 +4212,7 @@
4206 4212 return cssid->depth;
4207 4213 return 0;
4208 4214 }
  4215 +EXPORT_SYMBOL_GPL(css_depth);
4209 4216  
4210 4217 bool css_is_ancestor(struct cgroup_subsys_state *child,
4211 4218 const struct cgroup_subsys_state *root)
... ... @@ -4242,6 +4249,7 @@
4242 4249 spin_unlock(&ss->id_lock);
4243 4250 call_rcu(&id->rcu_head, __free_css_id_cb);
4244 4251 }
  4252 +EXPORT_SYMBOL_GPL(free_css_id);
4245 4253  
4246 4254 /*
4247 4255 * This is called by init or create(). Then, calls to this function are
... ... @@ -4358,6 +4366,7 @@
4358 4366  
4359 4367 return rcu_dereference(cssid->css);
4360 4368 }
  4369 +EXPORT_SYMBOL_GPL(css_lookup);
4361 4370  
4362 4371 /**
4363 4372 * css_get_next - lookup next cgroup under specified hierarchy.