linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: memcontrol: simplify value comparison between count and limit
@ 2020-04-21 14:34 xiakaixu1987
  2020-04-21 14:59 ` Michal Hocko
  0 siblings, 1 reply; 2+ messages in thread
From: xiakaixu1987 @ 2020-04-21 14:34 UTC (permalink / raw)
  To: hannes, mhocko, vdavydov.dev; +Cc: linux-mm, Kaixu Xia

From: Kaixu Xia <kaixuxia@tencent.com>

When the variables count and limit have the same value(count == limit),
the result of min(margin, limit - count) statement should be 0 and the
variable margin is set to 0. So in this case, the min() statement is not
necessary and we can directly set the variable margin to 0.

Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5beea03dd58a..fedc5afdc482 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1314,7 +1314,7 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg)
 	if (do_memsw_account()) {
 		count = page_counter_read(&memcg->memsw);
 		limit = READ_ONCE(memcg->memsw.max);
-		if (count <= limit)
+		if (count < limit)
 			margin = min(margin, limit - count);
 		else
 			margin = 0;
-- 
2.20.0



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

* Re: [PATCH] mm: memcontrol: simplify value comparison between count and limit
  2020-04-21 14:34 [PATCH] mm: memcontrol: simplify value comparison between count and limit xiakaixu1987
@ 2020-04-21 14:59 ` Michal Hocko
  0 siblings, 0 replies; 2+ messages in thread
From: Michal Hocko @ 2020-04-21 14:59 UTC (permalink / raw)
  To: xiakaixu1987; +Cc: hannes, vdavydov.dev, linux-mm, Kaixu Xia

On Tue 21-04-20 22:34:21, xiakaixu1987@gmail.com wrote:
> From: Kaixu Xia <kaixuxia@tencent.com>
> 
> When the variables count and limit have the same value(count == limit),
> the result of min(margin, limit - count) statement should be 0 and the
> variable margin is set to 0. So in this case, the min() statement is not
> necessary and we can directly set the variable margin to 0.

I expect that the compiler would generate the same code but there is no
reason to differ in memsw branch from the main limit check so the patch
looks ok to me.

> Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>

 Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/memcontrol.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 5beea03dd58a..fedc5afdc482 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1314,7 +1314,7 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg)
>  	if (do_memsw_account()) {
>  		count = page_counter_read(&memcg->memsw);
>  		limit = READ_ONCE(memcg->memsw.max);
> -		if (count <= limit)
> +		if (count < limit)
>  			margin = min(margin, limit - count);
>  		else
>  			margin = 0;
> -- 
> 2.20.0

-- 
Michal Hocko
SUSE Labs


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

end of thread, other threads:[~2020-04-21 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21 14:34 [PATCH] mm: memcontrol: simplify value comparison between count and limit xiakaixu1987
2020-04-21 14:59 ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).