cgroup: Rename cgroup lifecycle hooks to cgroup_task_*()

The current names cgroup_exit(), cgroup_release(), and cgroup_free() are
confusing because they look like they're operating on cgroups themselves when
they're actually task lifecycle hooks. For example, cgroup_init() initializes
the cgroup subsystem while cgroup_exit() is a task exit notification to
cgroup. Rename them to cgroup_task_exit(), cgroup_task_release(), and
cgroup_task_free() to make it clear that these operate on tasks.

Cc: Dan Schatzberg <dschatzberg@meta.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Reviewed-by: Chen Ridong <chenridong@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
Tejun Heo
2025-10-28 20:19:15 -10:00
parent d5cf4d34a3
commit 16dad7801a
5 changed files with 17 additions and 16 deletions

View File

@@ -137,9 +137,9 @@ extern void cgroup_cancel_fork(struct task_struct *p,
struct kernel_clone_args *kargs); struct kernel_clone_args *kargs);
extern void cgroup_post_fork(struct task_struct *p, extern void cgroup_post_fork(struct task_struct *p,
struct kernel_clone_args *kargs); struct kernel_clone_args *kargs);
void cgroup_exit(struct task_struct *p); void cgroup_task_exit(struct task_struct *p);
void cgroup_release(struct task_struct *p); void cgroup_task_release(struct task_struct *p);
void cgroup_free(struct task_struct *p); void cgroup_task_free(struct task_struct *p);
int cgroup_init_early(void); int cgroup_init_early(void);
int cgroup_init(void); int cgroup_init(void);
@@ -680,9 +680,9 @@ static inline void cgroup_cancel_fork(struct task_struct *p,
struct kernel_clone_args *kargs) {} struct kernel_clone_args *kargs) {}
static inline void cgroup_post_fork(struct task_struct *p, static inline void cgroup_post_fork(struct task_struct *p,
struct kernel_clone_args *kargs) {} struct kernel_clone_args *kargs) {}
static inline void cgroup_exit(struct task_struct *p) {} static inline void cgroup_task_exit(struct task_struct *p) {}
static inline void cgroup_release(struct task_struct *p) {} static inline void cgroup_task_release(struct task_struct *p) {}
static inline void cgroup_free(struct task_struct *p) {} static inline void cgroup_task_free(struct task_struct *p) {}
static inline int cgroup_init_early(void) { return 0; } static inline int cgroup_init_early(void) { return 0; }
static inline int cgroup_init(void) { return 0; } static inline int cgroup_init(void) { return 0; }

View File

@@ -944,7 +944,8 @@ static void css_set_move_task(struct task_struct *task,
/* /*
* We are synchronized through cgroup_threadgroup_rwsem * We are synchronized through cgroup_threadgroup_rwsem
* against PF_EXITING setting such that we can't race * against PF_EXITING setting such that we can't race
* against cgroup_exit()/cgroup_free() dropping the css_set. * against cgroup_task_exit()/cgroup_task_free() dropping
* the css_set.
*/ */
WARN_ON_ONCE(task->flags & PF_EXITING); WARN_ON_ONCE(task->flags & PF_EXITING);
@@ -6972,13 +6973,13 @@ void cgroup_post_fork(struct task_struct *child,
} }
/** /**
* cgroup_exit - detach cgroup from exiting task * cgroup_task_exit - detach cgroup from exiting task
* @tsk: pointer to task_struct of exiting process * @tsk: pointer to task_struct of exiting process
* *
* Description: Detach cgroup from @tsk. * Description: Detach cgroup from @tsk.
* *
*/ */
void cgroup_exit(struct task_struct *tsk) void cgroup_task_exit(struct task_struct *tsk)
{ {
struct cgroup_subsys *ss; struct cgroup_subsys *ss;
struct css_set *cset; struct css_set *cset;
@@ -7010,7 +7011,7 @@ void cgroup_exit(struct task_struct *tsk)
} while_each_subsys_mask(); } while_each_subsys_mask();
} }
void cgroup_release(struct task_struct *task) void cgroup_task_release(struct task_struct *task)
{ {
struct cgroup_subsys *ss; struct cgroup_subsys *ss;
int ssid; int ssid;
@@ -7027,7 +7028,7 @@ void cgroup_release(struct task_struct *task)
} }
} }
void cgroup_free(struct task_struct *task) void cgroup_task_free(struct task_struct *task)
{ {
struct css_set *cset = task_css_set(task); struct css_set *cset = task_css_set(task);
put_css_set(cset); put_css_set(cset);

View File

@@ -257,7 +257,7 @@ repeat:
rcu_read_unlock(); rcu_read_unlock();
pidfs_exit(p); pidfs_exit(p);
cgroup_release(p); cgroup_task_release(p);
/* Retrieve @thread_pid before __unhash_process() may set it to NULL. */ /* Retrieve @thread_pid before __unhash_process() may set it to NULL. */
thread_pid = task_pid(p); thread_pid = task_pid(p);
@@ -967,7 +967,7 @@ void __noreturn do_exit(long code)
exit_thread(tsk); exit_thread(tsk);
sched_autogroup_exit_task(tsk); sched_autogroup_exit_task(tsk);
cgroup_exit(tsk); cgroup_task_exit(tsk);
/* /*
* FIXME: do that only when needed, using sched_exit tracepoint * FIXME: do that only when needed, using sched_exit tracepoint

View File

@@ -738,7 +738,7 @@ void __put_task_struct(struct task_struct *tsk)
unwind_task_free(tsk); unwind_task_free(tsk);
sched_ext_free(tsk); sched_ext_free(tsk);
io_uring_free(tsk); io_uring_free(tsk);
cgroup_free(tsk); cgroup_task_free(tsk);
task_numa_free(tsk, true); task_numa_free(tsk, true);
security_task_free(tsk); security_task_free(tsk);
exit_creds(tsk); exit_creds(tsk);

View File

@@ -178,8 +178,8 @@ autogroup_move_group(struct task_struct *p, struct autogroup *ag)
* this process can already run with task_group() == prev->tg or we can * this process can already run with task_group() == prev->tg or we can
* race with cgroup code which can read autogroup = prev under rq->lock. * race with cgroup code which can read autogroup = prev under rq->lock.
* In the latter case for_each_thread() can not miss a migrating thread, * In the latter case for_each_thread() can not miss a migrating thread,
* cpu_cgroup_attach() must not be possible after cgroup_exit() and it * cpu_cgroup_attach() must not be possible after cgroup_task_exit()
* can't be removed from thread list, we hold ->siglock. * and it can't be removed from thread list, we hold ->siglock.
* *
* If an exiting thread was already removed from thread list we rely on * If an exiting thread was already removed from thread list we rely on
* sched_autogroup_exit_task(). * sched_autogroup_exit_task().