Skip to content

Commit

Permalink
ck: memcg: Point wb to root memcg/blkcg when offlining to avoid zombie
Browse files Browse the repository at this point in the history
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 <yang.shi@linux.alibaba.com>
Reviewed-by: Gavin Shan <shan.gavin@linux.alibaba.com>
Signed-off-by: Xunlei Pang <xlpang@linux.alibaba.com>
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Acked-by: Caspar Zhang <caspar@linux.alibaba.com>
Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
  • Loading branch information
Xunlei Pang authored and shiloong committed Mar 12, 2021
1 parent bed50b9 commit cd5f2e4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions mm/backing-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,16 @@ void wb_memcg_offline(struct mem_cgroup *memcg)
struct bdi_writeback *wb, *next;

spin_lock_irq(&cgwb_lock);
list_for_each_entry_safe(wb, next, memcg_cgwb_list, memcg_node)
list_for_each_entry_safe(wb, next, memcg_cgwb_list, memcg_node) {
percpu_ref_get(&wb->refcnt);
cgwb_kill(wb);
if (wb->memcg_css) {
css_put(wb->memcg_css);
wb->memcg_css = &root_mem_cgroup->css;
css_get(wb->memcg_css);
}
percpu_ref_put(&wb->refcnt);
}
memcg_cgwb_list->next = NULL; /* prevent new wb's */
spin_unlock_irq(&cgwb_lock);
}
Expand All @@ -889,8 +897,16 @@ void wb_blkcg_offline(struct blkcg *blkcg)
struct bdi_writeback *wb, *next;

spin_lock_irq(&cgwb_lock);
list_for_each_entry_safe(wb, next, &blkcg->cgwb_list, blkcg_node)
list_for_each_entry_safe(wb, next, &blkcg->cgwb_list, blkcg_node) {
percpu_ref_get(&wb->refcnt);
cgwb_kill(wb);
if (wb->memcg_css) {
css_put(wb->memcg_css);
wb->memcg_css = &root_mem_cgroup->css;
css_get(wb->memcg_css);
}
percpu_ref_put(&wb->refcnt);
}
blkcg->cgwb_list.next = NULL; /* prevent new wb's */
spin_unlock_irq(&cgwb_lock);
}
Expand Down

0 comments on commit cd5f2e4

Please sign in to comment.