Skip to content

Commit 05070cd

Browse files
shakeelbhtejun
authored andcommitted
cgroup: reduce cgroup_file_kn_lock hold time in cgroup_file_notify()
cgroup_file_notify() calls kernfs_notify() while holding the global cgroup_file_kn_lock. kernfs_notify() does non-trivial work including wake_up_interruptible() and acquisition of a second global spinlock (kernfs_notify_lock), inflating the hold time. Take a kernfs_get() reference under the lock and call kernfs_notify() after dropping it, following the pattern from cgroup_file_show(). Reported-by: Jakub Kicinski <[email protected]> Signed-off-by: Shakeel Butt <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 5b30afc commit 05070cd

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

kernel/cgroup/cgroup.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4632,6 +4632,7 @@ int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
46324632
void cgroup_file_notify(struct cgroup_file *cfile)
46334633
{
46344634
unsigned long flags;
4635+
struct kernfs_node *kn = NULL;
46354636

46364637
spin_lock_irqsave(&cgroup_file_kn_lock, flags);
46374638
if (cfile->kn) {
@@ -4641,11 +4642,17 @@ void cgroup_file_notify(struct cgroup_file *cfile)
46414642
if (time_in_range(jiffies, last, next)) {
46424643
timer_reduce(&cfile->notify_timer, next);
46434644
} else {
4644-
kernfs_notify(cfile->kn);
4645+
kn = cfile->kn;
4646+
kernfs_get(kn);
46454647
cfile->notified_at = jiffies;
46464648
}
46474649
}
46484650
spin_unlock_irqrestore(&cgroup_file_kn_lock, flags);
4651+
4652+
if (kn) {
4653+
kernfs_notify(kn);
4654+
kernfs_put(kn);
4655+
}
46494656
}
46504657
EXPORT_SYMBOL_GPL(cgroup_file_notify);
46514658

0 commit comments

Comments
 (0)