Skip to content

Commit cd5f2e4

Browse files
Xunlei Pangshiloong
authored andcommitted
ck: memcg: Point wb to root memcg/blkcg when offlining to avoid zombie
fix #32630110 After turning off the memcg kmem charging, we still suffer from various zombie memcg problems on production environment because of its non-zero reference count from both page caches and per-memcg writeback related structure(bdi_writeback takes a reference). After we reclaimed all the page caches of the zombie memcg, it still can't be dropped due to its bdi_writeback. bdi_writeback is further referenced by the inodes of files, so the memcg can't be truely released until the inodes are destroyed afterwards which is quite unlikely in short term. When memcg is offlining, change it's bdi_writeback to root, and call css_put to formally release it. We've tested on product environment, it yields pretty good effect. Ditto for wb_blkcg_offline(). Reviewed-by: Yang Shi <[email protected]> Reviewed-by: Gavin Shan <[email protected]> Signed-off-by: Xunlei Pang <[email protected]> Signed-off-by: Joseph Qi <[email protected]> Acked-by: Caspar Zhang <[email protected]> Signed-off-by: Hao Xu <[email protected]> Acked-by: Joseph Qi <[email protected]>
1 parent bed50b9 commit cd5f2e4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

mm/backing-dev.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,16 @@ void wb_memcg_offline(struct mem_cgroup *memcg)
872872
struct bdi_writeback *wb, *next;
873873

874874
spin_lock_irq(&cgwb_lock);
875-
list_for_each_entry_safe(wb, next, memcg_cgwb_list, memcg_node)
875+
list_for_each_entry_safe(wb, next, memcg_cgwb_list, memcg_node) {
876+
percpu_ref_get(&wb->refcnt);
876877
cgwb_kill(wb);
878+
if (wb->memcg_css) {
879+
css_put(wb->memcg_css);
880+
wb->memcg_css = &root_mem_cgroup->css;
881+
css_get(wb->memcg_css);
882+
}
883+
percpu_ref_put(&wb->refcnt);
884+
}
877885
memcg_cgwb_list->next = NULL; /* prevent new wb's */
878886
spin_unlock_irq(&cgwb_lock);
879887
}
@@ -889,8 +897,16 @@ void wb_blkcg_offline(struct blkcg *blkcg)
889897
struct bdi_writeback *wb, *next;
890898

891899
spin_lock_irq(&cgwb_lock);
892-
list_for_each_entry_safe(wb, next, &blkcg->cgwb_list, blkcg_node)
900+
list_for_each_entry_safe(wb, next, &blkcg->cgwb_list, blkcg_node) {
901+
percpu_ref_get(&wb->refcnt);
893902
cgwb_kill(wb);
903+
if (wb->memcg_css) {
904+
css_put(wb->memcg_css);
905+
wb->memcg_css = &root_mem_cgroup->css;
906+
css_get(wb->memcg_css);
907+
}
908+
percpu_ref_put(&wb->refcnt);
909+
}
894910
blkcg->cgwb_list.next = NULL; /* prevent new wb's */
895911
spin_unlock_irq(&cgwb_lock);
896912
}

0 commit comments

Comments
 (0)