Skip to content

Commit aade7f9

Browse files
rgushchinhtejun
authored andcommitted
cgroup: implement __cgroup_task_count() helper
The helper is identical to the existing cgroup_task_count() except it doesn't take the css_set_lock by itself, assuming that the caller does. Also, move cgroup_task_count() implementation into kernel/cgroup/cgroup.c, as there is nothing specific to cgroup v1. Signed-off-by: Roman Gushchin <[email protected]> Signed-off-by: Tejun Heo <[email protected]> Cc: [email protected]
1 parent 50943f3 commit aade7f9

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

kernel/cgroup/cgroup-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ int cgroup_rmdir(struct kernfs_node *kn);
240240
int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node,
241241
struct kernfs_root *kf_root);
242242

243+
int __cgroup_task_count(const struct cgroup *cgrp);
243244
int cgroup_task_count(const struct cgroup *cgrp);
244245

245246
/*

kernel/cgroup/cgroup-v1.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,6 @@ static struct cgroup_pidlist *cgroup_pidlist_find_create(struct cgroup *cgrp,
342342
return l;
343343
}
344344

345-
/**
346-
* cgroup_task_count - count the number of tasks in a cgroup.
347-
* @cgrp: the cgroup in question
348-
*/
349-
int cgroup_task_count(const struct cgroup *cgrp)
350-
{
351-
int count = 0;
352-
struct cgrp_cset_link *link;
353-
354-
spin_lock_irq(&css_set_lock);
355-
list_for_each_entry(link, &cgrp->cset_links, cset_link)
356-
count += link->cset->nr_tasks;
357-
spin_unlock_irq(&css_set_lock);
358-
return count;
359-
}
360-
361345
/*
362346
* Load a cgroup's pidarray with either procs' tgids or tasks' pids
363347
*/

kernel/cgroup/cgroup.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,39 @@ static void cgroup_get_live(struct cgroup *cgrp)
593593
css_get(&cgrp->self);
594594
}
595595

596+
/**
597+
* __cgroup_task_count - count the number of tasks in a cgroup. The caller
598+
* is responsible for taking the css_set_lock.
599+
* @cgrp: the cgroup in question
600+
*/
601+
int __cgroup_task_count(const struct cgroup *cgrp)
602+
{
603+
int count = 0;
604+
struct cgrp_cset_link *link;
605+
606+
lockdep_assert_held(&css_set_lock);
607+
608+
list_for_each_entry(link, &cgrp->cset_links, cset_link)
609+
count += link->cset->nr_tasks;
610+
611+
return count;
612+
}
613+
614+
/**
615+
* cgroup_task_count - count the number of tasks in a cgroup.
616+
* @cgrp: the cgroup in question
617+
*/
618+
int cgroup_task_count(const struct cgroup *cgrp)
619+
{
620+
int count;
621+
622+
spin_lock_irq(&css_set_lock);
623+
count = __cgroup_task_count(cgrp);
624+
spin_unlock_irq(&css_set_lock);
625+
626+
return count;
627+
}
628+
596629
struct cgroup_subsys_state *of_css(struct kernfs_open_file *of)
597630
{
598631
struct cgroup *cgrp = of->kn->parent->priv;

0 commit comments

Comments
 (0)