Skip to contentSkip to conversation

IPC: account for kmem usage on mqueue and msg

PATCH Applied Aristeu Rozanski 3 participants 5 messages Oct 18, 2016 – Oct 19, 2016 4 messages not in the archive cgroup

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IPC: account for kmem usage on mqueue and msg

When kmem accounting switched from account by default to only account if flagged by __GFP_ACCOUNT, IPC mqueue and messages was left out.

Cc Andrew Morton <akpm-de/[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Davidlohr Bueso <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Vladimir Davydov <[email protected]>
Cc Stefan Schimanski <[email protected]>
---
 ipc/msgutil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ipc/msgutil.c +2 -2
index a521999..bf74eaa 100644
@@ -53,7 +53,7 @@ static struct msg_msg *alloc_msg(size_t len)
 	size_t alen;
 
 	alen = min(len, DATALEN_MSG);
-	msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL);
+	msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL_ACCOUNT);
 	if (msg == NULL)
 		return NULL;
 
@@ -65,7 +65,7 @@ static struct msg_msg *alloc_msg(size_t len)
 	while (len > 0) {
 		struct msg_msgseg *seg;
 		alen = min(len, DATALEN_SEG);
-		seg = kmalloc(sizeof(*seg) + alen, GFP_KERNEL);
+		seg = kmalloc(sizeof(*seg) + alen, GFP_KERNEL_ACCOUNT);
 		if (seg == NULL)
 			goto out_err;
 		*pseg = seg;
Signature · 1 line
1.8.3.1

A message that is not in the archive (sent off-list or not yet received): 1476806075-1210-1-git-send-email-arozansk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw
Quoted 2 lines · Aristeu Rozanski

When kmem accounting switched from account by default to only account if flagged by __GFP_ACCOUNT, IPC mqueue and messages was left out.

I guess this was because ipv msgqueue shouldn't allow for memory consumption runaways. The number of message queues and messages pending in them is bounded and not a large amount of memory AFAIR. Anyway I do not see anything unreasonable about accounting the memory to the caller.

Have you noticed this by a code inspection or you have a real world usecase where the missing accounting caused some problems? This would be a useful information for the changelog.

Quoted 9 lines
Cc Andrew Morton <akpm-de/[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Davidlohr Bueso <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Vladimir Davydov <[email protected]>
Cc Stefan Schimanski <[email protected]>

I am not familiar with this code enough to give my ack but I do not see anything obviously wrong either.

Quoted 33 lines
---
 ipc/msgutil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ipc/msgutil.c +2 -2
index a521999..bf74eaa 100644
@@ -53,7 +53,7 @@ static struct msg_msg *alloc_msg(size_t len)
 	size_t alen;
 
 	alen = min(len, DATALEN_MSG);
-	msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL);
+	msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL_ACCOUNT);
 	if (msg == NULL)
 		return NULL;
 
@@ -65,7 +65,7 @@ static struct msg_msg *alloc_msg(size_t len)
 	while (len > 0) {
 		struct msg_msgseg *seg;
 		alen = min(len, DATALEN_SEG);
-		seg = kmalloc(sizeof(*seg) + alen, GFP_KERNEL);
+		seg = kmalloc(sizeof(*seg) + alen, GFP_KERNEL_ACCOUNT);
 		if (seg == NULL)
 			goto out_err;
 		*pseg = seg;
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Michal Hocko
SUSE Labs

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hi Michal,

Quoted 8 lines · Michal Hocko

I guess this was because ipv msgqueue shouldn't allow for memory consumption runaways. The number of message queues and messages pending in them is bounded and not a large amount of memory AFAIR. Anyway I do not see anything unreasonable about accounting the memory to the caller.

Have you noticed this by a code inspection or you have a real world usecase where the missing accounting caused some problems? This would be a useful information for the changelog.

Stefan noticed this and filled an internal BZ and I saw it with a test program while comparing with our 3.10 kernel. We haven't hit this issue in production (AFAIK) but it's a concern while using containers.

Each message is up to 16MB and you can't get too many messages queued. While it's something that won't allow a container to eat a large portion of memory, it's significant enough to be accounted for.

Signature · 1 line
Aristeu
#5 lore raw
In reply to a message not in the archive
Quoted 8 lines · Michal Hocko
Quoted 2 lines · Aristeu Rozanski

When kmem accounting switched from account by default to only account if flagged by __GFP_ACCOUNT, IPC mqueue and messages was left out.

I guess this was because ipv msgqueue shouldn't allow for memory consumption runaways. The number of message queues and messages pending in them is bounded and not a large amount of memory AFAIR. Anyway I do not see anything unreasonable about accounting the memory to the caller.

It should be accounted because receiver may not intentionally or unintentionally consume messages.

A message that is not in the archive (sent off-list or not yet received): CAFtQ=dr2zGqeHtw84UGP8615TaWg92_n7nZPfn2qZkxDA1zN5Q@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAFtQ=dr2zGqeHtw84UGP8615TaWg92_n7nZPfn2qZkxDA1zN5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#8 lore raw
Quoted 5 lines · Stefan Schimanski

The production use case at hand is that mqueues should be customizable via sysctls in Docker containers in a Kubernetes cluster. This can only be safely allowed to the users of the cluster (without the risk that they can cause resource shortage on a node, influencing other users' containers) if all resources they control are bounded, i.e. accounted for.

THis is a valuable information and should be a part of the changelog IMHO.

Quoted 18 lines
Quoted 15 lines · Alexey Dobriyan
Quoted 2 lines · Michal Hocko
Quoted 1 line · Aristeu Rozanski

When kmem accounting switched from account by default to only account

if

Quoted 6 lines
Quoted 1 line

flagged by __GFP_ACCOUNT, IPC mqueue and messages was left out.

I guess this was because ipv msgqueue shouldn't allow for memory consumption runaways. The number of message queues and messages pending in them is bounded and not a large amount of memory AFAIR. Anyway I do not see anything unreasonable about accounting the memory to the caller.

It should be accounted because receiver may not intentionally or unintentionally
consume messages.

Signature · 2 lines
Michal Hocko
SUSE Labs