Re: [PATCH 0/2] mm->owner to mm->memcg fixes

From: Andrew Morton
Date: Fri May 25 2018 - 07:55:39 EST


On Thu, 24 May 2018 13:10:02 +0200 Michal Hocko <mhocko@xxxxxxxxxx> wrote:

> I would really prefer and appreciate a repost with all the fixes folded
> in.

[2/2]

From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Subject: mm/memcontrol.c: add mem_cgroup_from_task() as a local helper

Factor out some commonly-occurring code.

Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
Cc: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx>
Cc: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxxxx>
Cc: Tejun Heo <tj@xxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

mm/memcontrol.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff -puN mm/memcontrol.c~mm-memcontrolc-add-mem_cgroup_from_task-as-a-local-helper mm/memcontrol.c
--- a/mm/memcontrol.c~mm-memcontrolc-add-mem_cgroup_from_task-as-a-local-helper
+++ a/mm/memcontrol.c
@@ -664,6 +664,11 @@ static void memcg_check_events(struct me
}
}

+static inline struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
+{
+ return mem_cgroup_from_css(task_css(p, memory_cgrp_id));
+}
+
struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
{
struct mem_cgroup *memcg = NULL;
@@ -1011,7 +1016,7 @@ bool task_in_mem_cgroup(struct task_stru
* killed to prevent needlessly killing additional tasks.
*/
rcu_read_lock();
- task_memcg = mem_cgroup_from_css(task_css(task, memory_cgrp_id));
+ task_memcg = mem_cgroup_from_task(task);
css_get(&task_memcg->css);
rcu_read_unlock();
}
@@ -4836,7 +4841,7 @@ static int mem_cgroup_can_attach(struct
if (!move_flags)
return 0;

- from = mem_cgroup_from_css(task_css(p, memory_cgrp_id));
+ from = mem_cgroup_from_task(p);

VM_BUG_ON(from == memcg);

@@ -5887,7 +5892,7 @@ void mem_cgroup_sk_alloc(struct sock *sk
}

rcu_read_lock();
- memcg = mem_cgroup_from_css(task_css(current, memory_cgrp_id));
+ memcg = mem_cgroup_from_task(current);
if (memcg == root_mem_cgroup)
goto out;
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !memcg->tcpmem_active)
_