All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures
@ 2021-09-15  2:18 brookxu
  2021-09-15  2:18   ` brookxu
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: brookxu @ 2021-09-15  2:18 UTC (permalink / raw)
  To: tj, lizefan.x, hannes
  Cc: vipinsh, mkoutny, corbet, linux-kernel, cgroups, linux-doc

From: Chunguang Xu <brookxu@tencent.com>

Introduce misc.events to make it easier for us to understand
the pressure of resources. Currently only the 'max' event is
implemented, which indicates the times the resource is about
to exceeds the max limit.

Signed-off-by: Chunguang Xu <brookxu@tencent.com>
---

v3: remove misc.events.local.
v2: remove cgroup v1 files.

 include/linux/misc_cgroup.h |  5 +++++
 kernel/cgroup/misc.c        | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
index da2367e..091f2d2 100644
--- a/include/linux/misc_cgroup.h
+++ b/include/linux/misc_cgroup.h
@@ -36,6 +36,7 @@ enum misc_res_type {
 struct misc_res {
 	unsigned long max;
 	atomic_long_t usage;
+	atomic_long_t events;
 	bool failed;
 };
 
@@ -46,6 +47,10 @@ struct misc_res {
  */
 struct misc_cg {
 	struct cgroup_subsys_state css;
+
+	/* misc.events */
+	struct cgroup_file events_file;
+
 	struct misc_res res[MISC_CG_RES_TYPES];
 };
 
diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
index ec02d96..4b2b492 100644
--- a/kernel/cgroup/misc.c
+++ b/kernel/cgroup/misc.c
@@ -171,6 +171,11 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
 	return 0;
 
 err_charge:
+	for (j = i; j; j = parent_misc(j)) {
+		atomic_long_inc(&j->res[type].events);
+		cgroup_file_notify(&j->events_file);
+	}
+
 	for (j = cg; j != i; j = parent_misc(j))
 		misc_cg_cancel_charge(type, j, amount);
 	misc_cg_cancel_charge(type, i, amount);
@@ -335,6 +340,19 @@ static int misc_cg_capacity_show(struct seq_file *sf, void *v)
 	return 0;
 }
 
+static int misc_events_show(struct seq_file *sf, void *v)
+{
+	struct misc_cg *cg = css_misc(seq_css(sf));
+	unsigned long events, i;
+
+	for (i = 0; i < MISC_CG_RES_TYPES; i++) {
+		events = atomic_long_read(&cg->res[i].events);
+		if (READ_ONCE(misc_res_capacity[i]) || events)
+			seq_printf(sf, "%s.max %lu\n", misc_res_name[i], events);
+	}
+	return 0;
+}
+
 /* Misc cgroup interface files */
 static struct cftype misc_cg_files[] = {
 	{
@@ -353,6 +371,12 @@ static int misc_cg_capacity_show(struct seq_file *sf, void *v)
 		.seq_show = misc_cg_capacity_show,
 		.flags = CFTYPE_ONLY_ON_ROOT,
 	},
+	{
+		.name = "events",
+		.flags = CFTYPE_NOT_ON_ROOT,
+		.file_offset = offsetof(struct misc_cg, events_file),
+		.seq_show = misc_events_show,
+	},
 	{}
 };
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood
@ 2021-09-15  2:18   ` brookxu
  0 siblings, 0 replies; 10+ messages in thread
From: brookxu @ 2021-09-15  2:18 UTC (permalink / raw)
  To: tj, lizefan.x, hannes
  Cc: vipinsh, mkoutny, corbet, linux-kernel, cgroups, linux-doc

From: Chunguang Xu <brookxu@tencent.com>

In scenarios where containers are frequently created and deleted,
a large number of error logs maybe generated. This log provides
less information, we can get more detailed info from misc.events.
From this, perhaps we can remove it.

Signed-off-by: Chunguang Xu <brookxu@tencent.com>
---
 include/linux/misc_cgroup.h | 1 -
 kernel/cgroup/misc.c        | 7 -------
 2 files changed, 8 deletions(-)

diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
index 091f2d2..c238207 100644
--- a/include/linux/misc_cgroup.h
+++ b/include/linux/misc_cgroup.h
@@ -37,7 +37,6 @@ struct misc_res {
 	unsigned long max;
 	atomic_long_t usage;
 	atomic_long_t events;
-	bool failed;
 };
 
 /**
diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
index 4b2b492..fe3e8a0 100644
--- a/kernel/cgroup/misc.c
+++ b/kernel/cgroup/misc.c
@@ -157,13 +157,6 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
 		new_usage = atomic_long_add_return(amount, &res->usage);
 		if (new_usage > READ_ONCE(res->max) ||
 		    new_usage > READ_ONCE(misc_res_capacity[type])) {
-			if (!res->failed) {
-				pr_info("cgroup: charge rejected by the misc controller for %s resource in ",
-					misc_res_name[type]);
-				pr_cont_cgroup_path(i->css.cgroup);
-				pr_cont("\n");
-				res->failed = true;
-			}
 			ret = -EBUSY;
 			goto err_charge;
 		}
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood
@ 2021-09-15  2:18   ` brookxu
  0 siblings, 0 replies; 10+ messages in thread
From: brookxu @ 2021-09-15  2:18 UTC (permalink / raw)
  To: tj-DgEjT+Ai2ygdnm+yROfE0A, lizefan.x-EC8Uxl6Npydl57MIdRCFDg,
	hannes-druUgvl0LCNAfugRpC6u6w
  Cc: vipinsh-hpIqsD4AKlfQT0dZR+AlfA, mkoutny-IBi9RG/b67k,
	corbet-T1hC0tSOHrs, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	cgroups-u79uwXL29TY76Z2rM5mHXA, linux-doc-u79uwXL29TY76Z2rM5mHXA

From: Chunguang Xu <brookxu-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org>

In scenarios where containers are frequently created and deleted,
a large number of error logs maybe generated. This log provides
less information, we can get more detailed info from misc.events.
From this, perhaps we can remove it.

Signed-off-by: Chunguang Xu <brookxu-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org>
---
 include/linux/misc_cgroup.h | 1 -
 kernel/cgroup/misc.c        | 7 -------
 2 files changed, 8 deletions(-)

diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
index 091f2d2..c238207 100644
--- a/include/linux/misc_cgroup.h
+++ b/include/linux/misc_cgroup.h
@@ -37,7 +37,6 @@ struct misc_res {
 	unsigned long max;
 	atomic_long_t usage;
 	atomic_long_t events;
-	bool failed;
 };
 
 /**
diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
index 4b2b492..fe3e8a0 100644
--- a/kernel/cgroup/misc.c
+++ b/kernel/cgroup/misc.c
@@ -157,13 +157,6 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
 		new_usage = atomic_long_add_return(amount, &res->usage);
 		if (new_usage > READ_ONCE(res->max) ||
 		    new_usage > READ_ONCE(misc_res_capacity[type])) {
-			if (!res->failed) {
-				pr_info("cgroup: charge rejected by the misc controller for %s resource in ",
-					misc_res_name[type]);
-				pr_cont_cgroup_path(i->css.cgroup);
-				pr_cont("\n");
-				res->failed = true;
-			}
 			ret = -EBUSY;
 			goto err_charge;
 		}
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 3/3] docs/cgroup: add entry for misc.events
  2021-09-15  2:18 [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures brookxu
  2021-09-15  2:18   ` brookxu
@ 2021-09-15  2:18 ` brookxu
  2021-09-16 17:47   ` Michal Koutný
  2021-09-15 17:04 ` [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures Vipin Sharma
  2021-09-16 17:47 ` Michal Koutný
  3 siblings, 1 reply; 10+ messages in thread
From: brookxu @ 2021-09-15  2:18 UTC (permalink / raw)
  To: tj, lizefan.x, hannes
  Cc: vipinsh, mkoutny, corbet, linux-kernel, cgroups, linux-doc

From: Chunguang Xu <brookxu@tencent.com>

Added descriptions of misc.events.

Signed-off-by: Chunguang Xu <brookxu@tencent.com>
---
 Documentation/admin-guide/cgroup-v2.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
index babbe04..e7acc55 100644
--- a/Documentation/admin-guide/cgroup-v2.rst
+++ b/Documentation/admin-guide/cgroup-v2.rst
@@ -2310,6 +2310,16 @@ Miscellaneous controller provides 3 interface files. If two misc resources (res_
         Limits can be set higher than the capacity value in the misc.capacity
         file.
 
+  misc.events
+	A read-only flat-keyed file which exists on non-root cgroups. The
+	following entries are defined. Unless specified otherwise, a value
+	change in this file generates a file modified event. All fields in
+	this file are hierarchical.
+
+	  max
+		The number of times the cgroup's resource usage was
+		about to go over the max boundary.
+
 Migration and Ownership
 ~~~~~~~~~~~~~~~~~~~~~~~
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures
  2021-09-15  2:18 [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures brookxu
  2021-09-15  2:18   ` brookxu
  2021-09-15  2:18 ` [PATCH v3 3/3] docs/cgroup: add entry for misc.events brookxu
@ 2021-09-15 17:04 ` Vipin Sharma
  2021-09-16 17:47 ` Michal Koutný
  3 siblings, 0 replies; 10+ messages in thread
From: Vipin Sharma @ 2021-09-15 17:04 UTC (permalink / raw)
  To: brookxu
  Cc: tj, lizefan.x, hannes, mkoutny, corbet, linux-kernel, cgroups, linux-doc

On Tue, Sep 14, 2021 at 7:18 PM brookxu <brookxu.cn@gmail.com> wrote:
>
> From: Chunguang Xu <brookxu@tencent.com>
>
> Introduce misc.events to make it easier for us to understand
> the pressure of resources. Currently only the 'max' event is
> implemented, which indicates the times the resource is about
> to exceeds the max limit.
>
> Signed-off-by: Chunguang Xu <brookxu@tencent.com>
> ---
>
> v3: remove misc.events.local.
> v2: remove cgroup v1 files.
>
>  include/linux/misc_cgroup.h |  5 +++++
>  kernel/cgroup/misc.c        | 24 ++++++++++++++++++++++++
>  2 files changed, 29 insertions(+)
>
> diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
> index da2367e..091f2d2 100644
> --- a/include/linux/misc_cgroup.h
> +++ b/include/linux/misc_cgroup.h
> @@ -36,6 +36,7 @@ enum misc_res_type {
>  struct misc_res {
>         unsigned long max;
>         atomic_long_t usage;
> +       atomic_long_t events;
>         bool failed;
>  };
>
> @@ -46,6 +47,10 @@ struct misc_res {
>   */
>  struct misc_cg {
>         struct cgroup_subsys_state css;
> +
> +       /* misc.events */
> +       struct cgroup_file events_file;
> +
>         struct misc_res res[MISC_CG_RES_TYPES];
>  };
>
> diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
> index ec02d96..4b2b492 100644
> --- a/kernel/cgroup/misc.c
> +++ b/kernel/cgroup/misc.c
> @@ -171,6 +171,11 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
>         return 0;
>
>  err_charge:
> +       for (j = i; j; j = parent_misc(j)) {
> +               atomic_long_inc(&j->res[type].events);
> +               cgroup_file_notify(&j->events_file);
> +       }
> +
>         for (j = cg; j != i; j = parent_misc(j))
>                 misc_cg_cancel_charge(type, j, amount);
>         misc_cg_cancel_charge(type, i, amount);
> @@ -335,6 +340,19 @@ static int misc_cg_capacity_show(struct seq_file *sf, void *v)
>         return 0;
>  }
>
> +static int misc_events_show(struct seq_file *sf, void *v)
> +{
> +       struct misc_cg *cg = css_misc(seq_css(sf));
> +       unsigned long events, i;
> +
> +       for (i = 0; i < MISC_CG_RES_TYPES; i++) {
> +               events = atomic_long_read(&cg->res[i].events);
> +               if (READ_ONCE(misc_res_capacity[i]) || events)
> +                       seq_printf(sf, "%s.max %lu\n", misc_res_name[i], events);
> +       }
> +       return 0;
> +}
> +
>  /* Misc cgroup interface files */
>  static struct cftype misc_cg_files[] = {
>         {
> @@ -353,6 +371,12 @@ static int misc_cg_capacity_show(struct seq_file *sf, void *v)
>                 .seq_show = misc_cg_capacity_show,
>                 .flags = CFTYPE_ONLY_ON_ROOT,
>         },
> +       {
> +               .name = "events",
> +               .flags = CFTYPE_NOT_ON_ROOT,
> +               .file_offset = offsetof(struct misc_cg, events_file),
> +               .seq_show = misc_events_show,
> +       },
>         {}
>  };
>
> --
> 1.8.3.1
>

