* [PATCH -next] cgroup/misc: Introduce misc.peak
@ 2024-07-01 12:52 Xiu Jianfeng
2024-07-01 15:01 ` Randy Dunlap
2024-07-01 17:19 ` Tejun Heo
0 siblings, 2 replies; 5+ messages in thread
From: Xiu Jianfeng @ 2024-07-01 12:52 UTC (permalink / raw)
To: tj, lizefan.x, hannes, corbet, kamalesh.babulal, haitao.huang
Cc: cgroups, linux-doc, linux-kernel
Introduce misc.peak to record the historical maximum usage of the
resource, as in some scenarios the value of misc.max could be
adjusted based on the peak usage of the resource.
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
Documentation/admin-guide/cgroup-v2.rst | 9 ++++++++
include/linux/misc_cgroup.h | 2 ++
kernel/cgroup/misc.c | 29 +++++++++++++++++++++++++
3 files changed, 40 insertions(+)
diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
index ae0fdb6fc618..48ae30f2d9ab 100644
--- a/Documentation/admin-guide/cgroup-v2.rst
+++ b/Documentation/admin-guide/cgroup-v2.rst
@@ -2646,6 +2646,15 @@ Miscellaneous controller provides 3 interface files. If two misc resources (res_
res_a 3
res_b 0
+ misc.peak
+ A read-only flat-keyed file shown in the all cgroups. It shows
+ the historical maximum usage of the resources in the cgroup and
+ its children.::
+
+ $ cat misc.peak
+ res_a 10
+ res_b 8
+
misc.max
A read-write flat-keyed file shown in the non root cgroups. Allowed
maximum usage of the resources in the cgroup and its children.::
diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
index e799b1f8d05b..8aa69818291e 100644
--- a/include/linux/misc_cgroup.h
+++ b/include/linux/misc_cgroup.h
@@ -30,11 +30,13 @@ struct misc_cg;
/**
* struct misc_res: Per cgroup per misc type resource
* @max: Maximum limit on the resource.
+ * $watermark: Historical maximum usage of the resource.
* @usage: Current usage of the resource.
* @events: Number of times, the resource limit exceeded.
*/
struct misc_res {
u64 max;
+ u64 watermark;
atomic64_t usage;
atomic64_t events;
};
diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
index 79a3717a5803..a1b6ed76e00b 100644
--- a/kernel/cgroup/misc.c
+++ b/kernel/cgroup/misc.c
@@ -159,6 +159,8 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg, u64 amount)
ret = -EBUSY;
goto err_charge;
}
+ if (new_usage > READ_ONCE(res->watermark))
+ WRITE_ONCE(res->watermark, new_usage);
}
return 0;
@@ -307,6 +309,29 @@ static int misc_cg_current_show(struct seq_file *sf, void *v)
return 0;
}
+/**
+ * misc_cg_peak_show() - Show the peak usage of the misc cgroup.
+ * @sf: Interface file
+ * @v: Arguments passed
+ *
+ * Context: Any context.
+ * Return: 0 to denote successful print.
+ */
+static int misc_cg_peak_show(struct seq_file *sf, void *v)
+{
+ int i;
+ u64 watermark;
+ struct misc_cg *cg = css_misc(seq_css(sf));
+
+ for (i = 0; i < MISC_CG_RES_TYPES; i++) {
+ watermark = READ_ONCE(cg->res[i].watermark);
+ if (READ_ONCE(misc_res_capacity[i]) || watermark)
+ seq_printf(sf, "%s %llu\n", misc_res_name[i], watermark);
+ }
+
+ return 0;
+}
+
/**
* misc_cg_capacity_show() - Show the total capacity of misc res on the host.
* @sf: Interface file
@@ -357,6 +382,10 @@ static struct cftype misc_cg_files[] = {
.name = "current",
.seq_show = misc_cg_current_show,
},
+ {
+ .name = "peak",
+ .seq_show = misc_cg_peak_show,
+ },
{
.name = "capacity",
.seq_show = misc_cg_capacity_show,
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] cgroup/misc: Introduce misc.peak
2024-07-01 12:52 [PATCH -next] cgroup/misc: Introduce misc.peak Xiu Jianfeng
@ 2024-07-01 15:01 ` Randy Dunlap
2024-07-02 0:19 ` xiujianfeng
2024-07-01 17:19 ` Tejun Heo
1 sibling, 1 reply; 5+ messages in thread
From: Randy Dunlap @ 2024-07-01 15:01 UTC (permalink / raw)
To: Xiu Jianfeng, tj, lizefan.x, hannes, corbet, kamalesh.babulal,
haitao.huang
Cc: cgroups, linux-doc, linux-kernel
Hi--
On 7/1/24 5:52 AM, Xiu Jianfeng wrote:
> Introduce misc.peak to record the historical maximum usage of the
> resource, as in some scenarios the value of misc.max could be
> adjusted based on the peak usage of the resource.
>
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---
> Documentation/admin-guide/cgroup-v2.rst | 9 ++++++++
> include/linux/misc_cgroup.h | 2 ++
> kernel/cgroup/misc.c | 29 +++++++++++++++++++++++++
> 3 files changed, 40 insertions(+)
>
> diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
> index ae0fdb6fc618..48ae30f2d9ab 100644
> --- a/Documentation/admin-guide/cgroup-v2.rst
> +++ b/Documentation/admin-guide/cgroup-v2.rst
> @@ -2646,6 +2646,15 @@ Miscellaneous controller provides 3 interface files. If two misc resources (res_
> res_a 3
> res_b 0
>
> + misc.peak
> + A read-only flat-keyed file shown in the all cgroups. It shows
shown in all cgroups. It shows
> + the historical maximum usage of the resources in the cgroup and
> + its children.::
> +
> + $ cat misc.peak
> + res_a 10
> + res_b 8
> +
> misc.max
> A read-write flat-keyed file shown in the non root cgroups. Allowed
> maximum usage of the resources in the cgroup and its children.::
> diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
> index e799b1f8d05b..8aa69818291e 100644
> --- a/include/linux/misc_cgroup.h
> +++ b/include/linux/misc_cgroup.h
> @@ -30,11 +30,13 @@ struct misc_cg;
> /**
> * struct misc_res: Per cgroup per misc type resource
> * @max: Maximum limit on the resource.
> + * $watermark: Historical maximum usage of the resource.
@watermark:
> * @usage: Current usage of the resource.
> * @events: Number of times, the resource limit exceeded.
> */
> struct misc_res {
> u64 max;
> + u64 watermark;
> atomic64_t usage;
> atomic64_t events;
> };
--
~Randy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] cgroup/misc: Introduce misc.peak
2024-07-01 12:52 [PATCH -next] cgroup/misc: Introduce misc.peak Xiu Jianfeng
2024-07-01 15:01 ` Randy Dunlap
@ 2024-07-01 17:19 ` Tejun Heo
2024-07-02 0:20 ` xiujianfeng
1 sibling, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2024-07-01 17:19 UTC (permalink / raw)
To: Xiu Jianfeng
Cc: lizefan.x, hannes, corbet, kamalesh.babulal, haitao.huang,
cgroups, linux-doc, linux-kernel
On Mon, Jul 01, 2024 at 12:52:59PM +0000, Xiu Jianfeng wrote:
> + if (new_usage > READ_ONCE(res->watermark))
> + WRITE_ONCE(res->watermark, new_usage);
It'd be better to do cmpxchg loop on update. That doesn't make it noticeably
more expensive and the peak tracking would actually be accurate.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] cgroup/misc: Introduce misc.peak
2024-07-01 15:01 ` Randy Dunlap
@ 2024-07-02 0:19 ` xiujianfeng
0 siblings, 0 replies; 5+ messages in thread
From: xiujianfeng @ 2024-07-02 0:19 UTC (permalink / raw)
To: Randy Dunlap, tj, lizefan.x, hannes, corbet, kamalesh.babulal,
haitao.huang
Cc: cgroups, linux-doc, linux-kernel
On 2024/7/1 23:01, Randy Dunlap wrote:
> Hi--
>
> On 7/1/24 5:52 AM, Xiu Jianfeng wrote:
>> Introduce misc.peak to record the historical maximum usage of the
>> resource, as in some scenarios the value of misc.max could be
>> adjusted based on the peak usage of the resource.
>>
>> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
>> ---
>> Documentation/admin-guide/cgroup-v2.rst | 9 ++++++++
>> include/linux/misc_cgroup.h | 2 ++
>> kernel/cgroup/misc.c | 29 +++++++++++++++++++++++++
>> 3 files changed, 40 insertions(+)
>>
>> diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
>> index ae0fdb6fc618..48ae30f2d9ab 100644
>> --- a/Documentation/admin-guide/cgroup-v2.rst
>> +++ b/Documentation/admin-guide/cgroup-v2.rst
>> @@ -2646,6 +2646,15 @@ Miscellaneous controller provides 3 interface files. If two misc resources (res_
>> res_a 3
>> res_b 0
>>
>> + misc.peak
>> + A read-only flat-keyed file shown in the all cgroups. It shows
>
> shown in all cgroups. It shows
Thanks for your review, will fix it in v2.
>
>> + the historical maximum usage of the resources in the cgroup and
>> + its children.::
>> +
>> + $ cat misc.peak
>> + res_a 10
>> + res_b 8
>> +
>> misc.max
>> A read-write flat-keyed file shown in the non root cgroups. Allowed
>> maximum usage of the resources in the cgroup and its children.::
>> diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
>> index e799b1f8d05b..8aa69818291e 100644
>> --- a/include/linux/misc_cgroup.h
>> +++ b/include/linux/misc_cgroup.h
>> @@ -30,11 +30,13 @@ struct misc_cg;
>> /**
>> * struct misc_res: Per cgroup per misc type resource
>> * @max: Maximum limit on the resource.
>> + * $watermark: Historical maximum usage of the resource.
>
> @watermark:
>
>> * @usage: Current usage of the resource.
>> * @events: Number of times, the resource limit exceeded.
>> */
>> struct misc_res {
>> u64 max;
>> + u64 watermark;
>> atomic64_t usage;
>> atomic64_t events;
>> };
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] cgroup/misc: Introduce misc.peak
2024-07-01 17:19 ` Tejun Heo
@ 2024-07-02 0:20 ` xiujianfeng
0 siblings, 0 replies; 5+ messages in thread
From: xiujianfeng @ 2024-07-02 0:20 UTC (permalink / raw)
To: Tejun Heo
Cc: lizefan.x, hannes, corbet, kamalesh.babulal, haitao.huang,
cgroups, linux-doc, linux-kernel
On 2024/7/2 1:19, Tejun Heo wrote:
> On Mon, Jul 01, 2024 at 12:52:59PM +0000, Xiu Jianfeng wrote:
>> + if (new_usage > READ_ONCE(res->watermark))
>> + WRITE_ONCE(res->watermark, new_usage);
>
> It'd be better to do cmpxchg loop on update. That doesn't make it noticeably
> more expensive and the peak tracking would actually be accurate.
Thanks for your review, will do in v2.
>
> Thanks.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-07-02 0:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-01 12:52 [PATCH -next] cgroup/misc: Introduce misc.peak Xiu Jianfeng
2024-07-01 15:01 ` Randy Dunlap
2024-07-02 0:19 ` xiujianfeng
2024-07-01 17:19 ` Tejun Heo
2024-07-02 0:20 ` xiujianfeng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®