Skip to content

Commit 8a693f7

Browse files
committed
cgroup: Remove CFTYPE_PRESSURE
CFTYPE_PRESSURE is used to flag PSI related files so that they are not created if PSI is disabled during boot. It's a bit weird to use a generic flag to mark a specific file type. Let's instead move the PSI files into its own cftypes array and add/rm them conditionally. This is a bit more code but cleaner. No userland visible changes. Signed-off-by: Tejun Heo <[email protected]> Cc: Johannes Weiner <[email protected]>
1 parent 0083d27 commit 8a693f7

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

include/linux/cgroup-defs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ enum {
126126
CFTYPE_NO_PREFIX = (1 << 3), /* (DON'T USE FOR NEW FILES) no subsys prefix */
127127
CFTYPE_WORLD_WRITABLE = (1 << 4), /* (DON'T USE FOR NEW FILES) S_IWUGO */
128128
CFTYPE_DEBUG = (1 << 5), /* create when cgroup_debug */
129-
CFTYPE_PRESSURE = (1 << 6), /* only if pressure feature is enabled */
130129

131130
/* internal flags, do not use outside cgroup core proper */
132131
__CFTYPE_ONLY_ON_DFL = (1 << 16), /* only on default hierarchy */

kernel/cgroup/cgroup.c

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ struct cgroup_namespace init_cgroup_ns = {
217217

218218
static struct file_system_type cgroup2_fs_type;
219219
static struct cftype cgroup_base_files[];
220+
static struct cftype cgroup_psi_files[];
220221

221222
/* cgroup optional features */
222223
enum cgroup_opt_features {
@@ -1689,12 +1690,16 @@ static void css_clear_dir(struct cgroup_subsys_state *css)
16891690
css->flags &= ~CSS_VISIBLE;
16901691

16911692
if (!css->ss) {
1692-
if (cgroup_on_dfl(cgrp))
1693-
cfts = cgroup_base_files;
1694-
else
1695-
cfts = cgroup1_base_files;
1696-
1697-
cgroup_addrm_files(css, cgrp, cfts, false);
1693+
if (cgroup_on_dfl(cgrp)) {
1694+
cgroup_addrm_files(css, cgrp,
1695+
cgroup_base_files, false);
1696+
if (cgroup_psi_enabled())
1697+
cgroup_addrm_files(css, cgrp,
1698+
cgroup_psi_files, false);
1699+
} else {
1700+
cgroup_addrm_files(css, cgrp,
1701+
cgroup1_base_files, false);
1702+
}
16981703
} else {
16991704
list_for_each_entry(cfts, &css->ss->cfts, node)
17001705
cgroup_addrm_files(css, cgrp, cfts, false);
@@ -1717,14 +1722,22 @@ static int css_populate_dir(struct cgroup_subsys_state *css)
17171722
return 0;
17181723

17191724
if (!css->ss) {
1720-
if (cgroup_on_dfl(cgrp))
1721-
cfts = cgroup_base_files;
1722-
else
1723-
cfts = cgroup1_base_files;
1724-
1725-
ret = cgroup_addrm_files(&cgrp->self, cgrp, cfts, true);
1726-
if (ret < 0)
1727-
return ret;
1725+
if (cgroup_on_dfl(cgrp)) {
1726+
ret = cgroup_addrm_files(&cgrp->self, cgrp,
1727+
cgroup_base_files, true);
1728+
if (ret < 0)
1729+
return ret;
1730+
1731+
if (cgroup_psi_enabled()) {
1732+
ret = cgroup_addrm_files(&cgrp->self, cgrp,
1733+
cgroup_psi_files, true);
1734+
if (ret < 0)
1735+
return ret;
1736+
}
1737+
} else {
1738+
cgroup_addrm_files(css, cgrp,
1739+
cgroup1_base_files, true);
1740+
}
17281741
} else {
17291742
list_for_each_entry(cfts, &css->ss->cfts, node) {
17301743
ret = cgroup_addrm_files(css, cgrp, cfts, true);
@@ -4132,8 +4145,6 @@ static int cgroup_addrm_files(struct cgroup_subsys_state *css,
41324145
restart:
41334146
for (cft = cfts; cft != cft_end && cft->name[0] != '\0'; cft++) {
41344147
/* does cft->flags tell us to skip this file on @cgrp? */
4135-
if ((cft->flags & CFTYPE_PRESSURE) && !cgroup_psi_enabled())
4136-
continue;
41374148
if ((cft->flags & __CFTYPE_ONLY_ON_DFL) && !cgroup_on_dfl(cgrp))
41384149
continue;
41394150
if ((cft->flags & __CFTYPE_NOT_ON_DFL) && cgroup_on_dfl(cgrp))
@@ -4218,9 +4229,6 @@ static int cgroup_init_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
42184229
break;
42194230
}
42204231

4221-
if ((cft->flags & CFTYPE_PRESSURE) && !cgroup_psi_enabled())
4222-
continue;
4223-
42244232
if (cft->seq_start)
42254233
kf_ops = &cgroup_kf_ops;
42264234
else
@@ -5144,26 +5152,27 @@ static struct cftype cgroup_base_files[] = {
51445152
.name = "cpu.stat",
51455153
.seq_show = cpu_stat_show,
51465154
},
5155+
{ } /* terminate */
5156+
};
5157+
5158+
static struct cftype cgroup_psi_files[] = {
51475159
#ifdef CONFIG_PSI
51485160
{
51495161
.name = "io.pressure",
5150-
.flags = CFTYPE_PRESSURE,
51515162
.seq_show = cgroup_io_pressure_show,
51525163
.write = cgroup_io_pressure_write,
51535164
.poll = cgroup_pressure_poll,
51545165
.release = cgroup_pressure_release,
51555166
},
51565167
{
51575168
.name = "memory.pressure",
5158-
.flags = CFTYPE_PRESSURE,
51595169
.seq_show = cgroup_memory_pressure_show,
51605170
.write = cgroup_memory_pressure_write,
51615171
.poll = cgroup_pressure_poll,
51625172
.release = cgroup_pressure_release,
51635173
},
51645174
{
51655175
.name = "cpu.pressure",
5166-
.flags = CFTYPE_PRESSURE,
51675176
.seq_show = cgroup_cpu_pressure_show,
51685177
.write = cgroup_cpu_pressure_write,
51695178
.poll = cgroup_pressure_poll,
@@ -5930,6 +5939,7 @@ int __init cgroup_init(void)
59305939

59315940
BUILD_BUG_ON(CGROUP_SUBSYS_COUNT > 16);
59325941
BUG_ON(cgroup_init_cftypes(NULL, cgroup_base_files));
5942+
BUG_ON(cgroup_init_cftypes(NULL, cgroup_psi_files));
59335943
BUG_ON(cgroup_init_cftypes(NULL, cgroup1_base_files));
59345944

59355945
cgroup_rstat_boot();
@@ -6821,9 +6831,6 @@ static ssize_t show_delegatable_files(struct cftype *files, char *buf,
68216831
if (!(cft->flags & CFTYPE_NS_DELEGATABLE))
68226832
continue;
68236833

6824-
if ((cft->flags & CFTYPE_PRESSURE) && !cgroup_psi_enabled())
6825-
continue;
6826-
68276834
if (prefix)
68286835
ret += snprintf(buf + ret, size - ret, "%s.", prefix);
68296836

@@ -6843,8 +6850,11 @@ static ssize_t delegate_show(struct kobject *kobj, struct kobj_attribute *attr,
68436850
int ssid;
68446851
ssize_t ret = 0;
68456852

6846-
ret = show_delegatable_files(cgroup_base_files, buf, PAGE_SIZE - ret,
6847-
NULL);
6853+
ret = show_delegatable_files(cgroup_base_files, buf + ret,
6854+
PAGE_SIZE - ret, NULL);
6855+
if (cgroup_psi_enabled())
6856+
ret += show_delegatable_files(cgroup_psi_files, buf + ret,
6857+
PAGE_SIZE - ret, NULL);
68486858

68496859
for_each_subsys(ss, ssid)
68506860
ret += show_delegatable_files(ss->dfl_cftypes, buf + ret,

0 commit comments

Comments
 (0)