Skip to content

Commit 6a26f9c

Browse files
Xiu Jianfenghtejun
authored andcommitted
cgroup/misc: Introduce misc.events.local
Currently the event counting provided by misc.events is hierarchical, it's not practical if user is only concerned with events of a specified cgroup. Therefore, introduce misc.events.local collect events specific to the given cgroup. This is analogous to memory.events.local and pids.events.local. Signed-off-by: Xiu Jianfeng <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent b824766 commit 6a26f9c

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,6 +2680,11 @@ Miscellaneous controller provides 3 interface files. If two misc resources (res_
26802680
The number of times the cgroup's resource usage was
26812681
about to go over the max boundary.
26822682

2683+
misc.events.local
2684+
Similar to misc.events but the fields in the file are local to the
2685+
cgroup i.e. not hierarchical. The file modified event generated on
2686+
this file reflects only the local events.
2687+
26832688
Migration and Ownership
26842689
~~~~~~~~~~~~~~~~~~~~~~~
26852690

include/linux/misc_cgroup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct misc_res {
4040
atomic64_t watermark;
4141
atomic64_t usage;
4242
atomic64_t events;
43+
atomic64_t events_local;
4344
};
4445

4546
/**
@@ -53,6 +54,8 @@ struct misc_cg {
5354

5455
/* misc.events */
5556
struct cgroup_file events_file;
57+
/* misc.events.local */
58+
struct cgroup_file events_local_file;
5659

5760
struct misc_res res[MISC_CG_RES_TYPES];
5861
};

kernel/cgroup/misc.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ static void misc_cg_update_watermark(struct misc_res *res, u64 new_usage)
134134
}
135135
}
136136

137+
static void misc_cg_event(enum misc_res_type type, struct misc_cg *cg)
138+
{
139+
atomic64_inc(&cg->res[type].events_local);
140+
cgroup_file_notify(&cg->events_local_file);
141+
142+
for (; parent_misc(cg); cg = parent_misc(cg)) {
143+
atomic64_inc(&cg->res[type].events);
144+
cgroup_file_notify(&cg->events_file);
145+
}
146+
}
147+
137148
/**
138149
* misc_cg_try_charge() - Try charging the misc cgroup.
139150
* @type: Misc res type to charge.
@@ -177,10 +188,7 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg, u64 amount)
177188
return 0;
178189

179190
err_charge:
180-
for (j = i; j; j = parent_misc(j)) {
181-
atomic64_inc(&j->res[type].events);
182-
cgroup_file_notify(&j->events_file);
183-
}
191+
misc_cg_event(type, i);
184192

185193
for (j = cg; j != i; j = parent_misc(j))
186194
misc_cg_cancel_charge(type, j, amount);
@@ -368,20 +376,33 @@ static int misc_cg_capacity_show(struct seq_file *sf, void *v)
368376
return 0;
369377
}
370378

371-
static int misc_events_show(struct seq_file *sf, void *v)
379+
static int __misc_events_show(struct seq_file *sf, bool local)
372380
{
373381
struct misc_cg *cg = css_misc(seq_css(sf));
374382
u64 events;
375383
int i;
376384

377385
for (i = 0; i < MISC_CG_RES_TYPES; i++) {
378-
events = atomic64_read(&cg->res[i].events);
386+
if (local)
387+
events = atomic64_read(&cg->res[i].events_local);
388+
else
389+
events = atomic64_read(&cg->res[i].events);
379390
if (READ_ONCE(misc_res_capacity[i]) || events)
380391
seq_printf(sf, "%s.max %llu\n", misc_res_name[i], events);
381392
}
382393
return 0;
383394
}
384395

396+
static int misc_events_show(struct seq_file *sf, void *v)
397+
{
398+
return __misc_events_show(sf, false);
399+
}
400+
401+
static int misc_events_local_show(struct seq_file *sf, void *v)
402+
{
403+
return __misc_events_show(sf, true);
404+
}
405+
385406
/* Misc cgroup interface files */
386407
static struct cftype misc_cg_files[] = {
387408
{
@@ -409,6 +430,12 @@ static struct cftype misc_cg_files[] = {
409430
.file_offset = offsetof(struct misc_cg, events_file),
410431
.seq_show = misc_events_show,
411432
},
433+
{
434+
.name = "events.local",
435+
.flags = CFTYPE_NOT_ON_ROOT,
436+
.file_offset = offsetof(struct misc_cg, events_local_file),
437+
.seq_show = misc_events_local_show,
438+
},
412439
{}
413440
};
414441

0 commit comments

Comments
 (0)