diff options
author | Wanpeng Li <liwanp@linux.vnet.ibm.com> | 2012-07-31 19:46:01 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-31 21:42:49 -0400 |
commit | b214514592d2dcb0b9d14ee8dd14f3699e3b0a84 (patch) | |
tree | 317258b7f9229e56a26373c81551d24e7b83142f /mm/memcontrol.c | |
parent | c3b94f44fcb0725471ecebb701c077a0ed67bd07 (diff) |
memcg: add mem_cgroup_from_css() helper
Add a mem_cgroup_from_css() helper to replace open-coded invokations of
container_of(). To clarify the code and to add a little more type safety.
[akpm@linux-foundation.org: fix extensive breakage]
Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Gavin Shan <shangw@linux.vnet.ibm.com>
Cc: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Cc: Gavin Shan <shangw@linux.vnet.ibm.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r-- | mm/memcontrol.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b06833f2b89e..795e525afaba 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -405,6 +405,12 @@ enum charge_type { | |||
405 | static void mem_cgroup_get(struct mem_cgroup *memcg); | 405 | static void mem_cgroup_get(struct mem_cgroup *memcg); |
406 | static void mem_cgroup_put(struct mem_cgroup *memcg); | 406 | static void mem_cgroup_put(struct mem_cgroup *memcg); |
407 | 407 | ||
408 | static inline | ||
409 | struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s) | ||
410 | { | ||
411 | return container_of(s, struct mem_cgroup, css); | ||
412 | } | ||
413 | |||
408 | /* Writing them here to avoid exposing memcg's inner layout */ | 414 | /* Writing them here to avoid exposing memcg's inner layout */ |
409 | #ifdef CONFIG_MEMCG_KMEM | 415 | #ifdef CONFIG_MEMCG_KMEM |
410 | #include <net/sock.h> | 416 | #include <net/sock.h> |
@@ -862,9 +868,8 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page) | |||
862 | 868 | ||
863 | struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont) | 869 | struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont) |
864 | { | 870 | { |
865 | return container_of(cgroup_subsys_state(cont, | 871 | return mem_cgroup_from_css( |
866 | mem_cgroup_subsys_id), struct mem_cgroup, | 872 | cgroup_subsys_state(cont, mem_cgroup_subsys_id)); |
867 | css); | ||
868 | } | 873 | } |
869 | 874 | ||
870 | struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) | 875 | struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) |
@@ -877,8 +882,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) | |||
877 | if (unlikely(!p)) | 882 | if (unlikely(!p)) |
878 | return NULL; | 883 | return NULL; |
879 | 884 | ||
880 | return container_of(task_subsys_state(p, mem_cgroup_subsys_id), | 885 | return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id)); |
881 | struct mem_cgroup, css); | ||
882 | } | 886 | } |
883 | 887 | ||
884 | struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm) | 888 | struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm) |
@@ -964,8 +968,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, | |||
964 | css = css_get_next(&mem_cgroup_subsys, id + 1, &root->css, &id); | 968 | css = css_get_next(&mem_cgroup_subsys, id + 1, &root->css, &id); |
965 | if (css) { | 969 | if (css) { |
966 | if (css == &root->css || css_tryget(css)) | 970 | if (css == &root->css || css_tryget(css)) |
967 | memcg = container_of(css, | 971 | memcg = mem_cgroup_from_css(css); |
968 | struct mem_cgroup, css); | ||
969 | } else | 972 | } else |
970 | id = 0; | 973 | id = 0; |
971 | rcu_read_unlock(); | 974 | rcu_read_unlock(); |
@@ -2494,7 +2497,7 @@ static struct mem_cgroup *mem_cgroup_lookup(unsigned short id) | |||
2494 | css = css_lookup(&mem_cgroup_subsys, id); | 2497 | css = css_lookup(&mem_cgroup_subsys, id); |
2495 | if (!css) | 2498 | if (!css) |
2496 | return NULL; | 2499 | return NULL; |
2497 | return container_of(css, struct mem_cgroup, css); | 2500 | return mem_cgroup_from_css(css); |
2498 | } | 2501 | } |
2499 | 2502 | ||
2500 | struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) | 2503 | struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) |