Skip to contentSkip to conversation

mm: memcontrol: fix the return in mem_cgroup_margin

PATCH Superseded [email protected] 3 participants 8 messages May 18, 2016 – May 24, 2016

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: memcontrol: fix the return in mem_cgroup_margin

From: Li RongQing <[email protected]>

when memory+swap is over limit, return 0

---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +2 -0
index fe787f5..e9211c2 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
#1 lore raw
Quoted 14 lines · On Wed 18-05-16 15:24:15, [email protected]…

From: Li RongQing <[email protected]>

when memory+swap is over limit, return 0

---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)
mm/memcontrol.c +0 -0
index fe787f5..e9211c2 100644

mm/memcontrol.c static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg) · line 1094

Quoted 5 lines
mm/memcontrol.c +2 -0
@@ -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;

count should always be smaller than memsw.limit (this is a hard limit). Even if we have some temporary breach then the code should work as expected because margin is initialized to 0 and memsw.limit >= limit.

Or have you seen any real problem with this code path?

Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw
Quoted 1 line · Michal Hocko

Or have you seen any real problem with this code path?

not;
I read the codes, think it is more reasonable to set margin to 0 here

-Roy

#3 lore raw
In reply to Michal Hocko
Quoted 3 lines · Michal Hocko

count should always be smaller than memsw.limit (this is a hard limit). Even if we have some temporary breach then the code should work as expected because margin is initialized to 0 and memsw.limit >= limit.

is it possible for this case? for example

memory count is 500, memory limit is 600; the margin is set to 100 firstly, then check memory+swap limit, its count(1100) is bigger than its limit(1000), then the margin 100 is returned wrongly.

-Roy

#4 lore raw
Quoted 10 lines · Li RongQing
Quoted 3 lines · Michal Hocko

count should always be smaller than memsw.limit (this is a hard limit). Even if we have some temporary breach then the code should work as expected because margin is initialized to 0 and memsw.limit >= limit.

is it possible for this case? for example

memory count is 500, memory limit is 600; the margin is set to 100 firstly, then check memory+swap limit, its count(1100) is bigger than its limit(1000), then the margin 100 is returned wrongly.

I guess it is possible, 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, we might end up looping in try_charge forever. I've never seen that happen in practice, but I still think the patch is worth applying.

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

maintainer
#5 lore raw
Quoted 12 lines · Vladimir Davydov
Quoted 10 lines · Li RongQing
Quoted 3 lines · Michal Hocko

count should always be smaller than memsw.limit (this is a hard limit). Even if we have some temporary breach then the code should work as expected because margin is initialized to 0 and memsw.limit >= limit.

is it possible for this case? for example

memory count is 500, memory limit is 600; the margin is set to 100 firstly, then check memory+swap limit, its count(1100) is bigger than its limit(1000), then the margin 100 is returned wrongly.

Quoted 5 lines

I guess it is possible, 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, we might end up looping in try_charge forever. I've never seen that happen in practice, but I still think the patch is worth applying.

You are right. I have completely missed a potential interaction with __GFP_NOFAIL. We even do not seem to trigger the memcg OOM killer for these requests to sort the situation out.

Can we have updated patch with all this useful information in the changelog, please?

Thanks Vladimir!

Signature · 8 lines
Michal Hocko
SUSE Labs

--
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>
maintainer
#6 lore raw

On Mon 23-05-16 14:06:20, Michal Hocko wrote:
[...]

Quoted 3 lines

I have completely missed a potential interaction with __GFP_NOFAIL. We even do not seem to trigger the memcg OOM killer for these requests to sort the situation out.

Which is intentional. a0d8b00a3381 ("mm: memcg: do not declare OOM from __GFP_NOFAIL allocations")

Signature · 8 lines
Michal Hocko
SUSE Labs

--
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>
#7 lore raw
In reply to Michal Hocko
Quoted 3 lines · Michal Hocko

Can we have updated patch with all this useful information in the changelog, please?

Ok, I will update this patch

-Roy