diff options
| author | Li Zefan <lizefan@huawei.com> | 2013-09-23 04:56:01 -0400 |
|---|---|---|
| committer | Tejun Heo <tj@kernel.org> | 2013-09-23 21:44:14 -0400 |
| commit | 34c00c319ce7eddf79be0cd307acd5630addcbb8 (patch) | |
| tree | 258bfd6fe01e876feea8a05112338564dde46e05 | |
| parent | b47f77b5a2243768d5cb1f143ce5e6c28baa271a (diff) | |
memcg: convert to use cgroup id
Use cgroup id instead of css id. This is a preparation to kill css id.
Note, as memcg treat 0 as an invalid id, while cgroup id starts with 0,
we define memcg_id == cgroup_id + 1.
Signed-off-by: Li Zefan <lizefan@huawei.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Tejun Heo <tj@kernel.org>
| -rw-r--r-- | mm/memcontrol.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index aa8363ef381c..404a13a09efa 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
| @@ -488,6 +488,23 @@ static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg) | |||
| 488 | return (memcg == root_mem_cgroup); | 488 | return (memcg == root_mem_cgroup); |
| 489 | } | 489 | } |
| 490 | 490 | ||
| 491 | static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) | ||
| 492 | { | ||
| 493 | /* | ||
| 494 | * The ID of the root cgroup is 0, but memcg treat 0 as an | ||
| 495 | * invalid ID, so we return (cgroup_id + 1). | ||
| 496 | */ | ||
| 497 | return memcg->css.cgroup->id + 1; | ||
| 498 | } | ||
| 499 | |||
| 500 | static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) | ||
| 501 | { | ||
| 502 | struct cgroup_subsys_state *css; | ||
| 503 | |||
| 504 | css = css_from_id(id - 1, &mem_cgroup_subsys); | ||
| 505 | return mem_cgroup_from_css(css); | ||
| 506 | } | ||
| 507 | |||
| 491 | /* Writing them here to avoid exposing memcg's inner layout */ | 508 | /* Writing them here to avoid exposing memcg's inner layout */ |
| 492 | #if defined(CONFIG_INET) && defined(CONFIG_MEMCG_KMEM) | 509 | #if defined(CONFIG_INET) && defined(CONFIG_MEMCG_KMEM) |
| 493 | 510 | ||
| @@ -2709,15 +2726,10 @@ static void __mem_cgroup_cancel_local_charge(struct mem_cgroup *memcg, | |||
| 2709 | */ | 2726 | */ |
| 2710 | static struct mem_cgroup *mem_cgroup_lookup(unsigned short id) | 2727 | static struct mem_cgroup *mem_cgroup_lookup(unsigned short id) |
| 2711 | { | 2728 | { |
| 2712 | struct cgroup_subsys_state *css; | ||
| 2713 | |||
| 2714 | /* ID 0 is unused ID */ | 2729 | /* ID 0 is unused ID */ |
| 2715 | if (!id) | 2730 | if (!id) |
| 2716 | return NULL; | 2731 | return NULL; |
| 2717 | css = css_lookup(&mem_cgroup_subsys, id); | 2732 | return mem_cgroup_from_id(id); |
| 2718 | if (!css) | ||
| 2719 | return NULL; | ||
| 2720 | return mem_cgroup_from_css(css); | ||
| 2721 | } | 2733 | } |
| 2722 | 2734 | ||
| 2723 | struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) | 2735 | struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) |
| @@ -4232,7 +4244,7 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout) | |||
| 4232 | * css_get() was called in uncharge(). | 4244 | * css_get() was called in uncharge(). |
| 4233 | */ | 4245 | */ |
| 4234 | if (do_swap_account && swapout && memcg) | 4246 | if (do_swap_account && swapout && memcg) |
| 4235 | swap_cgroup_record(ent, css_id(&memcg->css)); | 4247 | swap_cgroup_record(ent, mem_cgroup_id(memcg)); |
| 4236 | } | 4248 | } |
| 4237 | #endif | 4249 | #endif |
| 4238 | 4250 | ||
| @@ -4284,8 +4296,8 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry, | |||
| 4284 | { | 4296 | { |
| 4285 | unsigned short old_id, new_id; | 4297 | unsigned short old_id, new_id; |
| 4286 | 4298 | ||
| 4287 | old_id = css_id(&from->css); | 4299 | old_id = mem_cgroup_id(from); |
| 4288 | new_id = css_id(&to->css); | 4300 | new_id = mem_cgroup_id(to); |
| 4289 | 4301 | ||
| 4290 | if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) { | 4302 | if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) { |
| 4291 | mem_cgroup_swap_statistics(from, false); | 4303 | mem_cgroup_swap_statistics(from, false); |
| @@ -6325,7 +6337,7 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma, | |||
| 6325 | } | 6337 | } |
| 6326 | /* There is a swap entry and a page doesn't exist or isn't charged */ | 6338 | /* There is a swap entry and a page doesn't exist or isn't charged */ |
| 6327 | if (ent.val && !ret && | 6339 | if (ent.val && !ret && |
| 6328 | css_id(&mc.from->css) == lookup_swap_cgroup_id(ent)) { | 6340 | mem_cgroup_id(mc.from) == lookup_swap_cgroup_id(ent)) { |
| 6329 | ret = MC_TARGET_SWAP; | 6341 | ret = MC_TARGET_SWAP; |
| 6330 | if (target) | 6342 | if (target) |
| 6331 | target->ent = ent; | 6343 | target->ent = ent; |
