Skip to content

Commit 8d42abb

Browse files
ryncsnakpm00
authored andcommitted
mm/list_lru: code clean up for reparenting
No feature change, just change of code structure and fix comment. The list lrus are not empty until memcg_reparent_list_lru_node() calls are all done, so the comments in memcg_offline_kmem were slightly inaccurate. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kairui Song <[email protected]> Reviewed-by: Muchun Song <[email protected]> Acked-by: Shakeel Butt <[email protected]> Cc: Chengming Zhou <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Qi Zheng <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Waiman Long <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 78c0ed0 commit 8d42abb

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

mm/list_lru.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -421,35 +421,16 @@ static void memcg_reparent_list_lru_node(struct list_lru *lru, int nid,
421421
spin_unlock_irq(&nlru->lock);
422422
}
423423

424-
static void memcg_reparent_list_lru(struct list_lru *lru,
425-
int src_idx, struct mem_cgroup *dst_memcg)
426-
{
427-
int i;
428-
429-
for_each_node(i)
430-
memcg_reparent_list_lru_node(lru, i, src_idx, dst_memcg);
431-
432-
memcg_list_lru_free(lru, src_idx);
433-
}
434-
435424
void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *parent)
436425
{
437426
struct cgroup_subsys_state *css;
438427
struct list_lru *lru;
439-
int src_idx = memcg->kmemcg_id;
428+
int src_idx = memcg->kmemcg_id, i;
440429

441430
/*
442431
* Change kmemcg_id of this cgroup and all its descendants to the
443432
* parent's id, and then move all entries from this cgroup's list_lrus
444433
* to ones of the parent.
445-
*
446-
* After we have finished, all list_lrus corresponding to this cgroup
447-
* are guaranteed to remain empty. So we can safely free this cgroup's
448-
* list lrus in memcg_list_lru_free().
449-
*
450-
* Changing ->kmemcg_id to the parent can prevent memcg_list_lru_alloc()
451-
* from allocating list lrus for this cgroup after memcg_list_lru_free()
452-
* call.
453434
*/
454435
rcu_read_lock();
455436
css_for_each_descendant_pre(css, &memcg->css) {
@@ -460,9 +441,23 @@ void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *paren
460441
}
461442
rcu_read_unlock();
462443

444+
/*
445+
* With kmemcg_id set to parent, holding the lock of each list_lru_node
446+
* below can prevent list_lru_{add,del,isolate} from touching the lru,
447+
* safe to reparent.
448+
*/
463449
mutex_lock(&list_lrus_mutex);
464-
list_for_each_entry(lru, &memcg_list_lrus, list)
465-
memcg_reparent_list_lru(lru, src_idx, parent);
450+
list_for_each_entry(lru, &memcg_list_lrus, list) {
451+
for_each_node(i)
452+
memcg_reparent_list_lru_node(lru, i, src_idx, parent);
453+
454+
/*
455+
* Here all list_lrus corresponding to the cgroup are guaranteed
456+
* to remain empty, we can safely free this lru, any further
457+
* memcg_list_lru_alloc() call will simply bail out.
458+
*/
459+
memcg_list_lru_free(lru, src_idx);
460+
}
466461
mutex_unlock(&list_lrus_mutex);
467462
}
468463

mm/memcontrol.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,13 +3111,6 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg)
31113111
parent = root_mem_cgroup;
31123112

31133113
memcg_reparent_objcgs(memcg, parent);
3114-
3115-
/*
3116-
* After we have finished memcg_reparent_objcgs(), all list_lrus
3117-
* corresponding to this cgroup are guaranteed to remain empty.
3118-
* The ordering is imposed by list_lru_node->lock taken by
3119-
* memcg_reparent_list_lrus().
3120-
*/
31213114
memcg_reparent_list_lrus(memcg, parent);
31223115
}
31233116

0 commit comments

Comments
 (0)