cgroup: inline cgroup_task_freeze()
authorRoman Gushchin <guro@fb.com>
Mon, 10 May 2021 21:39:46 +0000 (14:39 -0700)
committerTejun Heo <tj@kernel.org>
Tue, 11 May 2021 01:31:03 +0000 (21:31 -0400)
After the introduction of the cgroup.kill there is only one call site
of cgroup_task_freeze() left: cgroup_exit(). cgroup_task_freeze() is
currently taking rcu_read_lock() to read task's cgroup flags, but
because it's always called with css_set_lock locked, the rcu protection
is excessive.

Simplify the code by inlining cgroup_task_freeze().

v2: fix build

Signed-off-by: Roman Gushchin <guro@fb.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
include/linux/cgroup.h
kernel/cgroup/cgroup.c

index 4f2f79de083e213b53967d2808af15636f9eb222..a72764287cb53723dfbe4274719390ef829907ee 100644 (file)
@@ -906,20 +906,6 @@ void cgroup_freeze(struct cgroup *cgrp, bool freeze);
 void cgroup_freezer_migrate_task(struct task_struct *task, struct cgroup *src,
                                 struct cgroup *dst);
 
-static inline bool cgroup_task_freeze(struct task_struct *task)
-{
-       bool ret;
-
-       if (task->flags & PF_KTHREAD)
-               return false;
-
-       rcu_read_lock();
-       ret = test_bit(CGRP_FREEZE, &task_dfl_cgroup(task)->flags);
-       rcu_read_unlock();
-
-       return ret;
-}
-
 static inline bool cgroup_task_frozen(struct task_struct *task)
 {
        return task->frozen;
@@ -929,10 +915,6 @@ static inline bool cgroup_task_frozen(struct task_struct *task)
 
 static inline void cgroup_enter_frozen(void) { }
 static inline void cgroup_leave_frozen(bool always_leave) { }
-static inline bool cgroup_task_freeze(struct task_struct *task)
-{
-       return false;
-}
 static inline bool cgroup_task_frozen(struct task_struct *task)
 {
        return false;
index e640fc78d731f1cd21d84ddc505b0b205279a9da..8e0d7092afbb009623e03e9bab8ec9a1657d2111 100644 (file)
@@ -6267,7 +6267,8 @@ void cgroup_exit(struct task_struct *tsk)
        cset->nr_tasks--;
 
        WARN_ON_ONCE(cgroup_task_frozen(tsk));
-       if (unlikely(cgroup_task_freeze(tsk)))
+       if (unlikely(!(tsk->flags & PF_KTHREAD) &&
+                    test_bit(CGRP_FREEZE, &task_dfl_cgroup(tsk)->flags)))
                cgroup_update_frozen(task_dfl_cgroup(tsk));
 
        spin_unlock_irq(&css_set_lock);