cgroup: make per-cgroup pressure stall tracking configurable

PSI accounts stalls for each cgroup separately and aggregates it at each
level of the hierarchy. This causes additional overhead with psi_avgs_work
being called for each cgroup in the hierarchy. psi_avgs_work has been
highly optimized, however on systems with large number of cgroups the
overhead becomes noticeable.
Systems which use PSI only at the system level could avoid this overhead
if PSI can be configured to skip per-cgroup stall accounting.
Add "cgroup_disable=pressure" kernel command-line option to allow
requesting system-wide only pressure stall accounting. When set, it
keeps system-wide accounting under /proc/pressure/ but skips accounting
for individual cgroups and does not expose PSI nodes in cgroup hierarchy.

Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
Suren Baghdasaryan 2021-05-24 12:53:39 -07:00 committed by Tejun Heo
parent 2ca11b0e04
commit 3958e2d0c3
5 changed files with 80 additions and 15 deletions

View File

@ -497,16 +497,21 @@
ccw_timeout_log [S390] ccw_timeout_log [S390]
See Documentation/s390/common_io.rst for details. See Documentation/s390/common_io.rst for details.
cgroup_disable= [KNL] Disable a particular controller cgroup_disable= [KNL] Disable a particular controller or optional feature
Format: {name of the controller(s) to disable} Format: {name of the controller(s) or feature(s) to disable}
The effects of cgroup_disable=foo are: The effects of cgroup_disable=foo are:
- foo isn't auto-mounted if you mount all cgroups in - foo isn't auto-mounted if you mount all cgroups in
a single hierarchy a single hierarchy
- foo isn't visible as an individually mountable - foo isn't visible as an individually mountable
subsystem subsystem
- if foo is an optional feature then the feature is
disabled and corresponding cgroup files are not
created
{Currently only "memory" controller deal with this and {Currently only "memory" controller deal with this and
cut the overhead, others just disable the usage. So cut the overhead, others just disable the usage. So
only cgroup_disable=memory is actually worthy} only cgroup_disable=memory is actually worthy}
Specifying "pressure" disables per-cgroup pressure
stall information accounting feature
cgroup_no_v1= [KNL] Disable cgroup controllers and named hierarchies in v1 cgroup_no_v1= [KNL] Disable cgroup controllers and named hierarchies in v1
Format: { { controller | "all" | "named" } Format: { { controller | "all" | "named" }

View File

@ -113,6 +113,7 @@ enum {
CFTYPE_NO_PREFIX = (1 << 3), /* (DON'T USE FOR NEW FILES) no subsys prefix */ CFTYPE_NO_PREFIX = (1 << 3), /* (DON'T USE FOR NEW FILES) no subsys prefix */
CFTYPE_WORLD_WRITABLE = (1 << 4), /* (DON'T USE FOR NEW FILES) S_IWUGO */ CFTYPE_WORLD_WRITABLE = (1 << 4), /* (DON'T USE FOR NEW FILES) S_IWUGO */
CFTYPE_DEBUG = (1 << 5), /* create when cgroup_debug */ CFTYPE_DEBUG = (1 << 5), /* create when cgroup_debug */
CFTYPE_PRESSURE = (1 << 6), /* only if pressure feature is enabled */
/* internal flags, do not use outside cgroup core proper */ /* internal flags, do not use outside cgroup core proper */
__CFTYPE_ONLY_ON_DFL = (1 << 16), /* only on default hierarchy */ __CFTYPE_ONLY_ON_DFL = (1 << 16), /* only on default hierarchy */

View File

@ -676,6 +676,8 @@ static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)
return &cgrp->psi; return &cgrp->psi;
} }
bool cgroup_psi_enabled(void);
static inline void cgroup_init_kthreadd(void) static inline void cgroup_init_kthreadd(void)
{ {
/* /*
@ -735,6 +737,11 @@ static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)
return NULL; return NULL;
} }
static inline bool cgroup_psi_enabled(void)
{
return false;
}
static inline bool task_under_cgroup_hierarchy(struct task_struct *task, static inline bool task_under_cgroup_hierarchy(struct task_struct *task,
struct cgroup *ancestor) struct cgroup *ancestor)
{ {

View File

@ -209,6 +209,22 @@ struct cgroup_namespace init_cgroup_ns = {
static struct file_system_type cgroup2_fs_type; static struct file_system_type cgroup2_fs_type;
static struct cftype cgroup_base_files[]; static struct cftype cgroup_base_files[];
/* cgroup optional features */
enum cgroup_opt_features {
#ifdef CONFIG_PSI
OPT_FEATURE_PRESSURE,
#endif
OPT_FEATURE_COUNT
};
static const char *cgroup_opt_feature_names[OPT_FEATURE_COUNT] = {
#ifdef CONFIG_PSI
"pressure",
#endif
};
static u16 cgroup_feature_disable_mask __read_mostly;
static int cgroup_apply_control(struct cgroup *cgrp); static int cgroup_apply_control(struct cgroup *cgrp);
static void cgroup_finalize_control(struct cgroup *cgrp, int ret); static void cgroup_finalize_control(struct cgroup *cgrp, int ret);
static void css_task_iter_skip(struct css_task_iter *it, static void css_task_iter_skip(struct css_task_iter *it,
@ -3631,6 +3647,18 @@ static void cgroup_pressure_release(struct kernfs_open_file *of)
{ {
psi_trigger_replace(&of->priv, NULL); psi_trigger_replace(&of->priv, NULL);
} }
bool cgroup_psi_enabled(void)
{
return (cgroup_feature_disable_mask & (1 << OPT_FEATURE_PRESSURE)) == 0;
}
#else /* CONFIG_PSI */
bool cgroup_psi_enabled(void)
{
return false;
}
#endif /* CONFIG_PSI */ #endif /* CONFIG_PSI */
static int cgroup_freeze_show(struct seq_file *seq, void *v) static int cgroup_freeze_show(struct seq_file *seq, void *v)
@ -3955,6 +3983,8 @@ static int cgroup_addrm_files(struct cgroup_subsys_state *css,
restart: restart:
for (cft = cfts; cft != cft_end && cft->name[0] != '\0'; cft++) { for (cft = cfts; cft != cft_end && cft->name[0] != '\0'; cft++) {
/* does cft->flags tell us to skip this file on @cgrp? */ /* does cft->flags tell us to skip this file on @cgrp? */
if ((cft->flags & CFTYPE_PRESSURE) && !cgroup_psi_enabled())
continue;
if ((cft->flags & __CFTYPE_ONLY_ON_DFL) && !cgroup_on_dfl(cgrp)) if ((cft->flags & __CFTYPE_ONLY_ON_DFL) && !cgroup_on_dfl(cgrp))
continue; continue;
if ((cft->flags & __CFTYPE_NOT_ON_DFL) && cgroup_on_dfl(cgrp)) if ((cft->flags & __CFTYPE_NOT_ON_DFL) && cgroup_on_dfl(cgrp))
@ -4032,6 +4062,9 @@ static int cgroup_init_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
WARN_ON(cft->ss || cft->kf_ops); WARN_ON(cft->ss || cft->kf_ops);
if ((cft->flags & CFTYPE_PRESSURE) && !cgroup_psi_enabled())
continue;
if (cft->seq_start) if (cft->seq_start)
kf_ops = &cgroup_kf_ops; kf_ops = &cgroup_kf_ops;
else else
@ -4945,6 +4978,7 @@ static struct cftype cgroup_base_files[] = {
#ifdef CONFIG_PSI #ifdef CONFIG_PSI
{ {
.name = "io.pressure", .name = "io.pressure",
.flags = CFTYPE_PRESSURE,
.seq_show = cgroup_io_pressure_show, .seq_show = cgroup_io_pressure_show,
.write = cgroup_io_pressure_write, .write = cgroup_io_pressure_write,
.poll = cgroup_pressure_poll, .poll = cgroup_pressure_poll,
@ -4952,6 +4986,7 @@ static struct cftype cgroup_base_files[] = {
}, },
{ {
.name = "memory.pressure", .name = "memory.pressure",
.flags = CFTYPE_PRESSURE,
.seq_show = cgroup_memory_pressure_show, .seq_show = cgroup_memory_pressure_show,
.write = cgroup_memory_pressure_write, .write = cgroup_memory_pressure_write,
.poll = cgroup_pressure_poll, .poll = cgroup_pressure_poll,
@ -4959,6 +4994,7 @@ static struct cftype cgroup_base_files[] = {
}, },
{ {
.name = "cpu.pressure", .name = "cpu.pressure",
.flags = CFTYPE_PRESSURE,
.seq_show = cgroup_cpu_pressure_show, .seq_show = cgroup_cpu_pressure_show,
.write = cgroup_cpu_pressure_write, .write = cgroup_cpu_pressure_write,
.poll = cgroup_pressure_poll, .poll = cgroup_pressure_poll,
@ -6313,6 +6349,15 @@ static int __init cgroup_disable(char *str)
pr_info("Disabling %s control group subsystem\n", pr_info("Disabling %s control group subsystem\n",
ss->name); ss->name);
} }
for (i = 0; i < OPT_FEATURE_COUNT; i++) {
if (strcmp(token, cgroup_opt_feature_names[i]))
continue;
cgroup_feature_disable_mask |= 1 << i;
pr_info("Disabling %s control group feature\n",
cgroup_opt_feature_names[i]);
break;
}
} }
return 1; return 1;
} }
@ -6611,6 +6656,9 @@ static ssize_t show_delegatable_files(struct cftype *files, char *buf,
if (!(cft->flags & CFTYPE_NS_DELEGATABLE)) if (!(cft->flags & CFTYPE_NS_DELEGATABLE))
continue; continue;
if ((cft->flags & CFTYPE_PRESSURE) && !cgroup_psi_enabled())
continue;
if (prefix) if (prefix)
ret += snprintf(buf + ret, size - ret, "%s.", prefix); ret += snprintf(buf + ret, size - ret, "%s.", prefix);

View File

@ -148,6 +148,7 @@
static int psi_bug __read_mostly; static int psi_bug __read_mostly;
DEFINE_STATIC_KEY_FALSE(psi_disabled); DEFINE_STATIC_KEY_FALSE(psi_disabled);
DEFINE_STATIC_KEY_TRUE(psi_cgroups_enabled);
#ifdef CONFIG_PSI_DEFAULT_DISABLED #ifdef CONFIG_PSI_DEFAULT_DISABLED
static bool psi_enable; static bool psi_enable;
@ -211,6 +212,9 @@ void __init psi_init(void)
return; return;
} }
if (!cgroup_psi_enabled())
static_branch_disable(&psi_cgroups_enabled);
psi_period = jiffies_to_nsecs(PSI_FREQ); psi_period = jiffies_to_nsecs(PSI_FREQ);
group_init(&psi_system); group_init(&psi_system);
} }
@ -744,23 +748,23 @@ static void psi_group_change(struct psi_group *group, int cpu,
static struct psi_group *iterate_groups(struct task_struct *task, void **iter) static struct psi_group *iterate_groups(struct task_struct *task, void **iter)
{ {
if (*iter == &psi_system)
return NULL;
#ifdef CONFIG_CGROUPS #ifdef CONFIG_CGROUPS
struct cgroup *cgroup = NULL; if (static_branch_likely(&psi_cgroups_enabled)) {
struct cgroup *cgroup = NULL;
if (!*iter) if (!*iter)
cgroup = task->cgroups->dfl_cgrp; cgroup = task->cgroups->dfl_cgrp;
else if (*iter == &psi_system) else
return NULL; cgroup = cgroup_parent(*iter);
else
cgroup = cgroup_parent(*iter);
if (cgroup && cgroup_parent(cgroup)) { if (cgroup && cgroup_parent(cgroup)) {
*iter = cgroup; *iter = cgroup;
return cgroup_psi(cgroup); return cgroup_psi(cgroup);
}
} }
#else
if (*iter)
return NULL;
#endif #endif
*iter = &psi_system; *iter = &psi_system;
return &psi_system; return &psi_system;