linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed
@ 2022-10-11 14:30 Waiman Long
  2022-10-11 15:39 ` Michal Hocko
  0 siblings, 1 reply; 7+ messages in thread
From: Waiman Long @ 2022-10-11 14:30 UTC (permalink / raw)
  To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
	Muchun Song, Andrew Morton
  Cc: linux-kernel, cgroups, linux-mm, Tejun Heo, Chris Down, 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.

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")
Signed-off-by: Waiman Long <longman@redhat.com>
---
 mm/memcontrol.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b69979c9ced5..893d4d5e518a 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -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
-- 
2.31.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed
  2022-10-11 14:30 [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed Waiman Long
@ 2022-10-11 15:39 ` Michal Hocko
  2022-10-11 17:00   ` Waiman Long
  0 siblings, 1 reply; 7+ messages in thread
From: Michal Hocko @ 2022-10-11 15:39 UTC (permalink / raw)
  To: Waiman Long
  Cc: Johannes Weiner, Roman Gushchin, Shakeel Butt, Muchun Song,
	Andrew Morton, linux-kernel, cgroups, linux-mm, Tejun Heo,
	Chris Down

On Tue 11-10-22 10:30:15, Waiman Long wrote:
> 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?

> 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")
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  mm/memcontrol.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index b69979c9ced5..893d4d5e518a 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -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.

>  	protected = min(usage, setting);
>  	/*
>  	 * If all cgroups at this level combined claim and use more
> -- 
> 2.31.1

-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed
  2022-10-11 15:39 ` Michal Hocko
@ 2022-10-11 17:00   ` Waiman Long
  2022-10-11 17:04     ` Tejun Heo
  0 siblings, 1 reply; 7+ messages in thread
From: Waiman Long @ 2022-10-11 17:00 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Johannes Weiner, Roman Gushchin, Shakeel Butt, Muchun Song,
	Andrew Morton, linux-kernel, cgroups, linux-mm, Tejun Heo,
	Chris Down

On 10/11/22 11:39, Michal Hocko wrote:
> On Tue 11-10-22 10:30:15, Waiman Long wrote:
>> 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.
>
>> 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")
>> Signed-off-by: Waiman Long <longman@redhat.com>
>> ---
>>   mm/memcontrol.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>> index b69979c9ced5..893d4d5e518a 100644
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -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.

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




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed
  2022-10-11 17:00   ` Waiman Long
@ 2022-10-11 17:04     ` Tejun Heo
  2022-10-11 17:14       ` Waiman Long
                         ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tejun Heo @ 2022-10-11 17:04 UTC (permalink / raw)
  To: Waiman Long
  Cc: Michal Hocko, Johannes Weiner, Roman Gushchin, Shakeel Butt,
	Muchun Song, Andrew Morton, linux-kernel, cgroups, linux-mm,
	Chris Down

On Tue, Oct 11, 2022 at 01:00:22PM -0400, Waiman Long wrote:
> 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.

-- 
tejun


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed
  2022-10-11 17:04     ` Tejun Heo
@ 2022-10-11 17:14       ` Waiman Long
  2022-10-11 19:01       ` Michal Hocko
  2022-10-17 22:46       ` Michal Koutný
  2 siblings, 0 replies; 7+ messages in thread
From: Waiman Long @ 2022-10-11 17:14 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Michal Hocko, Johannes Weiner, Roman Gushchin, Shakeel Butt,
	Muchun Song, Andrew Morton, linux-kernel, cgroups, linux-mm,
	Chris Down


On 10/11/22 13:04, Tejun Heo wrote:
> On Tue, Oct 11, 2022 at 01:00:22PM -0400, Waiman Long wrote:
>> 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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed
  2022-10-11 17:04     ` Tejun Heo
  2022-10-11 17:14       ` Waiman Long
@ 2022-10-11 19:01       ` Michal Hocko
  2022-10-17 22:46       ` Michal Koutný
  2 siblings, 0 replies; 7+ messages in thread
From: Michal Hocko @ 2022-10-11 19:01 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Waiman Long, Johannes Weiner, Roman Gushchin, Shakeel Butt,
	Muchun Song, Andrew Morton, linux-kernel, cgroups, linux-mm,
	Chris Down

On Tue 11-10-22 07:04:32, Tejun Heo wrote:
> On Tue, Oct 11, 2022 at 01:00:22PM -0400, Waiman Long wrote:
> > 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.
-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed
  2022-10-11 17:04     ` Tejun Heo
  2022-10-11 17:14       ` Waiman Long
  2022-10-11 19:01       ` Michal Hocko
@ 2022-10-17 22:46       ` Michal Koutný
  2 siblings, 0 replies; 7+ messages in thread
From: Michal Koutný @ 2022-10-17 22:46 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Waiman Long, Michal Hocko, Johannes Weiner, Roman Gushchin,
	Shakeel Butt, Muchun Song, Andrew Morton, linux-kernel, cgroups,
	linux-mm, Chris Down

On Tue, Oct 11, 2022 at 07:04:32AM -1000, Tejun Heo <tj@kernel.org> wrote:
> 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@blackbody.suse.cz/

HTH,
Michal


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-17 22:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11 14:30 [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed Waiman Long
2022-10-11 15:39 ` Michal Hocko
2022-10-11 17:00   ` Waiman Long
2022-10-11 17:04     ` Tejun Heo
2022-10-11 17:14       ` Waiman Long
2022-10-11 19:01       ` Michal Hocko
2022-10-17 22:46       ` Michal Koutný

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox