Skip to contentSkip to conversation

cgroup: make per-cgroup pressure stall tracking configurable

PATCH Superseded Suren Baghdasaryan 3 participants 6 messages May 18, 2021 – May 24, 2021

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Suren Baghdasaryan

author maintainer
#0 lore raw

PATCH 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
index cb89dbdedc46..653c62142f07 100644
@@ -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
index 559ee05f86b2..671f55cac0f0 100644
@@ -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
index 4f2f79de083e..b929f589968b 100644
@@ -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
index cc25a3cff41f..4b8e72640ac9 100644
@@ -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
#1 lore raw
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_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.

Quoted 1 line

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.

author maintainer
#2 lore raw
Quoted 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_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.

Quoted 6 lines
Quoted 1 line

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_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.

Haven't thought about it before but that makes sense to me.

maintainer
#3 lore raw
In reply to Suren Baghdasaryan

kernel/sched/psi.c line 151

Quoted 9 lines · Suren Baghdasaryan
kernel/sched/psi.c +1 -0
index cc25a3cff41f..4b8e72640ac9 100644
@@ -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.

author maintainer
#4 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 7 lines · Suren Baghdasaryan
kernel/sched/psi.c +0 -0
index cc25a3cff41f..4b8e72640ac9 100644
@@ -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 -0
 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);

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]

author maintainer
#5 lore raw
Quoted 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
index cc25a3cff41f..4b8e72640ac9 100644
@@ -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].