Skip to contentSkip to conversation

mm: memcontrol: simplify value comparison between count and limit

PATCH Applied [email protected] 2 participants 2 messages Apr 21, 2020

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

PATCH 1/1 mm: memcontrol: simplify value comparison between count and limit

From: Kaixu Xia <[email protected]>

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.

---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memcontrol.c +1 -1
index 5beea03dd58a..fedc5afdc482 100644
@@ -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;
Signature · 1 line
2.20.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Tue 21-04-20 22:34:21, [email protected] wrote:

From: Kaixu Xia <[email protected]>

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.

Quoted 1 line
Quoted 19 lines
---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memcontrol.c +1 -1
index 5beea03dd58a..fedc5afdc482 100644
@@ -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;
Signature · 1 line
2.20.0
Signature · 2 lines
Michal Hocko
SUSE Labs