提交 2061acd6 编写于 作者: X Xu Yu 提交者: Shile Zhang

alinux: mm, memcg: account number of processes in the css

Since commit e0205ae40f12 ("mm: memcontrol: use CSS_TASK_ITER_PROCS at
mem_cgroup_scan_tasks()") made mem_cgroup_scan_tasks() to check only one
thread from each thread group, we can make cgroup_subsys_state::nr_tasks
to record only the thread group leader, i.e., process, instead of
thread(s). Furthermore, this renames cgroup_subsys_state::nr_tasks to
cgroup_subsys_state::nr_procs.

Fixes: f061cd88 ("alinux: kernel: cgroup: account number of tasks in
the css and its descendants")
Signed-off-by: NXu Yu <xuyu@linux.alibaba.com>
Reviewed-by: NYang Shi <yang.shi@linux.alibaba.com>
Reviewed-by: NXunlei Pang <xlpang@linux.alibaba.com>
上级 7bf04cbb
...@@ -141,8 +141,8 @@ struct cgroup_subsys_state { ...@@ -141,8 +141,8 @@ struct cgroup_subsys_state {
*/ */
int id; int id;
/* number of tasks under this css and its descendants */ /* number of procs under this css and its descendants */
int nr_tasks; int nr_procs;
unsigned int flags; unsigned int flags;
......
...@@ -1796,20 +1796,24 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) ...@@ -1796,20 +1796,24 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
return 0; return 0;
} }
static void css_account_tasks(struct css_set *cset, int num) static void css_account_procs(struct task_struct *task,
struct css_set *cset, int num)
{ {
struct cgroup_subsys *ss; struct cgroup_subsys *ss;
int ssid; int ssid;
if (!thread_group_leader(task))
return;
for_each_subsys(ss, ssid) { for_each_subsys(ss, ssid) {
struct cgroup_subsys_state *css = cset->subsys[ssid]; struct cgroup_subsys_state *css = cset->subsys[ssid];
if (!css) if (!css)
continue; continue;
css->nr_tasks += num; css->nr_procs += num;
while (css->parent) { while (css->parent) {
css = css->parent; css = css->parent;
css->nr_tasks += num; css->nr_procs += num;
} }
} }
} }
...@@ -1865,7 +1869,7 @@ static void cgroup_enable_task_cg_lists(void) ...@@ -1865,7 +1869,7 @@ static void cgroup_enable_task_cg_lists(void)
list_add_tail(&p->cg_list, &cset->tasks); list_add_tail(&p->cg_list, &cset->tasks);
get_css_set(cset); get_css_set(cset);
cset->nr_tasks++; cset->nr_tasks++;
css_account_tasks(cset, 1); css_account_procs(p, cset, 1);
} }
spin_unlock(&p->sighand->siglock); spin_unlock(&p->sighand->siglock);
} while_each_thread(g, p); } while_each_thread(g, p);
...@@ -2358,11 +2362,11 @@ static int cgroup_migrate_execute(struct cgroup_mgctx *mgctx) ...@@ -2358,11 +2362,11 @@ static int cgroup_migrate_execute(struct cgroup_mgctx *mgctx)
get_css_set(to_cset); get_css_set(to_cset);
to_cset->nr_tasks++; to_cset->nr_tasks++;
css_account_tasks(to_cset, 1); css_account_procs(task, to_cset, 1);
css_set_move_task(task, from_cset, to_cset, true); css_set_move_task(task, from_cset, to_cset, true);
put_css_set_locked(from_cset); put_css_set_locked(from_cset);
from_cset->nr_tasks--; from_cset->nr_tasks--;
css_account_tasks(from_cset, -1); css_account_procs(task, from_cset, -1);
} }
} }
spin_unlock_irq(&css_set_lock); spin_unlock_irq(&css_set_lock);
...@@ -5849,7 +5853,7 @@ void cgroup_post_fork(struct task_struct *child) ...@@ -5849,7 +5853,7 @@ void cgroup_post_fork(struct task_struct *child)
if (list_empty(&child->cg_list)) { if (list_empty(&child->cg_list)) {
get_css_set(cset); get_css_set(cset);
cset->nr_tasks++; cset->nr_tasks++;
css_account_tasks(cset, 1); css_account_procs(child, cset, 1);
css_set_move_task(child, NULL, cset, false); css_set_move_task(child, NULL, cset, false);
} }
spin_unlock_irq(&css_set_lock); spin_unlock_irq(&css_set_lock);
...@@ -5901,7 +5905,7 @@ void cgroup_exit(struct task_struct *tsk) ...@@ -5901,7 +5905,7 @@ void cgroup_exit(struct task_struct *tsk)
css_set_move_task(tsk, cset, NULL, false); css_set_move_task(tsk, cset, NULL, false);
list_add_tail(&tsk->cg_list, &cset->dying_tasks); list_add_tail(&tsk->cg_list, &cset->dying_tasks);
cset->nr_tasks--; cset->nr_tasks--;
css_account_tasks(cset, -1); css_account_procs(tsk, cset, -1);
spin_unlock_irq(&css_set_lock); spin_unlock_irq(&css_set_lock);
} else { } else {
get_css_set(cset); get_css_set(cset);
......
...@@ -1158,7 +1158,7 @@ mem_cgroup_select_victim_cgroup(struct mem_cgroup *memcg) ...@@ -1158,7 +1158,7 @@ mem_cgroup_select_victim_cgroup(struct mem_cgroup *memcg)
parent_mem = mem_cgroup_from_css(parent); parent_mem = mem_cgroup_from_css(parent);
if (parent->nr_tasks <= parent_mem->num_oom_skip) if (parent->nr_procs <= parent_mem->num_oom_skip)
break; break;
victim = parent; victim = parent;
chosen = NULL; chosen = NULL;
...@@ -1168,7 +1168,7 @@ mem_cgroup_select_victim_cgroup(struct mem_cgroup *memcg) ...@@ -1168,7 +1168,7 @@ mem_cgroup_select_victim_cgroup(struct mem_cgroup *memcg)
tmp = mem_cgroup_from_css(pos); tmp = mem_cgroup_from_css(pos);
if (pos->nr_tasks <= tmp->num_oom_skip) if (pos->nr_procs <= tmp->num_oom_skip)
continue; continue;
if (tmp->priority > chosen_priority) if (tmp->priority > chosen_priority)
continue; continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册