Skip to contentSkip to conversation

mm, memcg: reset low limit during memcg offlining

PATCH In review Roman Gushchin 5 participants 14 messages Jul 25, 2017 – Jul 27, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm, memcg: reset low limit during memcg offlining

A removed memory cgroup with a defined low limit and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

Fix this issue by zeroing memcg->low during memcg offlining.

---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +2 -0
index aed11b2d0251..2aa204b8f9fd 100644
@@ -4300,6 +4300,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 	}
 	spin_unlock(&memcg->event_list_lock);
 
+	memcg->low = 0;
+
 	memcg_offline_kmem(memcg);
 	wb_memcg_offline(memcg);
 
Signature · 7 lines
2.13.3

--
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>
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Roman Gushchin

A removed memory cgroup with a defined low limit and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

Quoted 1 line

Fix this issue by zeroing memcg->low during memcg offlining.

Very well spotted! This goes all the way down to low limit inclusion AFAICS. I would be even tempted to mark it for stable because hiding some memory from reclaim basically indefinitely is not good. We might have been just lucky nobody has noticed that yet.

Fixes 241994ed8649 ("mm: memcontrol: default hierarchy interface for memory")
Quoted 9 lines

Thanks!

Quoted 19 lines
---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +2 -0
index aed11b2d0251..2aa204b8f9fd 100644
@@ -4300,6 +4300,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 	}
 	spin_unlock(&memcg->event_list_lock);
 
+	memcg->low = 0;
+
 	memcg_offline_kmem(memcg);
 	wb_memcg_offline(memcg);
 
Signature · 1 line
2.13.3
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>
#2 lore raw
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Roman Gushchin

A removed memory cgroup with a defined low limit and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

Quoted 6 lines
Quoted 1 line

Fix this issue by zeroing memcg->low during memcg offlining.

Very well spotted! This goes all the way down to low limit inclusion AFAICS. I would be even tempted to mark it for stable because hiding some memory from reclaim basically indefinitely is not good. We might have been just lucky nobody has noticed that yet.

I believe it's because there are not so many actual low limit users, and those who do, are using some offstream patches to mitigate this issue.

Thanks!

Roman

--
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>

#3 lore raw
In reply to Roman Gushchin
Quoted 32 lines · Roman Gushchin

A removed memory cgroup with a defined low limit and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

Fix this issue by zeroing memcg->low during memcg offlining.

---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +0 -0
index aed11b2d0251..2aa204b8f9fd 100644

mm/memcontrol.c static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) · line 4307

Quoted 8 lines
mm/memcontrol.c +2 -0
@@ -4300,6 +4300,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 	}
 	spin_unlock(&memcg->event_list_lock);
 
+	memcg->low = 0;
+
 	memcg_offline_kmem(memcg);
 	wb_memcg_offline(memcg);
 

We already have that - see mem_cgroup_css_reset().

#4 lore raw
Quoted 36 lines · Vladimir Davydov
Quoted 35 lines · Roman Gushchin

A removed memory cgroup with a defined low limit and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

Fix this issue by zeroing memcg->low during memcg offlining.

---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +0 -0
index aed11b2d0251..2aa204b8f9fd 100644
@@ -4300,6 +4300,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 	}
 	spin_unlock(&memcg->event_list_lock);
 
Quoted 7 lines

mm/memcontrol.c static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) · line 4307

Quoted 5 lines
mm/memcontrol.c +2 -0
+	memcg->low = 0;
+
 	memcg_offline_kmem(memcg);
 	wb_memcg_offline(memcg);
 

We already have that - see mem_cgroup_css_reset().

Hm, I see...

But are you sure, that calling mem_cgroup_css_reset() from offlining path is always a good idea?

As I understand, css_reset() callback is intended to _completely_ disable all limits, as if there were no cgroup at all. And it's main purpose to be called when controllers are detached from the hierarhy.

Offlining is different: some limits make perfect sence after offlining (e.g. we want to limit the writeback speed), and other might be tweaked (e.g. we can set soft limit to prioritize reclaiming of abandoned cgroups).

So, I'd prefer to move this code to the offlining callback, and not to call css_reset.

But, anyway, thanks for pointing at the mem_cgroup_css_reset().

Roman

maintainer
#5 lore raw
Quoted 45 lines · Roman Gushchin
Quoted 36 lines · Vladimir Davydov
Quoted 35 lines · Roman Gushchin

A removed memory cgroup with a defined low limit and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

Fix this issue by zeroing memcg->low during memcg offlining.

---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +0 -0
index aed11b2d0251..2aa204b8f9fd 100644
@@ -4300,6 +4300,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 	}
 	spin_unlock(&memcg->event_list_lock);
 
Quoted 7 lines

mm/memcontrol.c static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) · line 4307

Quoted 5 lines
mm/memcontrol.c +2 -0
+	memcg->low = 0;
+
 	memcg_offline_kmem(memcg);
 	wb_memcg_offline(memcg);
 

We already have that - see mem_cgroup_css_reset().

Quoted 4 lines

