cgroup: make per-cgroup pressure stall tracking configurable
Subsystems (4)
Suren Baghdasaryan
maintainerPATCH v2 1/1 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.
---
changes in v2:
- Added psi_cgroups_disabled static key, per PeterZ
- Refactored iterate_groups, per Johannes
.../admin-guide/kernel-parameters.txt | 9 +++- include/linux/cgroup-defs.h | 1 + include/linux/cgroup.h | 7 +++ kernel/cgroup/cgroup.c | 46 +++++++++++++++++++ kernel/sched/psi.c | 30 ++++++------ 5 files changed, 78 insertions(+), 15 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +7 -2
@@ -497,16 +497,21 @@ ccw_timeout_log [S390] See Documentation/s390/common_io.rst for details. - cgroup_disable= [KNL] Disable a particular controller - Format: {name of the controller(s) to disable} + cgroup_disable= [KNL] Disable a particular controller or optional feature + Format: {name of the controller(s) or feature(s) to disable} The effects of cgroup_disable=foo are: - foo isn't auto-mounted if you mount all cgroups in a single hierarchy - foo isn't visible as an individually mountable 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 cut the overhead, others just disable the usage. So 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 Format: { { controller | "all" | "named" }
include/linux/cgroup-defs.h +1 -0
@@ -110,6 +110,7 @@ enum {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_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 */ __CFTYPE_ONLY_ON_DFL = (1 << 16), /* only on default hierarchy */
include/linux/cgroup.h +7 -0
@@ -676,6 +676,8 @@ static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)return &cgrp->psi; } +bool cgroup_psi_enabled (void ); +static inline void cgroup_init_kthreadd (void ) {/*
@@ -735,6 +737,11 @@ static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)return NULL ; } +static inline bool cgroup_psi_enabled (void ) +{ +return false; +} +static inline bool task_under_cgroup_hierarchy (struct task_struct *task,struct cgroup *ancestor) {
kernel/cgroup/cgroup.c +46 -0
100 lines not on this page · raw message
kernel/sched/psi.c +17 -13
@@ -148,6 +148,7 @@static int psi_bug__read_mostly ;DEFINE_STATIC_KEY_FALSE (psi_disabled); +DEFINE_STATIC_KEY_FALSE (psi_cgroups_disabled);#ifdef CONFIG_PSI_DEFAULT_DISABLED static bool psi_enable;
@@ -211,6 +212,9 @@ void __init psi_init(void)return ; } +if (!cgroup_psi_enabled ()) +static_branch_enable (&psi_cgroups_disabled); + psi_period =jiffies_to_nsecs (PSI_FREQ );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) { +if (*iter == &psi_system) +return NULL ; +#ifdef CONFIG_CGROUPS -struct cgroup *cgroup =NULL ; +if (!static_branch_likely (&psi_cgroups_disabled)) { +struct cgroup *cgroup =NULL ; -if (!*iter) - cgroup = task->cgroups->dfl_cgrp; -else if (*iter == &psi_system) -return NULL ; -else - cgroup =cgroup_parent (*iter); +if (!*iter) + cgroup = task->cgroups->dfl_cgrp; +else + cgroup =cgroup_parent (*iter); -if (cgroup &&cgroup_parent (cgroup)) { - *iter = cgroup; -return cgroup_psi (cgroup); +if (cgroup &&cgroup_parent (cgroup)) { + *iter = cgroup; +return cgroup_psi (cgroup); + } } -#else -if (*iter) -return NULL ;#endif *iter = &psi_system;return &psi_system;
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Quoted 13 lines · Suren Baghdasaryan
PSI accounts stalls for each cgroup separately and aggregates it at each level of the hierarchy. This causes additional overhead with
psi_avgs_workbeing called for each cgroup in the hierarchy.psi_avgs_workhas 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.
Quoted 1 line
Signed-off-by Suren Baghdasaryan <[email protected]>
I am assuming that this is for Android and at the moment Android is only interested in system level pressure. I am wondering if there is any plan for Android to have cgroup hierarchies with explicit limits in future?
If yes, then I think we should follow up (this patch is fine independently) with making this feature more general by explicitly enabling psi for each cgroup level similar to how we enable controllers through cgroup.subtree_control.
Something like:
$ echo "+psi" > cgroup.subtree_control
This definitely would be helpful for server use cases where jobs do sub-containers but might not be interested in psi but the admin is interested in the top level job's psi.
Suren Baghdasaryan
maintainerQuoted 15 lines · Shakeel Butt
Quoted 13 lines · Suren Baghdasaryan
PSI accounts stalls for each cgroup separately and aggregates it at each level of the hierarchy. This causes additional overhead with
psi_avgs_workbeing called for each cgroup in the hierarchy.psi_avgs_workhas 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.
Quoted 6 lines
Quoted 1 line
Signed-off-by Suren Baghdasaryan <[email protected]>I am assuming that this is for Android and at the moment Android is only interested in system level pressure. I am wondering if there is any plan for Android to have cgroup hierarchies with explicit limits in future?
Correct and yes, we would like to use memcgs to limit memory in the future, however we do not plan on using per-cgroup psi so far.
Quoted 6 lines
If yes, then I think we should follow up (this patch is fine independently) with making this feature more general by explicitly enabling psi for each cgroup level similar to how we enable controllers through cgroup.subtree_control.
Quoted 7 lines
Something like:
$ echo "+psi" > cgroup.subtree_controlThis definitely would be helpful for server use cases where jobs do sub-containers but might not be interested in psi but the admin is interested in the top level job's psi.
Haven't thought about it before but that makes sense to me.
Peter Zijlstra
maintainerkernel/sched/psi.c line 151
Quoted 9 lines · Suren Baghdasaryan
kernel/sched/psi.c +1
-0@@ -148,6 +148,7 @@static int psi_bug__read_mostly ;DEFINE_STATIC_KEY_FALSE (psi_disabled); +DEFINE_STATIC_KEY_FALSE (psi_cgroups_disabled);
I'm thinking the whole thing will be easier/clearer when you make this:
DEFINE_STATIC_KEY_TRUE(psi_cgroups_enabled);
kernel/sched/psi.c void __init psi_init(void) · line 216
Quoted 9 lines
kernel/sched/psi.c +2
-0#ifdef CONFIG_PSI_DEFAULT_DISABLED static bool psi_enable;@@ -211,6 +212,9 @@ void __init psi_init(void)return ; } +if (!cgroup_psi_enabled ()) +static_branch_enable (&psi_cgroups_disabled);
if (!cgroup_psi_enabled()) static_branch_disable(&psi_cgroups_enabled);
kernel/sched/psi.c static void psi_group_change(struct psi_group *group, int cpu, · line 755
Quoted 13 lines
kernel/sched/psi.c +5
-0+ psi_period =jiffies_to_nsecs (PSI_FREQ );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) { +if (*iter == &psi_system) +return NULL ; +#ifdef CONFIG_CGROUPS +if (!static_branch_likely (&psi_cgroups_disabled)) {
if (static_branch_likely(&psi_cgroups_enabled)) {Quoted 5 lines
kernel/sched/psi.c +4
-0+struct cgroup *cgroup =NULL ; +if (!*iter) + cgroup = task->cgroups->dfl_cgrp; +else
kernel/sched/psi.c static void psi_group_change(struct psi_group *group, int cpu, · line 770
Quoted 10 lines
kernel/sched/psi.c +5
-0+ cgroup =cgroup_parent (*iter); +if (cgroup &&cgroup_parent (cgroup)) { + *iter = cgroup; +return cgroup_psi (cgroup); + } }#endif *iter = &psi_system;return &psi_system;
But yes, very nice.
Suren Baghdasaryan
maintainerQuoted 10 lines · Peter Zijlstra
Quoted 7 lines · Suren Baghdasaryan
kernel/sched/psi.c +0
-0@@ -148,6 +148,7 @@static int psi_bug__read_mostly ;
Quoted 7 lines
kernel/sched/psi.c line 151
Quoted 2 lines
kernel/sched/psi.c +1
-0DEFINE_STATIC_KEY_FALSE (psi_disabled); +DEFINE_STATIC_KEY_FALSE (psi_cgroups_disabled);I'm thinking the whole thing will be easier/clearer when you make this:
DEFINE_STATIC_KEY_TRUE(psi_cgroups_enabled);
Sounds good. Will respin another version. Thanks for reviewing!
Quoted 50 lines
kernel/sched/psi.c void __init psi_init(void) · line 216
Quoted 9 lines
kernel/sched/psi.c +2
-0#ifdef CONFIG_PSI_DEFAULT_DISABLED static bool psi_enable;@@ -211,6 +212,9 @@ void __init psi_init(void)return ; } +if (!cgroup_psi_enabled ()) +static_branch_enable (&psi_cgroups_disabled);if (!cgroup_psi_enabled()) static_branch_disable(&psi_cgroups_enabled);kernel/sched/psi.c static void psi_group_change(struct psi_group *group, int cpu, · line 755
Quoted 13 lines
kernel/sched/psi.c +5
-0+ psi_period =jiffies_to_nsecs (PSI_FREQ );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) { +if (*iter == &psi_system) +return NULL ; +#ifdef CONFIG_CGROUPS +if (!static_branch_likely (&psi_cgroups_disabled)) {if (static_branch_likely(&psi_cgroups_enabled)) {Quoted 5 lines
kernel/sched/psi.c +4
-0+struct cgroup *cgroup =NULL ; +if (!*iter) + cgroup = task->cgroups->dfl_cgrp; +else kernel/sched/psi.c static void psi_group_change(struct psi_group *group, int cpu, · line 770
Quoted 10 lines
kernel/sched/psi.c +5
-0+ cgroup =cgroup_parent (*iter); +if (cgroup &&cgroup_parent (cgroup)) { + *iter = cgroup; +return cgroup_psi (cgroup); + } }#endif *iter = &psi_system;return &psi_system;But yes, very nice.
--
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]
Suren Baghdasaryan
maintainerQuoted 17 lines · Suren Baghdasaryan
Quoted 15 lines · Peter Zijlstra
kernel/sched/psi.c line 151
Quoted 9 lines · Suren Baghdasaryan
kernel/sched/psi.c +1
-0@@ -148,6 +148,7 @@static int psi_bug__read_mostly ;DEFINE_STATIC_KEY_FALSE (psi_disabled); +DEFINE_STATIC_KEY_FALSE (psi_cgroups_disabled);I'm thinking the whole thing will be easier/clearer when you make this:
Quoted 4 lines
Quoted 2 lines
DEFINE_STATIC_KEY_TRUE(psi_cgroups_enabled);Sounds good. Will respin another version. Thanks for reviewing!
v3 is posted at https://lore.kernel.org/patchwork/patch/1435705
Quoted 52 lines
Quoted 52 lines
kernel/sched/psi.c void __init psi_init(void) · line 216
Quoted 11 lines
kernel/sched/psi.c +2
-0#ifdef CONFIG_PSI_DEFAULT_DISABLED static bool psi_enable;@@ -211,6 +212,9 @@ void __init psi_init(void)return ; } +if (!cgroup_psi_enabled ()) +static_branch_enable (&psi_cgroups_disabled);if (!cgroup_psi_enabled()) static_branch_disable(&psi_cgroups_enabled);kernel/sched/psi.c static void psi_group_change(struct psi_group *group, int cpu, · line 755
Quoted 13 lines
kernel/sched/psi.c +5
-0+ psi_period =jiffies_to_nsecs (PSI_FREQ );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) { +if (*iter == &psi_system) +return NULL ; +#ifdef CONFIG_CGROUPS +if (!static_branch_likely (&psi_cgroups_disabled)) {if (static_branch_likely(&psi_cgroups_enabled)) {Quoted 5 lines
kernel/sched/psi.c +4
-0+struct cgroup *cgroup =NULL ; +if (!*iter) + cgroup = task->cgroups->dfl_cgrp; +else kernel/sched/psi.c static void psi_group_change(struct psi_group *group, int cpu, · line 770
Quoted 10 lines
kernel/sched/psi.c +5
-0+ cgroup =cgroup_parent (*iter); +if (cgroup &&cgroup_parent (cgroup)) { + *iter = cgroup; +return cgroup_psi (cgroup); + } }#endif *iter = &psi_system;return &psi_system;But yes, very nice.
--
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].