Reviewed-by: Vipin Sharma <vipinsh@google.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures
  2021-09-15  2:18 [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures brookxu
                   ` (2 preceding siblings ...)
  2021-09-15 17:04 ` [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures Vipin Sharma
@ 2021-09-16 17:47 ` Michal Koutný
  3 siblings, 0 replies; 10+ messages in thread
From: Michal Koutný @ 2021-09-16 17:47 UTC (permalink / raw)
  To: brookxu
  Cc: tj, lizefan.x, hannes, vipinsh, corbet, linux-kernel, cgroups, linux-doc

On Wed, Sep 15, 2021 at 10:18:49AM +0800, brookxu <brookxu.cn@gmail.com> wrote:
> From: Chunguang Xu <brookxu@tencent.com>
> 
> Introduce misc.events to make it easier for us to understand
> the pressure of resources. Currently only the 'max' event is
> implemented, which indicates the times the resource is about
> to exceeds the max limit.
> 
> Signed-off-by: Chunguang Xu <brookxu@tencent.com>
> ---
> 
> v3: remove misc.events.local.
> v2: remove cgroup v1 files.
> 
>  include/linux/misc_cgroup.h |  5 +++++
>  kernel/cgroup/misc.c        | 24 ++++++++++++++++++++++++
>  2 files changed, 29 insertions(+)

LGTM,
Reviewed-by: Michal Koutný <mkoutny@suse.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 3/3] docs/cgroup: add entry for misc.events
  2021-09-15  2:18 ` [PATCH v3 3/3] docs/cgroup: add entry for misc.events brookxu
@ 2021-09-16 17:47   ` Michal Koutný
  0 siblings, 0 replies; 10+ messages in thread
From: Michal Koutný @ 2021-09-16 17:47 UTC (permalink / raw)
  To: brookxu
  Cc: tj, lizefan.x, hannes, vipinsh, corbet, linux-kernel, cgroups, linux-doc

On Wed, Sep 15, 2021 at 10:18:51AM +0800, brookxu <brookxu.cn@gmail.com> wrote:
> From: Chunguang Xu <brookxu@tencent.com>
> 
> Added descriptions of misc.events.
> 
> Signed-off-by: Chunguang Xu <brookxu@tencent.com>
> ---
>  Documentation/admin-guide/cgroup-v2.rst | 10 ++++++++++
>  1 file changed, 10 insertions(+)

Reviewed-by: Michal Koutný <mkoutny@suse.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood
  2021-09-15  2:18   ` brookxu
  (?)
@ 2021-09-16 17:57   ` Michal Koutný
  2021-09-17  1:56     ` brookxu
  -1 siblings, 1 reply; 10+ messages in thread
From: Michal Koutný @ 2021-09-16 17:57 UTC (permalink / raw)
  To: brookxu
  Cc: tj, lizefan.x, hannes, vipinsh, corbet, linux-kernel, cgroups, linux-doc

On Wed, Sep 15, 2021 at 10:18:50AM +0800, brookxu <brookxu.cn@gmail.com> wrote:
> In scenarios where containers are frequently created and deleted,
> a large number of error logs maybe generated. This log provides
> less information, we can get more detailed info from misc.events.

IIUC, the log provides equal information (with persistence), no?

> diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
> index 4b2b492..fe3e8a0 100644
> --- a/kernel/cgroup/misc.c
> +++ b/kernel/cgroup/misc.c
> @@ -157,13 +157,6 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
>  		new_usage = atomic_long_add_return(amount, &res->usage);
>  		if (new_usage > READ_ONCE(res->max) ||
>  		    new_usage > READ_ONCE(misc_res_capacity[type])) {
> -			if (!res->failed) {
> -				pr_info("cgroup: charge rejected by the misc controller for %s resource in ",
> -					misc_res_name[type]);
> -				pr_cont_cgroup_path(i->css.cgroup);
> -				pr_cont("\n");
> -				res->failed = true;
> -			}

As I argued previously, reporting this as "in" `i` cgroup instead
of `cg` is not that useful and equivalent to the misc.events:*.max now,
so the drop is appropriate.

The change/patch is OK,
Reviewed-by: Michal Koutný <mkoutny@suse.com>

The commit message might be fixed (if you agree with remark).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood
  2021-09-16 17:57   ` Michal Koutný
@ 2021-09-17  1:56     ` brookxu
  2021-09-17  8:09       ` Michal Koutný
  0 siblings, 1 reply; 10+ messages in thread
From: brookxu @ 2021-09-17  1:56 UTC (permalink / raw)
  To: Michal Koutný
  Cc: tj, lizefan.x, hannes, vipinsh, corbet, linux-kernel, cgroups, linux-doc

Thanks for your time.

Michal Koutný wrote on 2021/9/17 1:57 上午:
> On Wed, Sep 15, 2021 at 10:18:50AM +0800, brookxu <brookxu.cn@gmail.com> wrote:
>> In scenarios where containers are frequently created and deleted,
>> a large number of error logs maybe generated. This log provides
>> less information, we can get more detailed info from misc.events.
> 
> IIUC, the log provides equal information (with persistence), no?
> 
>> diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
>> index 4b2b492..fe3e8a0 100644
>> --- a/kernel/cgroup/misc.c
>> +++ b/kernel/cgroup/misc.c
>> @@ -157,13 +157,6 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
>>  		new_usage = atomic_long_add_return(amount, &res->usage);
>>  		if (new_usage > READ_ONCE(res->max) ||
>>  		    new_usage > READ_ONCE(misc_res_capacity[type])) {
>> -			if (!res->failed) {
>> -				pr_info("cgroup: charge rejected by the misc controller for %s resource in ",
>> -					misc_res_name[type]);
>> -				pr_cont_cgroup_path(i->css.cgroup);
>> -				pr_cont("\n");
>> -				res->failed = true;
>> -			}
> 
> As I argued previously, reporting this as "in" `i` cgroup instead
> of `cg` is not that useful and equivalent to the misc.events:*.max now,
> so the drop is appropriate.
> 
> The change/patch is OK,
> Reviewed-by: Michal Koutný <mkoutny@suse.com>
> 
> The commit message might be fixed (if you agree with remark).

Yeah, maybe we should make it more clearly, What do you think of
the commit below:

In scenarios where containers are frequently created and deleted,
a large number of error logs maybe generated. The logs only show
which node is about to go over the max limit, not the node which
resource request failed. As misc.event has provided relevant
information, maybe we can remove this log.


> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood
  2021-09-17  1:56     ` brookxu
@ 2021-09-17  8:09       ` Michal Koutný
  0 siblings, 0 replies; 10+ messages in thread
From: Michal Koutný @ 2021-09-17  8:09 UTC (permalink / raw)
  To: brookxu
  Cc: tj, lizefan.x, hannes, vipinsh, corbet, linux-kernel, cgroups, linux-doc

On Fri, Sep 17, 2021 at 09:56:26AM +0800, brookxu <brookxu.cn@gmail.com> wrote:
> Yeah, maybe we should make it more clearly, What do you think of
> the commit below:
> 
> In scenarios where containers are frequently created and deleted,
> a large number of error logs maybe generated. The logs only show
> which node is about to go over the max limit, not the node which
> resource request failed. As misc.event has provided relevant
> information, maybe we can remove this log.

It is a good reasoning for the change. LGTM.

Michal

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-09-17  8:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15  2:18 [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures brookxu
2021-09-15  2:18 ` [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood brookxu
2021-09-15  2:18   ` brookxu
2021-09-16 17:57   ` Michal Koutný
2021-09-17  1:56     ` brookxu
2021-09-17  8:09       ` Michal Koutný
2021-09-15  2:18 ` [PATCH v3 3/3] docs/cgroup: add entry for misc.events brookxu
2021-09-16 17:47   ` Michal Koutný
2021-09-15 17:04 ` [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures Vipin Sharma
2021-09-16 17:47 ` Michal Koutný

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.