Skip to content

Commit de00ffa

Browse files
committed
cgroup: make cgroup_subsys->base_cftypes use cgroup_add_cftypes()
Currently, cgroup_subsys->base_cftypes registration is different from dynamic cftypes registartion. Instead of going through cgroup_add_cftypes(), cgroup_init_subsys() invokes cgroup_init_cftsets() which makes use of cgroup_subsys->base_cftset which doesn't involve dynamic allocation. While avoiding dynamic allocation is somewhat nice, having two separate paths for cftypes registration is nasty, especially as we're planning to add more operations during cftypes registration. This patch drops cgroup_init_cftsets() and cgroup_subsys->base_cftset and registers base_cftypes using cgroup_add_cftypes(). This is done as a separate step in cgroup_init() instead of a part of cgroup_init_subsys(). This is because cgroup_init_subsys() can be called very early during boot when kmalloc() isn't available yet. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
1 parent 8d7e6fb commit de00ffa

2 files changed

Lines changed: 9 additions & 23 deletions

File tree

‎include/linux/cgroup.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,8 @@ struct cgroup_subsys {
604604
/* list of cftype_sets */
605605
struct list_head cftsets;
606606

607-
/* base cftypes, automatically [de]registered with subsys itself */
607+
/* base cftypes, automatically registered with subsys itself */
608608
struct cftype *base_cftypes;
609-
struct cftype_set base_cftset;
610609
};
611610

612611
#define SUBSYS(_x) extern struct cgroup_subsys _x ## _cgrp_subsys;

‎kernel/cgroup.c‎

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4503,25 +4503,6 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
45034503
return ret;
45044504
}
45054505

4506-
static void __init cgroup_init_cftsets(struct cgroup_subsys *ss)
4507-
{
4508-
INIT_LIST_HEAD(&ss->cftsets);
4509-
4510-
/*
4511-
* base_cftset is embedded in subsys itself, no need to worry about
4512-
* deregistration.
4513-
*/
4514-
if (ss->base_cftypes) {
4515-
struct cftype *cft;
4516-
4517-
for (cft = ss->base_cftypes; cft->name[0] != '\0'; cft++)
4518-
cft->ss = ss;
4519-
4520-
ss->base_cftset.cfts = ss->base_cftypes;
4521-
list_add_tail(&ss->base_cftset.node, &ss->cftsets);
4522-
}
4523-
}
4524-
45254506
static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
45264507
{
45274508
struct cgroup_subsys_state *css;
@@ -4531,8 +4512,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
45314512
mutex_lock(&cgroup_tree_mutex);
45324513
mutex_lock(&cgroup_mutex);
45334514

4534-
/* init base cftset */
4535-
cgroup_init_cftsets(ss);
4515+
INIT_LIST_HEAD(&ss->cftsets);
45364516

45374517
/* Create the top cgroup state for this subsystem */
45384518
ss->root = &cgroup_dummy_root;
@@ -4621,6 +4601,13 @@ int __init cgroup_init(void)
46214601
for_each_subsys(ss, i) {
46224602
if (!ss->early_init)
46234603
cgroup_init_subsys(ss);
4604+
4605+
/*
4606+
* cftype registration needs kmalloc and can't be done
4607+
* during early_init. Register base cftypes separately.
4608+
*/
4609+
if (ss->base_cftypes)
4610+
WARN_ON(cgroup_add_cftypes(ss, ss->base_cftypes));
46244611
}
46254612

46264613
/* allocate id for the dummy hierarchy */

0 commit comments

Comments
 (0)