Skip to content

Commit

Permalink
memcg: get_mem_cgroup_from_mm()
Browse files Browse the repository at this point in the history
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.

[[email protected]: fix warnings]
Signed-off-by: Johannes Weiner <[email protected]>
Signed-off-by: Fengguang Wu <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hnaz authored and torvalds committed Apr 7, 2014
1 parent 03583f1 commit df38197
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
6 changes: 0 additions & 6 deletions include/linux/memcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *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 *mem_cgroup_from_css(struct cgroup_subsys_state *css);
Expand Down Expand Up @@ -294,11 +293,6 @@ static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
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,
struct mem_cgroup *memcg)
{
Expand Down
18 changes: 4 additions & 14 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,15 +1071,15 @@ 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 *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;

rcu_read_lock();
do {
memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
if (unlikely(!memcg))
break;
memcg = root_mem_cgroup;
} while (!css_tryget(&memcg->css));
rcu_read_unlock();
return memcg;
Expand Down Expand Up @@ -1475,7 +1475,7 @@ bool task_in_mem_cgroup(struct task_struct *task,

p = find_lock_task_mm(task);
if (p) {
curr = try_get_mem_cgroup_from_mm(p->mm);
curr = get_mem_cgroup_from_mm(p->mm);
task_unlock(p);
} else {
/*
Expand All @@ -1489,8 +1489,6 @@ bool task_in_mem_cgroup(struct task_struct *task,
css_get(&curr->css);
rcu_read_unlock();
}
if (!curr)
return false;
/*
* We should check use_hierarchy of "memcg" not "curr". Because checking
* use_hierarchy of "curr" here make this function true if hierarchy is
Expand Down Expand Up @@ -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)
return true;

memcg = try_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;
memcg = get_mem_cgroup_from_mm(current->mm);

if (!memcg_can_account_kmem(memcg)) {
css_put(&memcg->css);
Expand Down

0 comments on commit df38197

Please sign in to comment.