Skip to content

Commit 0450236

Browse files
committed
cgroup: remove cgroup_pidlist->use_count
After the recent changes, pidlist ref is held only between cgroup_pidlist_start() and cgroup_pidlist_stop() during which cgroup->pidlist_mutex is also held. IOW, the reference count is redundant now. While in use, it's always one and pidlist_mutex is held - holding the mutex has exactly the same protection. This patch collapses destroy_dwork queueing into cgroup_pidlist_stop() so that pidlist_mutex is not released inbetween and drops pidlist->use_count. This patch shouldn't introduce any behavior changes. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
1 parent 4bac00d commit 0450236

1 file changed

Lines changed: 7 additions & 21 deletions

File tree

‎kernel/cgroup.c‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3456,8 +3456,6 @@ struct cgroup_pidlist {
34563456
pid_t *list;
34573457
/* how many elements the above list has */
34583458
int length;
3459-
/* how many files are using the current array */
3460-
int use_count;
34613459
/* each of these stored in a list by its cgroup */
34623460
struct list_head links;
34633461
/* pointer to the cgroup we belong to, for list removal purposes */
@@ -3473,8 +3471,6 @@ struct cgroup_pidlist_open_file {
34733471
struct cgroup_pidlist *pidlist;
34743472
};
34753473

3476-
static void cgroup_release_pid_array(struct cgroup_pidlist *l);
3477-
34783474
/*
34793475
* The following two functions "fix" the issue where there are more pids
34803476
* than kmalloc will give memory for; in such cases, we use vmalloc/vfree.
@@ -3524,10 +3520,10 @@ static void cgroup_pidlist_destroy_work_fn(struct work_struct *work)
35243520
mutex_lock(&l->owner->pidlist_mutex);
35253521

35263522
/*
3527-
* Destroy iff we didn't race with a new user or get queued again.
3528-
* Queued state won't change as it can only be queued while locked.
3523+
* Destroy iff we didn't get queued again. The state won't change
3524+
* as destroy_dwork can only be queued while locked.
35293525
*/
3530-
if (!l->use_count && !delayed_work_pending(dwork)) {
3526+
if (!delayed_work_pending(dwork)) {
35313527
list_del(&l->links);
35323528
pidlist_free(l->list);
35333529
put_pid_ns(l->key.ns);
@@ -3775,7 +3771,6 @@ static void *cgroup_pidlist_start(struct seq_file *s, loff_t *pos)
37753771
return ERR_PTR(ret);
37763772
}
37773773
l = of->pidlist;
3778-
l->use_count++;
37793774

37803775
if (pid) {
37813776
int end = l->length;
@@ -3804,9 +3799,11 @@ static void cgroup_pidlist_stop(struct seq_file *s, void *v)
38043799
{
38053800
struct cgroup_pidlist_open_file *of = s->private;
38063801

3807-
mutex_unlock(&of->cgrp->pidlist_mutex);
38083802
if (of->pidlist)
3809-
cgroup_release_pid_array(of->pidlist);
3803+
mod_delayed_work(cgroup_pidlist_destroy_wq,
3804+
&of->pidlist->destroy_dwork,
3805+
CGROUP_PIDLIST_DESTROY_DELAY);
3806+
mutex_unlock(&of->cgrp->pidlist_mutex);
38103807
}
38113808

38123809
static void *cgroup_pidlist_next(struct seq_file *s, void *v, loff_t *pos)
@@ -3844,17 +3841,6 @@ static const struct seq_operations cgroup_pidlist_seq_operations = {
38443841
.show = cgroup_pidlist_show,
38453842
};
38463843

3847-
static void cgroup_release_pid_array(struct cgroup_pidlist *l)
3848-
{
3849-
mutex_lock(&l->owner->pidlist_mutex);
3850-
BUG_ON(!l->use_count);
3851-
/* if the last user, arm the destroy work */
3852-
if (!--l->use_count)
3853-
mod_delayed_work(cgroup_pidlist_destroy_wq, &l->destroy_dwork,
3854-
CGROUP_PIDLIST_DESTROY_DELAY);
3855-
mutex_unlock(&l->owner->pidlist_mutex);
3856-
}
3857-
38583844
static const struct file_operations cgroup_pidlist_operations = {
38593845
.read = seq_read,
38603846
.llseek = seq_lseek,

0 commit comments

Comments
 (0)