Skip to contentSkip to conversation

mm/memcontrol: Don't increase effective low/min if no protection needed

PATCH In review Waiman Long 4 participants 7 messages Oct 11, 2022 – Oct 17, 2022

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

PATCH 1/1 mm/memcontrol: Don't increase effective low/min if no protection needed

Since commit bc50bcc6e00b ("mm: memcontrol: clean up and document effective low/min calculations"), the effective low/min protections can be non-zero even if the corresponding memory.low/min values are 0. That can surprise users to see MEMCG_LOW events even when the memory.low value is not set. One example is the LTP's memcontrol04 test which fails because it detects some MEMCG_LOW events for a cgroup with a memory.min value of 0.

Fix this by updating effective_protection() to not returning a non-zero low/min protection values if the corresponding memory.low/min values or those of its parent are 0.

Fixes bc50bcc6e00b ("mm: memcontrol: clean up and document effective low/min calculations")
---
 mm/memcontrol.c | 3 +++
 1 file changed, 3 insertions(+)
mm/memcontrol.c +3 -0
index b69979c9ced5..893d4d5e518a 100644
@@ -6660,6 +6660,9 @@ static unsigned long effective_protection(unsigned long usage,
 	unsigned long protected;
 	unsigned long ep;
 
+	if (!setting || !parent_effective)
+		return 0UL;	/* No protection is needed */
+
 	protected = min(usage, setting);
 	/*
 	 * If all cgroups at this level combined claim and use more
Signature · 1 line
2.31.1
#1 lore raw
Quoted 7 lines · Waiman Long

Since commit bc50bcc6e00b ("mm: memcontrol: clean up and document effective low/min calculations"), the effective low/min protections can be non-zero even if the corresponding memory.low/min values are 0. That can surprise users to see MEMCG_LOW events even when the memory.low value is not set. One example is the LTP's memcontrol04 test which fails because it detects some MEMCG_LOW events for a cgroup with a memory.min value of 0.

Is this with memory_recursiveprot mount option?

Quoted 15 lines

Fix this by updating effective_protection() to not returning a non-zero low/min protection values if the corresponding memory.low/min values or those of its parent are 0.

Fixes bc50bcc6e00b ("mm: memcontrol: clean up and document effective low/min calculations")
---
 mm/memcontrol.c | 3 +++
 1 file changed, 3 insertions(+)
mm/memcontrol.c +0 -0
index b69979c9ced5..893d4d5e518a 100644

mm/memcontrol.c static unsigned long effective_protection(unsigned long usage, · line 6665

Quoted 6 lines
mm/memcontrol.c +3 -0
@@ -6660,6 +6660,9 @@ static unsigned long effective_protection(unsigned long usage,
 	unsigned long protected;
 	unsigned long ep;
 
+	if (!setting || !parent_effective)
+		return 0UL;	/* No protection is needed */
+

This will break the above memory_recursiveprot AFAICS.

Quoted 5 lines
mm/memcontrol.c +0 -0
 	protected = min(usage, setting);
 	/*
 	 * If all cgroups at this level combined claim and use more
Signature · 1 line
2.31.1
Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw
Quoted 9 lines · Michal Hocko
Quoted 7 lines · Waiman Long

Since commit bc50bcc6e00b ("mm: memcontrol: clean up and document effective low/min calculations"), the effective low/min protections can be non-zero even if the corresponding memory.low/min values are 0. That can surprise users to see MEMCG_LOW events even when the memory.low value is not set. One example is the LTP's memcontrol04 test which fails because it detects some MEMCG_LOW events for a cgroup with a memory.min value of 0.

Is this with memory_recursiveprot mount option?

Yes, the memory_recursiveprot mount option is indeed turned on.

Quoted 19 lines
Quoted 19 lines

Fix this by updating effective_protection() to not returning a non-zero low/min protection values if the corresponding memory.low/min values or those of its parent are 0.

Fixes bc50bcc6e00b ("mm: memcontrol: clean up and document effective low/min calculations")
---
  mm/memcontrol.c | 3 +++
  1 file changed, 3 insertions(+)
mm/memcontrol.c +0 -0
index b69979c9ced5..893d4d5e518a 100644
@@ -6660,6 +6660,9 @@ static unsigned long effective_protection(unsigned long usage,
  	unsigned long protected;
  	unsigned long ep;
 
Quoted 4 lines

mm/memcontrol.c static unsigned long effective_protection(unsigned long usage, · line 6665

Quoted 3 lines
mm/memcontrol.c +3 -0
+	if (!setting || !parent_effective)
+		return 0UL;	/* No protection is needed */
+

This will break the above memory_recursiveprot AFAICS.

You are right about that. An alternative way to address this issue is to disable memory low event when memory.low isn't set. An user who want to track memory.low event has to set it to a non-zero value. Would that be acceptable?

Cheers,
Longman

maintainer
#3 lore raw
Quoted 4 lines · Waiman Long

You are right about that. An alternative way to address this issue is to disable memory low event when memory.low isn't set. An user who want to track memory.low event has to set it to a non-zero value. Would that be acceptable?

Wouldn't it make sense to fix the test? With recursive_prot on, the cgroup actually is under low protection and it seems like the correct behavior is to report the low events accordingly.

Thanks.

Signature · 1 line
tejun
#4 lore raw
Quoted 8 lines · Tejun Heo
Quoted 4 lines · Waiman Long

You are right about that. An alternative way to address this issue is to disable memory low event when memory.low isn't set. An user who want to track memory.low event has to set it to a non-zero value. Would that be acceptable?

Wouldn't it make sense to fix the test? With recursive_prot on, the cgroup actually is under low protection and it seems like the correct behavior is to report the low events accordingly.

Yes, that is another possible way of looking at that problem. Will talk to our QE people of doing that.

Thanks,
Longman

#5 lore raw
In reply to Tejun Heo
Quoted 9 lines · Tejun Heo
Quoted 4 lines · Waiman Long

You are right about that. An alternative way to address this issue is to disable memory low event when memory.low isn't set. An user who want to track memory.low event has to set it to a non-zero value. Would that be acceptable?

Wouldn't it make sense to fix the test? With recursive_prot on, the cgroup actually is under low protection and it seems like the correct behavior is to report the low events accordingly.

Agreed, the semantic makes sense and it seems to be just the test that is not aware of it.

Signature · 2 lines
Michal Hocko
SUSE Labs
maintainer
#6 lore raw
In reply to Tejun Heo
Quoted 3 lines · Tejun Heo

Wouldn't it make sense to fix the test? With recursive_prot on, the cgroup actually is under low protection and it seems like the correct behavior is to report the low events accordingly.

It depends whether the there is a residual protection that the memory.low=0 sibling can use (with memory_recursiveprot).

In the discussed LTP test, there should be no residual protection that would justify the apparently misreported memory.low events. I.e. the test is correct, the failure points to a subtle issue with distributing residual protection among siblings.

Been there, (haven't) done that:
1) https://bugzilla.suse.com/show_bug.cgi?id=1196298
2) https://lore.kernel.org/r/20220325103118.GC2828-9OudH3eul5jcvrawFnH+a6VXKuFTiq87@public.gmane.org/

HTH,
Michal