diff options
author | Wu Fengguang <fengguang.wu@intel.com> | 2009-12-16 06:19:59 -0500 |
---|---|---|
committer | Andi Kleen <ak@linux.intel.com> | 2009-12-16 06:19:59 -0500 |
commit | e42d9d5d47961fb5db0be65b56dd52fe7b2421f1 (patch) | |
tree | 6a898c8d43ee0533581076342b9a7a97cca0509e | |
parent | 478c5ffc0b50527bd2390f2daa46cc16276b8413 (diff) |
memcg: rename and export try_get_mem_cgroup_from_page()
So that the hwpoison injector can get mem_cgroup for arbitrary page
and thus know whether it is owned by some mem_cgroup task(s).
[AK: Merged with latest git tree]
CC: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
CC: Hugh Dickins <hugh.dickins@tiscali.co.uk>
CC: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
CC: Balbir Singh <balbir@linux.vnet.ibm.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
-rw-r--r-- | include/linux/memcontrol.h | 6 | ||||
-rw-r--r-- | mm/memcontrol.c | 11 |
2 files changed, 10 insertions, 7 deletions
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index bf9213b2db8f..fc9bae82ac42 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h | |||
@@ -68,6 +68,7 @@ extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan, | |||
68 | extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask); | 68 | extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask); |
69 | int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem); | 69 | int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem); |
70 | 70 | ||
71 | extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page); | ||
71 | extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); | 72 | extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); |
72 | 73 | ||
73 | static inline | 74 | static inline |
@@ -189,6 +190,11 @@ mem_cgroup_move_lists(struct page *page, enum lru_list from, enum lru_list to) | |||
189 | { | 190 | { |
190 | } | 191 | } |
191 | 192 | ||
193 | static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) | ||
194 | { | ||
195 | return NULL; | ||
196 | } | ||
197 | |||
192 | static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem) | 198 | static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem) |
193 | { | 199 | { |
194 | return 1; | 200 | return 1; |
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e0c2066495e3..b5ac61ce7346 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -1379,25 +1379,22 @@ static struct mem_cgroup *mem_cgroup_lookup(unsigned short id) | |||
1379 | return container_of(css, struct mem_cgroup, css); | 1379 | return container_of(css, struct mem_cgroup, css); |
1380 | } | 1380 | } |
1381 | 1381 | ||
1382 | static struct mem_cgroup *try_get_mem_cgroup_from_swapcache(struct page *page) | 1382 | struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) |
1383 | { | 1383 | { |
1384 | struct mem_cgroup *mem; | 1384 | struct mem_cgroup *mem = NULL; |
1385 | struct page_cgroup *pc; | 1385 | struct page_cgroup *pc; |
1386 | unsigned short id; | 1386 | unsigned short id; |
1387 | swp_entry_t ent; | 1387 | swp_entry_t ent; |
1388 | 1388 | ||
1389 | VM_BUG_ON(!PageLocked(page)); | 1389 | VM_BUG_ON(!PageLocked(page)); |
1390 | 1390 | ||
1391 | if (!PageSwapCache(page)) | ||
1392 | return NULL; | ||
1393 | |||
1394 | pc = lookup_page_cgroup(page); | 1391 | pc = lookup_page_cgroup(page); |
1395 | lock_page_cgroup(pc); | 1392 | lock_page_cgroup(pc); |
1396 | if (PageCgroupUsed(pc)) { | 1393 | if (PageCgroupUsed(pc)) { |
1397 | mem = pc->mem_cgroup; | 1394 | mem = pc->mem_cgroup; |
1398 | if (mem && !css_tryget(&mem->css)) | 1395 | if (mem && !css_tryget(&mem->css)) |
1399 | mem = NULL; | 1396 | mem = NULL; |
1400 | } else { | 1397 | } else if (PageSwapCache(page)) { |
1401 | ent.val = page_private(page); | 1398 | ent.val = page_private(page); |
1402 | id = lookup_swap_cgroup(ent); | 1399 | id = lookup_swap_cgroup(ent); |
1403 | rcu_read_lock(); | 1400 | rcu_read_lock(); |
@@ -1743,7 +1740,7 @@ int mem_cgroup_try_charge_swapin(struct mm_struct *mm, | |||
1743 | */ | 1740 | */ |
1744 | if (!PageSwapCache(page)) | 1741 | if (!PageSwapCache(page)) |
1745 | goto charge_cur_mm; | 1742 | goto charge_cur_mm; |
1746 | mem = try_get_mem_cgroup_from_swapcache(page); | 1743 | mem = try_get_mem_cgroup_from_page(page); |
1747 | if (!mem) | 1744 | if (!mem) |
1748 | goto charge_cur_mm; | 1745 | goto charge_cur_mm; |
1749 | *ptr = mem; | 1746 | *ptr = mem; |