Skip to content

Commit 1028f39

Browse files
Xiu Jianfenghtejun
authored andcommitted
cgroup/misc: Introduce misc.peak
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 <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 7a44796 commit 1028f39

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,15 @@ Miscellaneous controller provides 3 interface files. If two misc resources (res_
26422642
res_a 3
26432643
res_b 0
26442644

2645+
misc.peak
2646+
A read-only flat-keyed file shown in all cgroups. It shows the
2647+
historical maximum usage of the resources in the cgroup and its
2648+
children.::
2649+
2650+
$ cat misc.peak
2651+
res_a 10
2652+
res_b 8
2653+
26452654
misc.max
26462655
A read-write flat-keyed file shown in the non root cgroups. Allowed
26472656
maximum usage of the resources in the cgroup and its children.::

include/linux/misc_cgroup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ struct misc_cg;
3131
/**
3232
* struct misc_res: Per cgroup per misc type resource
3333
* @max: Maximum limit on the resource.
34+
* @watermark: Historical maximum usage of the resource.
3435
* @usage: Current usage of the resource.
3536
* @events: Number of times, the resource limit exceeded.
3637
*/
3738
struct misc_res {
3839
u64 max;
40+
atomic64_t watermark;
3941
atomic64_t usage;
4042
atomic64_t events;
4143
};

kernel/cgroup/misc.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ static void misc_cg_cancel_charge(enum misc_res_type type, struct misc_cg *cg,
121121
misc_res_name[type]);
122122
}
123123

124+
static void misc_cg_update_watermark(struct misc_res *res, u64 new_usage)
125+
{
126+
u64 old;
127+
128+
while (true) {
129+
old = atomic64_read(&res->watermark);
130+
if (new_usage <= old)
131+
break;
132+
if (atomic64_cmpxchg(&res->watermark, old, new_usage) == old)
133+
break;
134+
}
135+
}
136+
124137
/**
125138
* misc_cg_try_charge() - Try charging the misc cgroup.
126139
* @type: Misc res type to charge.
@@ -159,6 +172,7 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg, u64 amount)
159172
ret = -EBUSY;
160173
goto err_charge;
161174
}
175+
misc_cg_update_watermark(res, new_usage);
162176
}
163177
return 0;
164178

@@ -307,6 +321,29 @@ static int misc_cg_current_show(struct seq_file *sf, void *v)
307321
return 0;
308322
}
309323

324+
/**
325+
* misc_cg_peak_show() - Show the peak usage of the misc cgroup.
326+
* @sf: Interface file
327+
* @v: Arguments passed
328+
*
329+
* Context: Any context.
330+
* Return: 0 to denote successful print.
331+
*/
332+
static int misc_cg_peak_show(struct seq_file *sf, void *v)
333+
{
334+
int i;
335+
u64 watermark;
336+
struct misc_cg *cg = css_misc(seq_css(sf));
337+
338+
for (i = 0; i < MISC_CG_RES_TYPES; i++) {
339+
watermark = atomic64_read(&cg->res[i].watermark);
340+
if (READ_ONCE(misc_res_capacity[i]) || watermark)
341+
seq_printf(sf, "%s %llu\n", misc_res_name[i], watermark);
342+
}
343+
344+
return 0;
345+
}
346+
310347
/**
311348
* misc_cg_capacity_show() - Show the total capacity of misc res on the host.
312349
* @sf: Interface file
@@ -357,6 +394,10 @@ static struct cftype misc_cg_files[] = {
357394
.name = "current",
358395
.seq_show = misc_cg_current_show,
359396
},
397+
{
398+
.name = "peak",
399+
.seq_show = misc_cg_peak_show,
400+
},
360401
{
361402
.name = "capacity",
362403
.seq_show = misc_cg_capacity_show,

0 commit comments

Comments
 (0)