提交 f061cd88 编写于 作者: W Wenwei Tao 提交者: Caspar Zhang

alinux: kernel: cgroup: account number of tasks in the css and its descendants

Account number of the tasks in the css and its descendants, this is
prepared for the incoming memcg priority patch.

In memcg priority oom, we will select victim cgroup which has victim
tasks in it. We need to know whether the memcg and its descendants
have tasks before the selection can move on.
Signed-off-by: NWenwei Tao <wenwei.tao@linux.alibaba.com>
Reviewed-by: NXunlei Pang <xlpang@linux.alibaba.com>
上级 37cf1452
......@@ -141,6 +141,9 @@ struct cgroup_subsys_state {
*/
int id;
/* number of tasks under this css and its descendants */
int nr_tasks;
unsigned int flags;
/*
......
......@@ -1796,6 +1796,24 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
return 0;
}
static void css_account_tasks(struct css_set *cset, int num)
{
struct cgroup_subsys *ss;
int ssid;
for_each_subsys(ss, ssid) {
struct cgroup_subsys_state *css = cset->subsys[ssid];
if (!css)
continue;
css->nr_tasks += num;
while (css->parent) {
css = css->parent;
css->nr_tasks += num;
}
}
}
/*
* To reduce the fork() overhead for systems that are not actually using
* their cgroups capability, we don't maintain the lists running through
......@@ -1847,6 +1865,7 @@ static void cgroup_enable_task_cg_lists(void)
list_add_tail(&p->cg_list, &cset->tasks);
get_css_set(cset);
cset->nr_tasks++;
css_account_tasks(cset, 1);
}
spin_unlock(&p->sighand->siglock);
} while_each_thread(g, p);
......@@ -2339,9 +2358,11 @@ static int cgroup_migrate_execute(struct cgroup_mgctx *mgctx)
get_css_set(to_cset);
to_cset->nr_tasks++;
css_account_tasks(to_cset, 1);
css_set_move_task(task, from_cset, to_cset, true);
put_css_set_locked(from_cset);
from_cset->nr_tasks--;
css_account_tasks(from_cset, -1);
}
}
spin_unlock_irq(&css_set_lock);
......@@ -5828,6 +5849,7 @@ void cgroup_post_fork(struct task_struct *child)
if (list_empty(&child->cg_list)) {
get_css_set(cset);
cset->nr_tasks++;
css_account_tasks(cset, 1);
css_set_move_task(child, NULL, cset, false);
}
spin_unlock_irq(&css_set_lock);
......@@ -5879,6 +5901,7 @@ void cgroup_exit(struct task_struct *tsk)
css_set_move_task(tsk, cset, NULL, false);
list_add_tail(&tsk->cg_list, &cset->dying_tasks);
cset->nr_tasks--;
css_account_tasks(cset, -1);
spin_unlock_irq(&css_set_lock);
} else {
get_css_set(cset);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册