Hm, I see...

But are you sure, that calling mem_cgroup_css_reset() from offlining path is always a good idea?

Well, originally I wanted to suggest the same but then I asked the very same question and couldn't answer it myself. memcg_offline_kmem feels much more generic.

Quoted 3 lines

As I understand, css_reset() callback is intended to _completely_ disable all limits, as if there were no cgroup at all. And it's main purpose to be called when controllers are detached from the hierarhy.

yes, that is my understanding as well.

Quoted 3 lines

Offlining is different: some limits make perfect sence after offlining (e.g. we want to limit the writeback speed), and other might be tweaked (e.g. we can set soft limit to prioritize reclaiming of abandoned cgroups).

and the writeback path was exactly the one that triggered my suspicious...

Signature · 2 lines
Michal Hocko
SUSE Labs
#6 lore raw
In reply to Roman Gushchin
Quoted 45 lines · Roman Gushchin
Quoted 36 lines · Vladimir Davydov
Quoted 35 lines · Roman Gushchin

A removed memory cgroup with a defined low limit and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

Fix this issue by zeroing memcg->low during memcg offlining.

---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +0 -0
index aed11b2d0251..2aa204b8f9fd 100644
@@ -4300,6 +4300,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 	}
 	spin_unlock(&memcg->event_list_lock);
 
Quoted 7 lines

mm/memcontrol.c static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) · line 4307

Quoted 5 lines
mm/memcontrol.c +2 -0
+	memcg->low = 0;
+
 	memcg_offline_kmem(memcg);
 	wb_memcg_offline(memcg);
 

We already have that - see mem_cgroup_css_reset().

Quoted 7 lines

Hm, I see...

But are you sure, that calling mem_cgroup_css_reset() from offlining path is always a good idea?

As I understand, css_reset() callback is intended to _completely_ disable all limits, as if there were no cgroup at all.

But that's exactly what cgroup offline is: deletion of a cgroup as if it never existed. The fact that we leave the zombie dangling until all pages charged to the cgroup are gone is an implementation detail. IIRC we would "reparent" those charges and delete the mem_cgroup right away if it were not inherently racy.

Quoted 6 lines

And it's main purpose to be called
when controllers are detached from the hierarhy.

Offlining is different: some limits make perfect sence after offlining (e.g. we want to limit the writeback speed), and other might be tweaked (e.g. we can set soft limit to prioritize reclaiming of abandoned cgroups).

The user can't tweak limits of an offline cgroup, because the cgroup directory no longer exist. So IMHO resetting all limits is reasonable. If you want to keep the cgroup limits effective, you shouldn't have deleted it in the first place, I suppose.

You might also want to check out this:

http://www.spinics.net/lists/linux-mm/msg102995.html

Quoted 5 lines

So, I'd prefer to move this code to the offlining callback, and not to call css_reset.

But, anyway, thanks for pointing at the mem_cgroup_css_reset().

maintainer
#7 lore raw

Hello, Vladimir.

Quoted 8 lines · Vladimir Davydov
Quoted 2 lines

As I understand, css_reset() callback is intended to _completely_ disable all limits, as if there were no cgroup at all.

But that's exactly what cgroup offline is: deletion of a cgroup as if it never existed. The fact that we leave the zombie dangling until all pages charged to the cgroup are gone is an implementation detail. IIRC we would "reparent" those charges and delete the mem_cgroup right away if it were not inherently racy.

That may be true for memcg but not in general. Think about writeback IOs servicing dirty pages of a removed cgroup. Removing a cgroup shouldn't grant it more resources than when it was alive and changing the membership to the parent will break that. For memcg, they seem the same just because no new major consumption can be generated after removal.

Quoted 4 lines

The user can't tweak limits of an offline cgroup, because the cgroup directory no longer exist. So IMHO resetting all limits is reasonable. If you want to keep the cgroup limits effective, you shouldn't have deleted it in the first place, I suppose.

I don't think that's the direction we wanna go. Granting more resources on removal is surprising.

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>
#8 lore raw

PATCH 1/2 mm, memcg: reset memory.low during memcg offlining

In reply to Vladimir Davydov

A removed memory cgroup with a defined memory.low and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

This problem was fixed earlier by commit fa06235b8eb0 ("cgroup: reset css on destruction"), but it's not a best way to do it, as we can't really reset all limits/counters during cgroup offlining.

---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +2 -0
index d61133e6af99..7b24210596ea 100644
@@ -4300,6 +4300,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 	}
 	spin_unlock(&memcg->event_list_lock);
 
+	memcg->low = 0;
+
 	memcg_offline_kmem(memcg);
 	wb_memcg_offline(memcg);
 
Signature · 7 lines
2.13.3

--
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>
#9 lore raw

PATCH 2/2 cgroup: revert fa06235b8eb0 ("cgroup: reset css on destruction")

Commit fa06235b8eb0 ("cgroup: reset css on destruction") caused css_reset callback to be called from the offlining path. Although it solves the problem mentioned in the commit description ("For instance, memory cgroup needs to reset memory.low, otherwise pages charged to a dead cgroup might never get reclaimed."), generally speaking, it's not correct.

