Commit fc5ed1e9 authored by Tejun Heo's avatar Tejun Heo

cgroup: replace cgroup_subsys->disabled tests with cgroup_subsys_enabled()

Replace cgroup_subsys->disabled tests in controllers with
cgroup_subsys_enabled().  cgroup_subsys_enabled() requires literal
subsys name as its parameter and thus can't be used for cgroup core
which iterates through controllers.  For cgroup core, introduce and
use cgroup_ssid_enabled() which uses slower static_key_enabled() test
and can be indexed by subsys ID.

This leaves cgroup_subsys->disabled unused.  Removed.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarZefan Li <lizefan@huawei.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
parent 49d1dc4b
...@@ -419,7 +419,6 @@ struct cgroup_subsys { ...@@ -419,7 +419,6 @@ struct cgroup_subsys {
struct task_struct *task); struct task_struct *task);
void (*bind)(struct cgroup_subsys_state *root_css); void (*bind)(struct cgroup_subsys_state *root_css);
int disabled;
int early_init; int early_init;
/* /*
......
...@@ -48,9 +48,7 @@ int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg) ...@@ -48,9 +48,7 @@ int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
static inline bool hugetlb_cgroup_disabled(void) static inline bool hugetlb_cgroup_disabled(void)
{ {
if (hugetlb_cgrp_subsys.disabled) return !cgroup_subsys_enabled(hugetlb_cgrp_subsys);
return true;
return false;
} }
extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
......
...@@ -347,9 +347,7 @@ ino_t page_cgroup_ino(struct page *page); ...@@ -347,9 +347,7 @@ ino_t page_cgroup_ino(struct page *page);
static inline bool mem_cgroup_disabled(void) static inline bool mem_cgroup_disabled(void)
{ {
if (memory_cgrp_subsys.disabled) return !cgroup_subsys_enabled(memory_cgrp_subsys);
return true;
return false;
} }
/* /*
......
...@@ -224,6 +224,19 @@ static void kill_css(struct cgroup_subsys_state *css); ...@@ -224,6 +224,19 @@ static void kill_css(struct cgroup_subsys_state *css);
static int cgroup_addrm_files(struct cgroup *cgrp, struct cftype cfts[], static int cgroup_addrm_files(struct cgroup *cgrp, struct cftype cfts[],
bool is_add); bool is_add);
/**
* cgroup_ssid_enabled - cgroup subsys enabled test by subsys ID
* @ssid: subsys ID of interest
*
* cgroup_subsys_enabled() can only be used with literal subsys names which
* is fine for individual subsystems but unsuitable for cgroup core. This
* is slower static_key_enabled() based test indexed by @ssid.
*/
static bool cgroup_ssid_enabled(int ssid)
{
return static_key_enabled(cgroup_subsys_enabled_key[ssid]);
}
/* IDR wrappers which synchronize using cgroup_idr_lock */ /* IDR wrappers which synchronize using cgroup_idr_lock */
static int cgroup_idr_alloc(struct idr *idr, void *ptr, int start, int end, static int cgroup_idr_alloc(struct idr *idr, void *ptr, int start, int end,
gfp_t gfp_mask) gfp_t gfp_mask)
...@@ -1482,7 +1495,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) ...@@ -1482,7 +1495,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
for_each_subsys(ss, i) { for_each_subsys(ss, i) {
if (strcmp(token, ss->legacy_name)) if (strcmp(token, ss->legacy_name))
continue; continue;
if (ss->disabled) if (!cgroup_ssid_enabled(i))
continue; continue;
/* Mutually exclusive option 'all' + subsystem name */ /* Mutually exclusive option 'all' + subsystem name */
...@@ -1513,7 +1526,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) ...@@ -1513,7 +1526,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
*/ */
if (all_ss || (!one_ss && !opts->none && !opts->name)) if (all_ss || (!one_ss && !opts->none && !opts->name))
for_each_subsys(ss, i) for_each_subsys(ss, i)
if (!ss->disabled) if (cgroup_ssid_enabled(i))
opts->subsys_mask |= (1 << i); opts->subsys_mask |= (1 << i);
/* /*
...@@ -2762,7 +2775,8 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of, ...@@ -2762,7 +2775,8 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
if (tok[0] == '\0') if (tok[0] == '\0')
continue; continue;
for_each_subsys_which(ss, ssid, &tmp_ss_mask) { for_each_subsys_which(ss, ssid, &tmp_ss_mask) {
if (ss->disabled || strcmp(tok + 1, ss->name)) if (!cgroup_ssid_enabled(ssid) ||
strcmp(tok + 1, ss->name))
continue; continue;
if (*tok == '+') { if (*tok == '+') {
...@@ -3320,7 +3334,7 @@ static int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts) ...@@ -3320,7 +3334,7 @@ static int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
{ {
int ret; int ret;
if (ss->disabled) if (!cgroup_ssid_enabled(ss->id))
return 0; return 0;
if (!cfts || cfts[0].name[0] == '\0') if (!cfts || cfts[0].name[0] == '\0')
...@@ -5082,7 +5096,7 @@ int __init cgroup_init(void) ...@@ -5082,7 +5096,7 @@ int __init cgroup_init(void)
* disabled flag and cftype registration needs kmalloc, * disabled flag and cftype registration needs kmalloc,
* both of which aren't available during early_init. * both of which aren't available during early_init.
*/ */
if (ss->disabled) if (!cgroup_ssid_enabled(ssid))
continue; continue;
cgrp_dfl_root.subsys_mask |= 1 << ss->id; cgrp_dfl_root.subsys_mask |= 1 << ss->id;
...@@ -5217,7 +5231,8 @@ static int proc_cgroupstats_show(struct seq_file *m, void *v) ...@@ -5217,7 +5231,8 @@ static int proc_cgroupstats_show(struct seq_file *m, void *v)
for_each_subsys(ss, i) for_each_subsys(ss, i)
seq_printf(m, "%s\t%d\t%d\t%d\n", seq_printf(m, "%s\t%d\t%d\t%d\n",
ss->legacy_name, ss->root->hierarchy_id, ss->legacy_name, ss->root->hierarchy_id,
atomic_read(&ss->root->nr_cgrps), !ss->disabled); atomic_read(&ss->root->nr_cgrps),
cgroup_ssid_enabled(i));
mutex_unlock(&cgroup_mutex); mutex_unlock(&cgroup_mutex);
return 0; return 0;
...@@ -5508,7 +5523,6 @@ static int __init cgroup_disable(char *str) ...@@ -5508,7 +5523,6 @@ static int __init cgroup_disable(char *str)
continue; continue;
static_branch_disable(cgroup_subsys_enabled_key[i]); static_branch_disable(cgroup_subsys_enabled_key[i]);
ss->disabled = 1;
printk(KERN_INFO "Disabling %s control group subsystem\n", printk(KERN_INFO "Disabling %s control group subsystem\n",
ss->name); ss->name);
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment