Skip to content

Commit 6f3d828

Browse files
committed
cgroup: remove cgroup->count and use
cgroup->count tracks the number of css_sets associated with the cgroup and used only to verify that no css_set is associated when the cgroup is being destroyed. It's superflous as the destruction path can simply check whether cgroup->cset_links is empty instead. Drop cgroup->count and check ->cset_links directly from cgroup_destroy_locked(). Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
1 parent ddd6914 commit 6f3d828

2 files changed

Lines changed: 5 additions & 22 deletions

File tree

‎include/linux/cgroup.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,6 @@ struct cgroup_name {
169169
struct cgroup {
170170
unsigned long flags; /* "unsigned long" so bitops work */
171171

172-
/*
173-
* count users of this cgroup. >0 means busy, but doesn't
174-
* necessarily indicate the number of tasks in the cgroup
175-
*/
176-
atomic_t count;
177-
178172
int id; /* ida allocated in-hierarchy ID */
179173

180174
/*

‎kernel/cgroup.c‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,7 @@ static void __put_css_set(struct css_set *cset, int taskexit)
408408
list_del(&link->cgrp_link);
409409

410410
/* @cgrp can't go away while we're holding css_set_lock */
411-
if (atomic_dec_and_test(&cgrp->count) &&
412-
notify_on_release(cgrp)) {
411+
if (list_empty(&cgrp->cset_links) && notify_on_release(cgrp)) {
413412
if (taskexit)
414413
set_bit(CGRP_RELEASABLE, &cgrp->flags);
415414
check_for_release(cgrp);
@@ -616,7 +615,6 @@ static void link_css_set(struct list_head *tmp_links, struct css_set *cset,
616615
link = list_first_entry(tmp_links, struct cgrp_cset_link, cset_link);
617616
link->cset = cset;
618617
link->cgrp = cgrp;
619-
atomic_inc(&cgrp->count);
620618
list_move(&link->cset_link, &cgrp->cset_links);
621619
/*
622620
* Always add links to the tail of the list so that the list
@@ -4370,11 +4368,11 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
43704368
lockdep_assert_held(&cgroup_mutex);
43714369

43724370
/*
4373-
* css_set_lock prevents @cgrp from being removed while
4374-
* __put_css_set() is in progress.
4371+
* css_set_lock synchronizes access to ->cset_links and prevents
4372+
* @cgrp from being removed while __put_css_set() is in progress.
43754373
*/
43764374
read_lock(&css_set_lock);
4377-
empty = !atomic_read(&cgrp->count) && list_empty(&cgrp->children);
4375+
empty = list_empty(&cgrp->cset_links) && list_empty(&cgrp->children);
43784376
read_unlock(&css_set_lock);
43794377
if (!empty)
43804378
return -EBUSY;
@@ -5054,7 +5052,7 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks)
50545052
static void check_for_release(struct cgroup *cgrp)
50555053
{
50565054
if (cgroup_is_releasable(cgrp) &&
5057-
!atomic_read(&cgrp->count) && list_empty(&cgrp->children)) {
5055+
list_empty(&cgrp->cset_links) && list_empty(&cgrp->children)) {
50585056
/*
50595057
* Control Group is currently removeable. If it's not
50605058
* already queued for a userspace notification, queue
@@ -5422,11 +5420,6 @@ static void debug_css_free(struct cgroup *cont)
54225420
kfree(cont->subsys[debug_subsys_id]);
54235421
}
54245422

5425-
static u64 cgroup_refcount_read(struct cgroup *cont, struct cftype *cft)
5426-
{
5427-
return atomic_read(&cont->count);
5428-
}
5429-
54305423
static u64 debug_taskcount_read(struct cgroup *cont, struct cftype *cft)
54315424
{
54325425
return cgroup_task_count(cont);
@@ -5507,10 +5500,6 @@ static u64 releasable_read(struct cgroup *cgrp, struct cftype *cft)
55075500
}
55085501

55095502
static struct cftype debug_files[] = {
5510-
{
5511-
.name = "cgroup_refcount",
5512-
.read_u64 = cgroup_refcount_read,
5513-
},
55145503
{
55155504
.name = "taskcount",
55165505
.read_u64 = debug_taskcount_read,

0 commit comments

Comments
 (0)