Commit df381975 authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds
Browse files

memcg: get_mem_cgroup_from_mm()



Instead of returning NULL from try_get_mem_cgroup_from_mm() when the mm
owner is exiting, just return root_mem_cgroup.  This makes sense for all
callsites and gets rid of some of them having to fallback manually.

[fengguang.wu@intel.com: fix warnings]
Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Signed-off-by: default avatarFengguang Wu <fengguang.wu@intel.com>
Acked-by: default avatarMichal Hocko <mhocko@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 03583f1a
...@@ -94,7 +94,6 @@ bool task_in_mem_cgroup(struct task_struct *task, ...@@ -94,7 +94,6 @@ bool task_in_mem_cgroup(struct task_struct *task,
extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page); extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg); extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css); extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
...@@ -294,11 +293,6 @@ static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) ...@@ -294,11 +293,6 @@ static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
return NULL; return NULL;
} }
static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
{
return NULL;
}
static inline bool mm_match_cgroup(struct mm_struct *mm, static inline bool mm_match_cgroup(struct mm_struct *mm,
struct mem_cgroup *memcg) struct mem_cgroup *memcg)
{ {
......
...@@ -1071,7 +1071,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) ...@@ -1071,7 +1071,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
return mem_cgroup_from_css(task_css(p, memory_cgrp_id)); return mem_cgroup_from_css(task_css(p, memory_cgrp_id));
} }
struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm) static struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
{ {
struct mem_cgroup *memcg = NULL; struct mem_cgroup *memcg = NULL;
...@@ -1079,7 +1079,7 @@ struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm) ...@@ -1079,7 +1079,7 @@ struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
do { do {
memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
if (unlikely(!memcg)) if (unlikely(!memcg))
break; memcg = root_mem_cgroup;
} while (!css_tryget(&memcg->css)); } while (!css_tryget(&memcg->css));
rcu_read_unlock(); rcu_read_unlock();
return memcg; return memcg;
...@@ -1475,7 +1475,7 @@ bool task_in_mem_cgroup(struct task_struct *task, ...@@ -1475,7 +1475,7 @@ bool task_in_mem_cgroup(struct task_struct *task,
p = find_lock_task_mm(task); p = find_lock_task_mm(task);
if (p) { if (p) {
curr = try_get_mem_cgroup_from_mm(p->mm); curr = get_mem_cgroup_from_mm(p->mm);
task_unlock(p); task_unlock(p);
} else { } else {
/* /*
...@@ -1489,8 +1489,6 @@ bool task_in_mem_cgroup(struct task_struct *task, ...@@ -1489,8 +1489,6 @@ bool task_in_mem_cgroup(struct task_struct *task,
css_get(&curr->css); css_get(&curr->css);
rcu_read_unlock(); rcu_read_unlock();
} }
if (!curr)
return false;
/* /*
* We should check use_hierarchy of "memcg" not "curr". Because checking * We should check use_hierarchy of "memcg" not "curr". Because checking
* use_hierarchy of "curr" here make this function true if hierarchy is * use_hierarchy of "curr" here make this function true if hierarchy is
...@@ -3617,15 +3615,7 @@ __memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **_memcg, int order) ...@@ -3617,15 +3615,7 @@ __memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **_memcg, int order)
if (!current->mm || current->memcg_kmem_skip_account) if (!current->mm || current->memcg_kmem_skip_account)
return true; return true;
memcg = try_get_mem_cgroup_from_mm(current->mm); memcg = get_mem_cgroup_from_mm(current->mm);
/*
* very rare case described in mem_cgroup_from_task. Unfortunately there
* isn't much we can do without complicating this too much, and it would
* be gfp-dependent anyway. Just let it go
*/
if (unlikely(!memcg))
return true;
if (!memcg_can_account_kmem(memcg)) { if (!memcg_can_account_kmem(memcg)) {
css_put(&memcg->css); css_put(&memcg->css);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment