Skip to content

Commit f279294

Browse files
brookxu-txhtejun
authored andcommitted
misc_cgroup: introduce misc.events to count failures
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]> Reviewed-by: Vipin Sharma <[email protected]> Reviewed-by: Michal Koutný <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent c0002d1 commit f279294

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/linux/misc_cgroup.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct misc_cg;
3636
struct misc_res {
3737
unsigned long max;
3838
atomic_long_t usage;
39+
atomic_long_t events;
3940
bool failed;
4041
};
4142

@@ -46,6 +47,10 @@ struct misc_res {
4647
*/
4748
struct misc_cg {
4849
struct cgroup_subsys_state css;
50+
51+
/* misc.events */
52+
struct cgroup_file events_file;
53+
4954
struct misc_res res[MISC_CG_RES_TYPES];
5055
};
5156

kernel/cgroup/misc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
171171
return 0;
172172

173173
err_charge:
174+
for (j = i; j; j = parent_misc(j)) {
175+
atomic_long_inc(&j->res[type].events);
176+
cgroup_file_notify(&j->events_file);
177+
}
178+
174179
for (j = cg; j != i; j = parent_misc(j))
175180
misc_cg_cancel_charge(type, j, amount);
176181
misc_cg_cancel_charge(type, i, amount);
@@ -335,6 +340,19 @@ static int misc_cg_capacity_show(struct seq_file *sf, void *v)
335340
return 0;
336341
}
337342

343+
static int misc_events_show(struct seq_file *sf, void *v)
344+
{
345+
struct misc_cg *cg = css_misc(seq_css(sf));
346+
unsigned long events, i;
347+
348+
for (i = 0; i < MISC_CG_RES_TYPES; i++) {
349+
events = atomic_long_read(&cg->res[i].events);
350+
if (READ_ONCE(misc_res_capacity[i]) || events)
351+
seq_printf(sf, "%s.max %lu\n", misc_res_name[i], events);
352+
}
353+
return 0;
354+
}
355+
338356
/* Misc cgroup interface files */
339357
static struct cftype misc_cg_files[] = {
340358
{
@@ -353,6 +371,12 @@ static struct cftype misc_cg_files[] = {
353371
.seq_show = misc_cg_capacity_show,
354372
.flags = CFTYPE_ONLY_ON_ROOT,
355373
},
374+
{
375+
.name = "events",
376+
.flags = CFTYPE_NOT_ON_ROOT,
377+
.file_offset = offsetof(struct misc_cg, events_file),
378+
.seq_show = misc_events_show,
379+
},
356380
{}
357381
};
358382

0 commit comments

Comments
 (0)