Skip to content

Commit 1257b87

Browse files
shakeelbhtejun
authored andcommitted
cgroup: support to enable nmi-safe css_rstat_updated
Add necessary infrastructure to enable the nmi-safe execution of css_rstat_updated(). Currently css_rstat_updated() takes a per-cpu per-css raw spinlock to add the given css in the per-cpu per-css update tree. However the kernel can not spin in nmi context, so we need to remove the spinning on the raw spinlock in css_rstat_updated(). To support lockless css_rstat_updated(), let's add necessary data structures in the css and ss structures. Signed-off-by: Shakeel Butt <[email protected]> Tested-by: JP Kobryn <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 5da4f9d commit 1257b87

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

include/linux/cgroup-defs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ struct css_rstat_cpu {
384384
*/
385385
struct cgroup_subsys_state *updated_children;
386386
struct cgroup_subsys_state *updated_next; /* NULL if not on the list */
387+
388+
struct llist_node lnode; /* lockless list for update */
389+
struct cgroup_subsys_state *owner; /* back pointer */
387390
};
388391

389392
/*
@@ -822,6 +825,7 @@ struct cgroup_subsys {
822825

823826
spinlock_t rstat_ss_lock;
824827
raw_spinlock_t __percpu *rstat_ss_cpu_lock;
828+
struct llist_head __percpu *lhead; /* lockless update list head */
825829
};
826830

827831
extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem;

kernel/cgroup/rstat.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
static DEFINE_SPINLOCK(rstat_base_lock);
1313
static DEFINE_PER_CPU(raw_spinlock_t, rstat_base_cpu_lock);
14+
static DEFINE_PER_CPU(struct llist_head, rstat_backlog_list);
1415

1516
static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu);
1617

@@ -45,6 +46,13 @@ static spinlock_t *ss_rstat_lock(struct cgroup_subsys *ss)
4546
return &rstat_base_lock;
4647
}
4748

49+
static inline struct llist_head *ss_lhead_cpu(struct cgroup_subsys *ss, int cpu)
50+
{
51+
if (ss)
52+
return per_cpu_ptr(ss->lhead, cpu);
53+
return per_cpu_ptr(&rstat_backlog_list, cpu);
54+
}
55+
4856
static raw_spinlock_t *ss_rstat_cpu_lock(struct cgroup_subsys *ss, int cpu)
4957
{
5058
if (ss)
@@ -456,7 +464,8 @@ int css_rstat_init(struct cgroup_subsys_state *css)
456464
for_each_possible_cpu(cpu) {
457465
struct css_rstat_cpu *rstatc = css_rstat_cpu(css, cpu);
458466

459-
rstatc->updated_children = css;
467+
rstatc->owner = rstatc->updated_children = css;
468+
init_llist_node(&rstatc->lnode);
460469

461470
if (is_self) {
462471
struct cgroup_rstat_base_cpu *rstatbc;
@@ -525,9 +534,19 @@ int __init ss_rstat_init(struct cgroup_subsys *ss)
525534
}
526535
#endif
527536

537+
if (ss) {
538+
ss->lhead = alloc_percpu(struct llist_head);
539+
if (!ss->lhead) {
540+
free_percpu(ss->rstat_ss_cpu_lock);
541+
return -ENOMEM;
542+
}
543+
}
544+
528545
spin_lock_init(ss_rstat_lock(ss));
529-
for_each_possible_cpu(cpu)
546+
for_each_possible_cpu(cpu) {
530547
raw_spin_lock_init(ss_rstat_cpu_lock(ss, cpu));
548+
init_llist_head(ss_lhead_cpu(ss, cpu));
549+
}
531550

532551
return 0;
533552
}

0 commit comments

Comments
 (0)