aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2013-07-03 18:01:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 19:07:26 -0400
commitffbdccf5e1facd18b54429a749667fb185c10f20 (patch)
treeb3c8cf7399bb6493568d02bce307dce45b4ea9d7
parent541c237c0923f567c9c4cabb8a81635baadc713f (diff)
mm, memcg: don't take task_lock in task_in_mem_cgroup
For processes that have detached their mm's, task_in_mem_cgroup() unnecessarily takes task_lock() when rcu_read_lock() is all that is necessary to call mem_cgroup_from_task(). While we're here, switch task_in_mem_cgroup() to return bool. Signed-off-by: David Rientjes <rientjes@google.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Michal Hocko <mhocko@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/memcontrol.h9
-rw-r--r--mm/memcontrol.c11
2 files changed, 11 insertions, 9 deletions
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index d6183f06d8c1..7b4d9d79570b 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -77,7 +77,8 @@ extern void mem_cgroup_uncharge_cache_page(struct page *page);
77 77
78bool __mem_cgroup_same_or_subtree(const struct mem_cgroup *root_memcg, 78bool __mem_cgroup_same_or_subtree(const struct mem_cgroup *root_memcg,
79 struct mem_cgroup *memcg); 79 struct mem_cgroup *memcg);
80int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg); 80bool task_in_mem_cgroup(struct task_struct *task,
81 const struct mem_cgroup *memcg);
81 82
82extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page); 83extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
83extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); 84extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
@@ -273,10 +274,10 @@ static inline bool mm_match_cgroup(struct mm_struct *mm,
273 return true; 274 return true;
274} 275}
275 276
276static inline int task_in_mem_cgroup(struct task_struct *task, 277static inline bool task_in_mem_cgroup(struct task_struct *task,
277 const struct mem_cgroup *memcg) 278 const struct mem_cgroup *memcg)
278{ 279{
279 return 1; 280 return true;
280} 281}
281 282
282static inline struct cgroup_subsys_state 283static inline struct cgroup_subsys_state
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 194721839cf5..4748966b1511 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1448,11 +1448,12 @@ static bool mem_cgroup_same_or_subtree(const struct mem_cgroup *root_memcg,
1448 return ret; 1448 return ret;
1449} 1449}
1450 1450
1451int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg) 1451bool task_in_mem_cgroup(struct task_struct *task,
1452 const struct mem_cgroup *memcg)
1452{ 1453{
1453 int ret;
1454 struct mem_cgroup *curr = NULL; 1454 struct mem_cgroup *curr = NULL;
1455 struct task_struct *p; 1455 struct task_struct *p;
1456 bool ret;
1456 1457
1457 p = find_lock_task_mm(task); 1458 p = find_lock_task_mm(task);
1458 if (p) { 1459 if (p) {
@@ -1464,14 +1465,14 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg)
1464 * killer still needs to detect if they have already been oom 1465 * killer still needs to detect if they have already been oom
1465 * killed to prevent needlessly killing additional tasks. 1466 * killed to prevent needlessly killing additional tasks.
1466 */ 1467 */
1467 task_lock(task); 1468 rcu_read_lock();
1468 curr = mem_cgroup_from_task(task); 1469 curr = mem_cgroup_from_task(task);
1469 if (curr) 1470 if (curr)
1470 css_get(&curr->css); 1471 css_get(&curr->css);
1471 task_unlock(task); 1472 rcu_read_unlock();
1472 } 1473 }
1473 if (!curr) 1474 if (!curr)
1474 return 0; 1475 return false;
1475 /* 1476 /*
1476 * We should check use_hierarchy of "memcg" not "curr". Because checking 1477 * We should check use_hierarchy of "memcg" not "curr". Because checking
1477 * use_hierarchy of "curr" here make this function true if hierarchy is 1478 * use_hierarchy of "curr" here make this function true if hierarchy is