Skip to content

Commit 675d6c9

Browse files
rgushchinakpm00
authored andcommitted
mm: kmem: make memcg keep a reference to the original objcg
Keep a reference to the original objcg object for the entire life of a memcg structure. This allows to simplify the synchronization on the kernel memory allocation paths: pinning a (live) memcg will also pin the corresponding objcg. The memory overhead of this change is minimal because object cgroups usually outlive their corresponding memory cgroups even without this change, so it's only an additional pointer per memcg. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Roman Gushchin (Cruise) <[email protected]> Tested-by: Naresh Kamboju <[email protected]> Acked-by: Shakeel Butt <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Cc: David Rientjes <[email protected]> Cc: Dennis Zhou <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1aacbd3 commit 675d6c9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/linux/memcontrol.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,13 @@ struct mem_cgroup {
289289

290290
#ifdef CONFIG_MEMCG_KMEM
291291
int kmemcg_id;
292-
struct obj_cgroup __rcu *objcg;
292+
/*
293+
* memcg->objcg is wiped out as a part of the objcg repaprenting
294+
* process. memcg->orig_objcg preserves a pointer (and a reference)
295+
* to the original objcg until the end of live of memcg.
296+
*/
297+
struct obj_cgroup __rcu *objcg;
298+
struct obj_cgroup *orig_objcg;
293299
/* list of inherited objcgs, protected by objcg_lock */
294300
struct list_head objcg_list;
295301
#endif

mm/memcontrol.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,6 +3899,8 @@ static int memcg_online_kmem(struct mem_cgroup *memcg)
38993899

39003900
objcg->memcg = memcg;
39013901
rcu_assign_pointer(memcg->objcg, objcg);
3902+
obj_cgroup_get(objcg);
3903+
memcg->orig_objcg = objcg;
39023904

39033905
static_branch_enable(&memcg_kmem_online_key);
39043906

@@ -5406,6 +5408,9 @@ static void __mem_cgroup_free(struct mem_cgroup *memcg)
54065408
{
54075409
int node;
54085410

5411+
if (memcg->orig_objcg)
5412+
obj_cgroup_put(memcg->orig_objcg);
5413+
54095414
for_each_node(node)
54105415
free_mem_cgroup_per_node_info(memcg, node);
54115416
kfree(memcg->vmstats);

0 commit comments

Comments
 (0)