Skip to content

Commit 34c00c3

Browse files
lizf-oshtejun
authored andcommitted
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>
1 parent b47f77b commit 34c00c3

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

‎mm/memcontrol.c‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,23 @@ static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg)
488488
return (memcg == root_mem_cgroup);
489489
}
490490

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+
491508
/* Writing them here to avoid exposing memcg's inner layout */
492509
#if defined(CONFIG_INET) && defined(CONFIG_MEMCG_KMEM)
493510

@@ -2709,15 +2726,10 @@ static void __mem_cgroup_cancel_local_charge(struct mem_cgroup *memcg,
27092726
*/
27102727
static struct mem_cgroup *mem_cgroup_lookup(unsigned short id)
27112728
{
2712-
struct cgroup_subsys_state *css;
2713-
27142729
/* ID 0 is unused ID */
27152730
if (!id)
27162731
return NULL;
2717-
css = css_lookup(&mem_cgroup_subsys, id);
2718-
if (!css)
2719-
return NULL;
2720-
return mem_cgroup_from_css(css);
2732+
return mem_cgroup_from_id(id);
27212733
}
27222734

27232735
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)
42324244
* css_get() was called in uncharge().
42334245
*/
42344246
if (do_swap_account && swapout && memcg)
4235-
swap_cgroup_record(ent, css_id(&memcg->css));
4247+
swap_cgroup_record(ent, mem_cgroup_id(memcg));
42364248
}
42374249
#endif
42384250

@@ -4284,8 +4296,8 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry,
42844296
{
42854297
unsigned short old_id, new_id;
42864298

4287-
old_id = css_id(&from->css);
4288-
new_id = css_id(&to->css);
4299+
old_id = mem_cgroup_id(from);
4300+
new_id = mem_cgroup_id(to);
42894301

42904302
if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) {
42914303
mem_cgroup_swap_statistics(from, false);
@@ -6325,7 +6337,7 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma,
63256337
}
63266338
/* There is a swap entry and a page doesn't exist or isn't charged */
63276339
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)) {
63296341
ret = MC_TARGET_SWAP;
63306342
if (target)
63316343
target->ent = ent;

0 commit comments

Comments
 (0)