Skip to contentSkip to conversation

mm: memcontrol: fix the margin computation in mem_cgroup_margin

PATCH In review [email protected] 2 participants 3 messages May 24, 2016 – May 26, 2016

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

PATCH v2 1/1 mm: memcontrol: fix the margin computation in mem_cgroup_margin

From: Li RongQing <[email protected]>

The margin may be set to the difference value between memory limit and memory count firstly. which maybe returned wrongly if memsw.count excess memsw.limit, because try_charge forces charging __GFP_NOFAIL allocations, which may result in memsw.limit excess. If we are below memory.limit and there's nothing to reclaim to reduce memsw.usage, might end up looping in try_charge forever.

---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +2 -0
index 00981d2..12aaadd 100644
@@ -1090,6 +1090,8 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg)
 		limit = READ_ONCE(memcg->memsw.limit);
 		if (count <= limit)
 			margin = min(margin, limit - count);
+		else
+			margin = 0;
 	}
 
 	return margin;
Signature · 1 line
2.1.4
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 8 lines · On Tue 24-05-16 13:37:46, [email protected]…

From: Li RongQing <[email protected]>

The margin may be set to the difference value between memory limit and memory count firstly. which maybe returned wrongly if memsw.count excess memsw.limit, because try_charge forces charging __GFP_NOFAIL allocations, which may result in memsw.limit excess. If we are below memory.limit and there's nothing to reclaim to reduce memsw.usage, might end up looping in try_charge forever.

This is quite hard for me to grasp. What would you say about the following:
"
mem_cgroup_margin might return memory.limit - memory_count when the memsw.limit is in excess. This
doesn't happen usually because we do not allow excess on hard limits and memory.limit <= memsw.limit but __GFP_NOFAIL charges can force the charge and cause the excess when no memory is really swapable (swap is full or no anonymous memory is left).
"

Quoted 4 lines
Quoted 19 lines
---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +2 -0
index 00981d2..12aaadd 100644
@@ -1090,6 +1090,8 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg)
 		limit = READ_ONCE(memcg->memsw.limit);
 		if (count <= limit)
 			margin = min(margin, limit - count);
+		else
+			margin = 0;
 	}
 
 	return margin;
Signature · 1 line
2.1.4
Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw
Quoted 9 lines · Michal Hocko

This is quite hard for me to grasp. What would you say about the following:
"
mem_cgroup_margin might return memory.limit - memory_count when the memsw.limit is in excess. This
doesn't happen usually because we do not allow excess on hard limits and memory.limit <= memsw.limit but __GFP_NOFAIL charges can force the charge and cause the excess when no memory is really swapable (swap is full or no anonymous memory is left).

Sorry for my poor English, thanks for your description, hope it can be into the log

-Roy

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