An offline cgroup can still be a resource domain, and we shouldn't grant it more resources than it had before deletion.

For instance, if an offline memory cgroup has dirty pages, we should still imply i/o limits during writeback.

The css_reset callback is designed to return the cgroup state into the original state, that means reset all limits and counters. It's spomething different from the offlining, and we shouldn't use it from the offlining path. Instead, we should adjust necessary settings from the per-controller css_offline callbacks (e.g. reset memory.low).

---
 kernel/cgroup/cgroup.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/cgroup/cgroup.c +0 -3
index 29c36c075249..4e93482e066c 100644
@@ -4499,9 +4499,6 @@ static void offline_css(struct cgroup_subsys_state *css)
 	if (!(css->flags & CSS_ONLINE))
 		return;
 
-	if (ss->css_reset)
-		ss->css_reset(css);
-
 	if (ss->css_offline)
 		ss->css_offline(css);
 
Signature · 7 lines
2.13.3

--
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>
maintainer Acked-by on v1 2/2
#10 lore raw

Re: [PATCH 2/2] cgroup: revert fa06235b8eb0 ("cgroup: reset css on destruction")

Quoted 20 lines · Roman Gushchin

Commit fa06235b8eb0 ("cgroup: reset css on destruction") caused css_reset callback to be called from the offlining path. Although it solves the problem mentioned in the commit description ("For instance, memory cgroup needs to reset memory.low, otherwise pages charged to a dead cgroup might never get reclaimed."), generally speaking, it's not correct.

An offline cgroup can still be a resource domain, and we shouldn't grant it more resources than it had before deletion.

For instance, if an offline memory cgroup has dirty pages, we should still imply i/o limits during writeback.

The css_reset callback is designed to return the cgroup state into the original state, that means reset all limits and counters. It's spomething different from the offlining, and we shouldn't use it from the offlining path. Instead, we should adjust necessary settings from the per-controller css_offline callbacks (e.g. reset memory.low).

Quoted 9 lines

Please feel free to route with the previous patch through -mm.

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>
maintainer Acked-by on v1 2/2
#11 lore raw

Re: [PATCH 2/2] cgroup: revert fa06235b8eb0 ("cgroup: reset css on destruction")

In reply to Roman Gushchin
Quoted 20 lines · Roman Gushchin

Commit fa06235b8eb0 ("cgroup: reset css on destruction") caused css_reset callback to be called from the offlining path. Although it solves the problem mentioned in the commit description ("For instance, memory cgroup needs to reset memory.low, otherwise pages charged to a dead cgroup might never get reclaimed."), generally speaking, it's not correct.

An offline cgroup can still be a resource domain, and we shouldn't grant it more resources than it had before deletion.

For instance, if an offline memory cgroup has dirty pages, we should still imply i/o limits during writeback.

The css_reset callback is designed to return the cgroup state into the original state, that means reset all limits and counters. It's spomething different from the offlining, and we shouldn't use it from the offlining path. Instead, we should adjust necessary settings from the per-controller css_offline callbacks (e.g. reset memory.low).

Quoted 9 lines
maintainer Acked-by on v1 1/2
#12 lore raw

Re: [PATCH 1/2] mm, memcg: reset memory.low during memcg offlining

In reply to Roman Gushchin

CC Andrew - can you route these through the -mm tree please?

Quoted 17 lines · Roman Gushchin

A removed memory cgroup with a defined memory.low and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

This problem was fixed earlier by commit fa06235b8eb0 ("cgroup: reset css on destruction"), but it's not a best way to do it, as we can't really reset all limits/counters during cgroup offlining.

Quoted 9 lines
maintainer Acked-by on v1 1/2
#13 lore raw

Re: [PATCH 1/2] mm, memcg: reset memory.low during memcg offlining

In reply to Roman Gushchin
Quoted 17 lines · Roman Gushchin

A removed memory cgroup with a defined memory.low and some belonging pagecache has very low chances to be freed.

If a cgroup has been removed, there is likely no memory pressure inside the cgroup, and the pagecache is protected from the external pressure by the defined low limit. The cgroup will be freed only after the reclaim of all belonging pages. And it will not happen until there are any reclaimable memory in the system. That means, there is a good chance, that a cold pagecache will reside
in the memory for an undefined amount of time, wasting system resources.

This problem was fixed earlier by commit fa06235b8eb0 ("cgroup: reset css on destruction"), but it's not a best way to do it, as we can't really reset all limits/counters during cgroup offlining.

Quoted 9 lines

my ack for this patch still holds.

Quoted 19 lines
---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +2 -0
index d61133e6af99..7b24210596ea 100644
@@ -4300,6 +4300,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 	}
 	spin_unlock(&memcg->event_list_lock);
 
+	memcg->low = 0;
+
 	memcg_offline_kmem(memcg);
 	wb_memcg_offline(memcg);
 
Signature · 1 line
2.13.3
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>