2021-09-15 02:20:31

by brookxu.cn

[permalink] [raw]
Subject: [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures

From: Chunguang Xu <[email protected]>

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 <[email protected]>
---

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


2021-09-15 02:21:09

by brookxu.cn

[permalink] [raw]
Subject: [PATCH v3 3/3] docs/cgroup: add entry for misc.events

From: Chunguang Xu <[email protected]>

Added descriptions of misc.events.

Signed-off-by: Chunguang Xu <[email protected]>
---
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

2021-09-15 02:21:09

by brookxu.cn

[permalink] [raw]
Subject: [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood

From: Chunguang Xu <[email protected]>

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 <[email protected]>
---
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

2021-09-15 17:06:19

by Vipin Sharma

[permalink] [raw]
Subject: Re: [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures

On Tue, Sep 14, 2021 at 7:18 PM brookxu <[email protected]> wrote:
>
> From: Chunguang Xu <[email protected]>
>
> 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 <[email protected]>
> ---
>
> 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 <[email protected]>

2021-09-16 17:55:32

by Michal Koutný

[permalink] [raw]
Subject: Re: [PATCH v3 1/3] misc_cgroup: introduce misc.events to count failures

On Wed, Sep 15, 2021 at 10:18:49AM +0800, brookxu <[email protected]> wrote:
> From: Chunguang Xu <[email protected]>
>
> 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 <[email protected]>
> ---
>
> 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? <[email protected]>

2021-09-16 17:55:32

by Michal Koutný

[permalink] [raw]
Subject: Re: [PATCH v3 3/3] docs/cgroup: add entry for misc.events

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

Reviewed-by: Michal Koutn? <[email protected]>

2021-09-17 07:59:10

by Michal Koutný

[permalink] [raw]
Subject: Re: [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood

On Wed, Sep 15, 2021 at 10:18:50AM +0800, brookxu <[email protected]> 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? <[email protected]>

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

2021-09-17 10:14:49

by brookxu.cn

[permalink] [raw]
Subject: Re: [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood

Thanks for your time.

Michal Koutný wrote on 2021/9/17 1:57 上午:
> On Wed, Sep 15, 2021 at 10:18:50AM +0800, brookxu <[email protected]> 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ý <[email protected]>
>
> 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.


>

2021-09-17 13:12:27

by Michal Koutný

[permalink] [raw]
Subject: Re: [PATCH v3 2/3] misc_cgroup: remove error log to avoid log flood

On Fri, Sep 17, 2021 at 09:56:26AM +0800, brookxu <[email protected]> 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