提交 67523c48 编写于 作者: B Ben Blum 提交者: Linus Torvalds

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: NBen 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: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 8ca712ea
...@@ -78,7 +78,7 @@ config BLK_DEV_INTEGRITY ...@@ -78,7 +78,7 @@ config BLK_DEV_INTEGRITY
Protection. If in doubt, say N. Protection. If in doubt, say N.
config BLK_CGROUP config BLK_CGROUP
bool tristate
depends on CGROUPS depends on CGROUPS
default n default n
---help--- ---help---
......
...@@ -23,6 +23,7 @@ config IOSCHED_DEADLINE ...@@ -23,6 +23,7 @@ config IOSCHED_DEADLINE
config IOSCHED_CFQ config IOSCHED_CFQ
tristate "CFQ I/O scheduler" tristate "CFQ I/O scheduler"
select BLK_CGROUP if CFQ_GROUP_IOSCHED
default y default y
---help--- ---help---
The CFQ I/O scheduler tries to distribute bandwidth equally The CFQ I/O scheduler tries to distribute bandwidth equally
...@@ -35,7 +36,6 @@ config IOSCHED_CFQ ...@@ -35,7 +36,6 @@ config IOSCHED_CFQ
config CFQ_GROUP_IOSCHED config CFQ_GROUP_IOSCHED
bool "CFQ Group Scheduling support" bool "CFQ Group Scheduling support"
depends on IOSCHED_CFQ && CGROUPS depends on IOSCHED_CFQ && CGROUPS
select BLK_CGROUP
default n default n
---help--- ---help---
Enable group IO scheduling in CFQ. Enable group IO scheduling in CFQ.
......
...@@ -23,6 +23,31 @@ static LIST_HEAD(blkio_list); ...@@ -23,6 +23,31 @@ static LIST_HEAD(blkio_list);
struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT }; struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
EXPORT_SYMBOL_GPL(blkio_root_cgroup); EXPORT_SYMBOL_GPL(blkio_root_cgroup);
static struct cgroup_subsys_state *blkiocg_create(struct cgroup_subsys *,
struct cgroup *);
static int blkiocg_can_attach(struct cgroup_subsys *, struct cgroup *,
struct task_struct *, bool);
static void blkiocg_attach(struct cgroup_subsys *, struct cgroup *,
struct cgroup *, struct task_struct *, bool);
static void blkiocg_destroy(struct cgroup_subsys *, struct cgroup *);
static int blkiocg_populate(struct cgroup_subsys *, struct cgroup *);
struct cgroup_subsys blkio_subsys = {
.name = "blkio",
.create = blkiocg_create,
.can_attach = blkiocg_can_attach,
.attach = blkiocg_attach,
.destroy = blkiocg_destroy,
.populate = blkiocg_populate,
#ifdef CONFIG_BLK_CGROUP
/* note: blkio_subsys_id is otherwise defined in blk-cgroup.h */
.subsys_id = blkio_subsys_id,
#endif
.use_id = 1,
.module = THIS_MODULE,
};
EXPORT_SYMBOL_GPL(blkio_subsys);
struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup) struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)
{ {
return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id), return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id),
...@@ -253,6 +278,7 @@ remove_entry: ...@@ -253,6 +278,7 @@ remove_entry:
done: done:
free_css_id(&blkio_subsys, &blkcg->css); free_css_id(&blkio_subsys, &blkcg->css);
rcu_read_unlock(); rcu_read_unlock();
if (blkcg != &blkio_root_cgroup)
kfree(blkcg); kfree(blkcg);
} }
...@@ -319,17 +345,6 @@ static void blkiocg_attach(struct cgroup_subsys *subsys, struct cgroup *cgroup, ...@@ -319,17 +345,6 @@ static void blkiocg_attach(struct cgroup_subsys *subsys, struct cgroup *cgroup,
task_unlock(tsk); task_unlock(tsk);
} }
struct cgroup_subsys blkio_subsys = {
.name = "blkio",
.create = blkiocg_create,
.can_attach = blkiocg_can_attach,
.attach = blkiocg_attach,
.destroy = blkiocg_destroy,
.populate = blkiocg_populate,
.subsys_id = blkio_subsys_id,
.use_id = 1,
};
void blkio_policy_register(struct blkio_policy_type *blkiop) void blkio_policy_register(struct blkio_policy_type *blkiop)
{ {
spin_lock(&blkio_list_lock); spin_lock(&blkio_list_lock);
...@@ -345,3 +360,17 @@ void blkio_policy_unregister(struct blkio_policy_type *blkiop) ...@@ -345,3 +360,17 @@ void blkio_policy_unregister(struct blkio_policy_type *blkiop)
spin_unlock(&blkio_list_lock); spin_unlock(&blkio_list_lock);
} }
EXPORT_SYMBOL_GPL(blkio_policy_unregister); EXPORT_SYMBOL_GPL(blkio_policy_unregister);
static int __init init_cgroup_blkio(void)
{
return cgroup_load_subsys(&blkio_subsys);
}
static void __exit exit_cgroup_blkio(void)
{
cgroup_unload_subsys(&blkio_subsys);
}
module_init(init_cgroup_blkio);
module_exit(exit_cgroup_blkio);
MODULE_LICENSE("GPL");
...@@ -15,7 +15,13 @@ ...@@ -15,7 +15,13 @@
#include <linux/cgroup.h> #include <linux/cgroup.h>
#ifdef CONFIG_BLK_CGROUP #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
#ifndef CONFIG_BLK_CGROUP
/* When blk-cgroup is a module, its subsys_id isn't a compile-time constant */
extern struct cgroup_subsys blkio_subsys;
#define blkio_subsys_id blkio_subsys.subsys_id
#endif
struct blkio_cgroup { struct blkio_cgroup {
struct cgroup_subsys_state css; struct cgroup_subsys_state css;
...@@ -91,7 +97,7 @@ static inline void blkiocg_update_blkio_group_dequeue_stats( ...@@ -91,7 +97,7 @@ static inline void blkiocg_update_blkio_group_dequeue_stats(
struct blkio_group *blkg, unsigned long dequeue) {} struct blkio_group *blkg, unsigned long dequeue) {}
#endif #endif
#ifdef CONFIG_BLK_CGROUP #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
extern struct blkio_cgroup blkio_root_cgroup; extern struct blkio_cgroup blkio_root_cgroup;
extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup); extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
......
...@@ -42,7 +42,7 @@ struct io_context { ...@@ -42,7 +42,7 @@ struct io_context {
unsigned short ioprio; unsigned short ioprio;
unsigned short ioprio_changed; unsigned short ioprio_changed;
#ifdef CONFIG_BLK_CGROUP #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
unsigned short cgroup_changed; unsigned short cgroup_changed;
#endif #endif
......
...@@ -705,6 +705,7 @@ void cgroup_lock(void) ...@@ -705,6 +705,7 @@ void cgroup_lock(void)
{ {
mutex_lock(&cgroup_mutex); mutex_lock(&cgroup_mutex);
} }
EXPORT_SYMBOL_GPL(cgroup_lock);
/** /**
* cgroup_unlock - release lock on cgroup changes * cgroup_unlock - release lock on cgroup changes
...@@ -715,6 +716,7 @@ void cgroup_unlock(void) ...@@ -715,6 +716,7 @@ void cgroup_unlock(void)
{ {
mutex_unlock(&cgroup_mutex); mutex_unlock(&cgroup_mutex);
} }
EXPORT_SYMBOL_GPL(cgroup_unlock);
/* /*
* A couple of forward declarations required, due to cyclic reference loop: * A couple of forward declarations required, due to cyclic reference loop:
...@@ -1639,6 +1641,7 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) ...@@ -1639,6 +1641,7 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
memmove(buf, start, buf + buflen - start); memmove(buf, start, buf + buflen - start);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(cgroup_path);
/** /**
* cgroup_attach_task - attach task 'tsk' to cgroup 'cgrp' * cgroup_attach_task - attach task 'tsk' to cgroup 'cgrp'
...@@ -1805,6 +1808,7 @@ bool cgroup_lock_live_group(struct cgroup *cgrp) ...@@ -1805,6 +1808,7 @@ bool cgroup_lock_live_group(struct cgroup *cgrp)
} }
return true; return true;
} }
EXPORT_SYMBOL_GPL(cgroup_lock_live_group);
static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
const char *buffer) const char *buffer)
...@@ -4082,6 +4086,7 @@ void __css_put(struct cgroup_subsys_state *css, int count) ...@@ -4082,6 +4086,7 @@ void __css_put(struct cgroup_subsys_state *css, int count)
rcu_read_unlock(); rcu_read_unlock();
WARN_ON_ONCE(val < 1); WARN_ON_ONCE(val < 1);
} }
EXPORT_SYMBOL_GPL(__css_put);
/* /*
* Notify userspace when a cgroup is released, by running the * Notify userspace when a cgroup is released, by running the
...@@ -4197,6 +4202,7 @@ unsigned short css_id(struct cgroup_subsys_state *css) ...@@ -4197,6 +4202,7 @@ unsigned short css_id(struct cgroup_subsys_state *css)
return cssid->id; return cssid->id;
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(css_id);
unsigned short css_depth(struct cgroup_subsys_state *css) unsigned short css_depth(struct cgroup_subsys_state *css)
{ {
...@@ -4206,6 +4212,7 @@ unsigned short css_depth(struct cgroup_subsys_state *css) ...@@ -4206,6 +4212,7 @@ unsigned short css_depth(struct cgroup_subsys_state *css)
return cssid->depth; return cssid->depth;
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(css_depth);
bool css_is_ancestor(struct cgroup_subsys_state *child, bool css_is_ancestor(struct cgroup_subsys_state *child,
const struct cgroup_subsys_state *root) const struct cgroup_subsys_state *root)
...@@ -4242,6 +4249,7 @@ void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css) ...@@ -4242,6 +4249,7 @@ void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css)
spin_unlock(&ss->id_lock); spin_unlock(&ss->id_lock);
call_rcu(&id->rcu_head, __free_css_id_cb); call_rcu(&id->rcu_head, __free_css_id_cb);
} }
EXPORT_SYMBOL_GPL(free_css_id);
/* /*
* This is called by init or create(). Then, calls to this function are * This is called by init or create(). Then, calls to this function are
...@@ -4358,6 +4366,7 @@ struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id) ...@@ -4358,6 +4366,7 @@ struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id)
return rcu_dereference(cssid->css); return rcu_dereference(cssid->css);
} }
EXPORT_SYMBOL_GPL(css_lookup);
/** /**
* css_get_next - lookup next cgroup under specified hierarchy. * css_get_next - lookup next cgroup under specified hierarchy.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册