memcg: reparent charges of children before processing parent
Subsystems (3)
PATCH 1/2 memcg: reparent charges of children before processing parent
From: Filipe Brandenburger <[email protected]>
Sometimes the cleanup after memcg hierarchy testing gets stuck in mem_cgroup_reparent_charges(), unable to bring non-kmem usage down to 0.
There may turn out to be several causes, but a major cause is this: the workitem to offline parent can get run before workitem to offline child; parent's mem_cgroup_reparent_charges() circles around waiting for the child's pages to be reparented to its lrus, but it's holding cgroup_mutex which prevents the child from reaching its mem_cgroup_reparent_charges().
Further testing showed that an ordered workqueue for cgroup_destroy_wq is not always good enough: percpu_ref_kill_and_confirm's call_rcu_sched stage on the way can mess up the order before reaching the workqueue.
Instead, when offlining a memcg, call mem_cgroup_reparent_charges() on all its children (and grandchildren, in the correct order) to have their charges reparented first.
---
Or, you may prefer my alternative cgroup.c approach in 2/2:
there's no need for both. Please note that neither of these patches attempts to handle the unlikely case of racy charges made to child after its offline, but parent's offline coming before child's free:
mem_cgroup_css_free()'s backstop call to mem_cgroup_reparent_charges() cannot help in that case, with or without these patches. Fixing that would have to be a separate effort - Michal's?
mm/memcontrol.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
mm/memcontrol.c +9 -1
@@ -6595,6 +6595,7 @@ static void mem_cgroup_css_offline(struc {struct mem_cgroup *memcg =mem_cgroup_from_css (css);struct mem_cgroup_event *event, *tmp; +struct cgroup_subsys_state *iter;/* * Unregister events and notify userspace.
@@ -6611,7 +6612,14 @@ static void mem_cgroup_css_offline(struckmem_cgroup_css_offline (memcg);mem_cgroup_invalidate_reclaim_iterators (memcg); -mem_cgroup_reparent_charges (memcg); + +/* +* This requires that offlining is serialized. Right now that is +* guaranteed because css_killed_work_fn() holds the cgroup_mutex. +*/ +css_for_each_descendant_post (iter, css) +mem_cgroup_reparent_charges (mem_cgroup_from_css (iter)); +mem_cgroup_destroy_all_caches (memcg);vmpressure_cleanup (&memcg->vmpressure); }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hello,
Quoted 23 lines · Hugh Dickins
From: Filipe Brandenburger <[email protected]>
Sometimes the cleanup after memcg hierarchy testing gets stuck in
mem_cgroup_reparent_charges(), unable to bring non-kmem usage down to 0.There may turn out to be several causes, but a major cause is this: the workitem to offline parent can get run before workitem to offline child; parent's
mem_cgroup_reparent_charges()circles around waiting for the child's pages to be reparented to its lrus, but it's holdingcgroup_mutexwhich prevents the child from reaching itsmem_cgroup_reparent_charges().Further testing showed that an ordered workqueue for
cgroup_destroy_wqis not always good enough: percpu_ref_kill_and_confirm'scall_rcu_schedstage on the way can mess up the order before reaching the workqueue.Instead, when offlining a memcg, call
mem_cgroup_reparent_charges()on all its children (and grandchildren, in the correct order) to have their charges reparented first.Fixes e5fca243abae ("cgroup: use a dedicated workqueue for cgroup destruction")Signed-off-by Filipe Brandenburger <[email protected]>Signed-off-by Hugh Dickins <[email protected]>Cc [email protected] # v3.10+ (but will need extra care)
Quoted 8 lines
---
Or, you may prefer my alternativecgroup.capproach in 2/2:
there's no need for both. Please note that neither of these patches attempts to handle the unlikely case of racy charges made to child after its offline, but parent's offline coming before child's free:
mem_cgroup_css_free()'s backstop call tomem_cgroup_reparent_charges()cannot help in that case, with or without these patches. Fixing that would have to be a separate effort - Michal's?
I've changed my mind several times now but I think it'd be a better idea to stick to this patch, at least for now. This one is easier for -stable backport and it looks like the requirements for ordering ->css_offline() might go away depending on how reparenting changes work out.
Michal, Johannes, can you guys please ack this one if you guys agree?
Thanks.
Signature · 7 lines
tejun -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Hugh Dickins
From: Filipe Brandenburger <[email protected]>
Sometimes the cleanup after memcg hierarchy testing gets stuck in
mem_cgroup_reparent_charges(), unable to bring non-kmem usage down to 0.There may turn out to be several causes, but a major cause is this: the workitem to offline parent can get run before workitem to offline child; parent's
mem_cgroup_reparent_charges()circles around waiting for the child's pages to be reparented to its lrus, but it's holdingcgroup_mutexwhich prevents the child from reaching itsmem_cgroup_reparent_charges().
Quoted 3 lines
Further testing showed that an ordered workqueue for
cgroup_destroy_wqis not always good enough: percpu_ref_kill_and_confirm'scall_rcu_schedstage on the way can mess up the order before reaching the workqueue.
This whole code path is so complicated by different types of delayed work that I am not wondering that we have missed that :/
Quoted 3 lines
Instead, when offlining a memcg, call
mem_cgroup_reparent_charges()on all its children (and grandchildren, in the correct order) to have their charges reparented first.
That is basically what I was suggesting
http://marc.info/?l=linux-mm&m=139178386407184&w=2 as #1 option. I cannot say I would like it and I think that reparenting LRUs in css_offline and then reparent the remaining charges from css_free is a better solution but let's keep this for later.
Quoted 4 lines
Fixes e5fca243abae ("cgroup: use a dedicated workqueue for cgroup destruction")Signed-off-by Filipe Brandenburger <[email protected]>Signed-off-by Hugh Dickins <[email protected]>Cc [email protected] # v3.10+ (but will need extra care)
OK, I guess we should go with this one because it describes both the problem in memcg offlining and requirements from the cgroup core so the later approach can build on top of it.
Quoted 8 lines
---
Or, you may prefer my alternativecgroup.capproach in 2/2:
there's no need for both. Please note that neither of these patches attempts to handle the unlikely case of racy charges made to child after its offline, but parent's offline coming before child's free:
mem_cgroup_css_free()'s backstop call tomem_cgroup_reparent_charges()cannot help in that case, with or without these patches. Fixing that would have to be a separate effort - Michal's?
I plan to implement the LRU care for css_offline and charge drain for css_free later on but I have quite some work on my plate currently so I cannot promis it will be done right now. I hope to have it soon though.
Quoted 29 lines
mm/memcontrol.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)mm/memcontrol.c +9
-1@@ -6595,6 +6595,7 @@ static void mem_cgroup_css_offline(struc {struct mem_cgroup *memcg =mem_cgroup_from_css (css);struct mem_cgroup_event *event, *tmp; +struct cgroup_subsys_state *iter;/* * Unregister events and notify userspace. @@ -6611,7 +6612,14 @@ static void mem_cgroup_css_offline(struckmem_cgroup_css_offline (memcg);mem_cgroup_invalidate_reclaim_iterators (memcg); -mem_cgroup_reparent_charges (memcg); + +/* +* This requires that offlining is serialized. Right now that is +* guaranteed because css_killed_work_fn() holds the cgroup_mutex. +*/ +css_for_each_descendant_post (iter, css) +mem_cgroup_reparent_charges (mem_cgroup_from_css (iter)); +mem_cgroup_destroy_all_caches (memcg);vmpressure_cleanup (&memcg->vmpressure); }
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Tejun Heo
maintainerHello,
Quoted 6 lines · Michal Hocko
Quoted 3 lines
Further testing showed that an ordered workqueue for
cgroup_destroy_wqis not always good enough: percpu_ref_kill_and_confirm'scall_rcu_schedstage on the way can mess up the order before reaching the workqueue.This whole code path is so complicated by different types of delayed work that I am not wondering that we have missed that :/
Yeah, I know. Good part of the complexity comes from RCU -> wq bouncing. I wonder whether we just should bite the bullet and add something along the line of call_rcu_work(). The other part is percpu ref shutdown. For me that part is easier to swallow, as the benefits are quite clear.
Quoted 9 lines
Quoted 3 lines
Instead, when offlining a memcg, call
mem_cgroup_reparent_charges()on all its children (and grandchildren, in the correct order) to have their charges reparented first.That is basically what I was suggesting
http://marc.info/?l=linux-mm&m=139178386407184&w=2 as #1 option. I cannot say I would like it and I think that reparenting LRUs incss_offlineand then reparent the remaining charges fromcss_freeis a better solution but let's keep this for later.
I'm kinda wishing the reparenting things works out. Even if that involves a bit of overhead at offline, I think it'd be worthwhile to be able to follow the same object lifetime rules as other controllers, as long as the overhead is reasonable.
Thanks.
Signature · 7 lines
tejun -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
I wanted to give you small feedback, that this patch successfully fixes the problem with reparent_charges on our cluster. Thank you very much for finding and fixing this one!
Quoted 51 lines · On Wednesday 12 February 2014 15:03:31 Hugh Dickins wrote:
From: Filipe Brandenburger <[email protected]>
Sometimes the cleanup after memcg hierarchy testing gets stuck in
mem_cgroup_reparent_charges(), unable to bring non-kmem usage down to 0.There may turn out to be several causes, but a major cause is this: the workitem to offline parent can get run before workitem to offline child; parent's
mem_cgroup_reparent_charges()circles around waiting for the child's pages to be reparented to its lrus, but it's holdingcgroup_mutexwhich prevents the child from reaching itsmem_cgroup_reparent_charges().Further testing showed that an ordered workqueue for
cgroup_destroy_wqis not always good enough: percpu_ref_kill_and_confirm'scall_rcu_schedstage on the way can mess up the order before reaching the workqueue.Instead, when offlining a memcg, call
mem_cgroup_reparent_charges()on all its children (and grandchildren, in the correct order) to have their charges reparented first.Fixes e5fca243abae ("cgroup: use a dedicated workqueue for cgroupdestruction") Signed-off-by: Filipe Brandenburger <[email protected]>
Signed-off-by Hugh Dickins <[email protected]>Cc [email protected] # v3.10+ (but will need extra care)---
Or, you may prefer my alternativecgroup.capproach in 2/2:
there's no need for both. Please note that neither of these patches attempts to handle the unlikely case of racy charges made to child after its offline, but parent's offline coming before child's free:
mem_cgroup_css_free()'s backstop call tomem_cgroup_reparent_charges()cannot help in that case, with or without these patches. Fixing that would have to be a separate effort - Michal's?mm/memcontrol.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)mm/memcontrol.c +2
-1@@ -6595,6 +6595,7 @@ static void mem_cgroup_css_offline(struc {struct mem_cgroup *memcg =mem_cgroup_from_css (css);struct mem_cgroup_event *event, *tmp; +struct cgroup_subsys_state *iter;/* * Unregister events and notify userspace. @@ -6611,7 +6612,14 @@ static void mem_cgroup_css_offline(struckmem_cgroup_css_offline (memcg);mem_cgroup_invalidate_reclaim_iterators (memcg); -mem_cgroup_reparent_charges (memcg); +
mm/memcontrol.c static void mem_cgroup_css_offline(struc · line 6625
Quoted 10 lines
mm/memcontrol.c +7
-0+/* +* This requires that offlining is serialized. Right now that is +* guaranteed because css_killed_work_fn() holds the cgroup_mutex. +*/ +css_for_each_descendant_post (iter, css) +mem_cgroup_reparent_charges (mem_cgroup_from_css (iter)); +mem_cgroup_destroy_all_caches (memcg);vmpressure_cleanup (&memcg->vmpressure); }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Markus Blank-Burian
I wanted to give you small feedback, that this patch successfully fixes the problem with
reparent_chargeson our cluster. Thank you very much for finding and fixing this one!
That's great to hear, Markus: thanks a lot for letting us know. All credit to Filipe, who had the idea of what might be going wrong, and the best patch to fix it.
Hugh
Quoted 50 lines · On Wednesday 12 February 2014 15:03:31 Hugh Dickins wrote:
Quoted 48 lines
From: Filipe Brandenburger <[email protected]>
Sometimes the cleanup after memcg hierarchy testing gets stuck in
mem_cgroup_reparent_charges(), unable to bring non-kmem usage down to 0.There may turn out to be several causes, but a major cause is this: the workitem to offline parent can get run before workitem to offline child; parent's
mem_cgroup_reparent_charges()circles around waiting for the child's pages to be reparented to its lrus, but it's holdingcgroup_mutexwhich prevents the child from reaching itsmem_cgroup_reparent_charges().Further testing showed that an ordered workqueue for
cgroup_destroy_wqis not always good enough: percpu_ref_kill_and_confirm'scall_rcu_schedstage on the way can mess up the order before reaching the workqueue.Instead, when offlining a memcg, call
mem_cgroup_reparent_charges()on all its children (and grandchildren, in the correct order) to have their charges reparented first.Fixes e5fca243abae ("cgroup: use a dedicated workqueue for cgroupdestruction") Signed-off-by: Filipe Brandenburger <[email protected]>
Signed-off-by Hugh Dickins <[email protected]>Cc [email protected] # v3.10+ (but will need extra care)---
Or, you may prefer my alternativecgroup.capproach in 2/2:
there's no need for both. Please note that neither of these patches attempts to handle the unlikely case of racy charges made to child after its offline, but parent's offline coming before child's free:
mem_cgroup_css_free()'s backstop call tomem_cgroup_reparent_charges()cannot help in that case, with or without these patches. Fixing that would have to be a separate effort - Michal's?mm/memcontrol.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)mm/memcontrol.c +1
-0@@ -6595,6 +6595,7 @@ static void mem_cgroup_css_offline(struc {struct mem_cgroup *memcg =mem_cgroup_from_css (css);struct mem_cgroup_event *event, *tmp; +struct cgroup_subsys_state *iter;/* * Unregister events and notify userspace. @@ -6611,7 +6612,14 @@ static void mem_cgroup_css_offline(struckmem_cgroup_css_offline (memcg);
Quoted 13 lines
mm/memcontrol.c static void mem_cgroup_css_offline(struc · line 6625
Quoted 13 lines
mm/memcontrol.c +8
-1mem_cgroup_invalidate_reclaim_iterators (memcg); -mem_cgroup_reparent_charges (memcg); + +/* +* This requires that offlining is serialized. Right now that is +* guaranteed because css_killed_work_fn() holds the cgroup_mutex. +*/ +css_for_each_descendant_post (iter, css) +mem_cgroup_reparent_charges (mem_cgroup_from_css (iter)); +mem_cgroup_destroy_all_caches (memcg);vmpressure_cleanup (&memcg->vmpressure); }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>