All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] IPC: account for kmem usage on mqueue and msg
@ 2016-10-18 15:54 Aristeu Rozanski
       [not found] ` <1476806075-1210-1-git-send-email-arozansk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Aristeu Rozanski @ 2016-10-18 15:54 UTC (permalink / raw)
  To: cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Aristeu Rozanski, Andrew Morton, Alexey Dobriyan, Davidlohr Bueso,
	Johannes Weiner, Michal Hocko, Vladimir Davydov,
	Stefan Schimanski

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/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Cc: Alexey Dobriyan <adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Davidlohr Bueso <dave-h16yJtLeMjHk1uMJSBkQmQ@public.gmane.org>
Cc: Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
Cc: Michal Hocko <mhocko-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Vladimir Davydov <vdavydov.dev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Stefan Schimanski <sttts-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Reported-by: Stefan Schimanski <sttts-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Aristeu Rozanski <arozansk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 ipc/msgutil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ipc/msgutil.c b/ipc/msgutil.c
index a521999..bf74eaa 100644
--- a/ipc/msgutil.c
+++ b/ipc/msgutil.c
@@ -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;
-- 
1.8.3.1

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

* Re: [PATCH] IPC: account for kmem usage on mqueue and msg
       [not found] ` <1476806075-1210-1-git-send-email-arozansk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2016-10-18 18:26   ` Michal Hocko
       [not found]     ` <20161018182619.GB27792-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2016-10-18 18:26 UTC (permalink / raw)
  To: Aristeu Rozanski
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Alexey Dobriyan,
	Davidlohr Bueso, Johannes Weiner, Vladimir Davydov,
	Stefan Schimanski

On Tue 18-10-16 11:54:35, Aristeu Rozanski wrote:
> 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.

> Cc: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
> Cc: Alexey Dobriyan <adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Cc: Davidlohr Bueso <dave-h16yJtLeMjHk1uMJSBkQmQ@public.gmane.org>
> Cc: Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
> Cc: Michal Hocko <mhocko-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> Cc: Vladimir Davydov <vdavydov.dev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Cc: Stefan Schimanski <sttts-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Reported-by: Stefan Schimanski <sttts-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Aristeu Rozanski <arozansk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

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

> ---
>  ipc/msgutil.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/ipc/msgutil.c b/ipc/msgutil.c
> index a521999..bf74eaa 100644
> --- a/ipc/msgutil.c
> +++ b/ipc/msgutil.c
> @@ -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;
> -- 
> 1.8.3.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe cgroups" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] IPC: account for kmem usage on mqueue and msg
       [not found]     ` <20161018182619.GB27792-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
@ 2016-10-18 18:44       ` Aristeu Rozanski
  2016-10-18 19:30       ` Alexey Dobriyan
  1 sibling, 0 replies; 5+ messages in thread
From: Aristeu Rozanski @ 2016-10-18 18:44 UTC (permalink / raw)
  To: Michal Hocko
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, Alexey Dobriyan,
	Davidlohr Bueso, Johannes Weiner, Vladimir Davydov,
	Stefan Schimanski

Hi Michal,
On Tue, Oct 18, 2016 at 08:26:19PM +0200, Michal Hocko wrote:
> 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.

-- 
Aristeu

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

* Re: [PATCH] IPC: account for kmem usage on mqueue and msg
       [not found]     ` <20161018182619.GB27792-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
  2016-10-18 18:44       ` Aristeu Rozanski
@ 2016-10-18 19:30       ` Alexey Dobriyan
       [not found]         ` <CAFtQ=dr2zGqeHtw84UGP8615TaWg92_n7nZPfn2qZkxDA1zN5Q@mail.gmail.com>
  1 sibling, 1 reply; 5+ messages in thread
From: Alexey Dobriyan @ 2016-10-18 19:30 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Aristeu Rozanski, cgroups-u79uwXL29TY76Z2rM5mHXA, Andrew Morton,
	Davidlohr Bueso, Johannes Weiner, Vladimir Davydov,
	Stefan Schimanski

On Tue, Oct 18, 2016 at 08:26:19PM +0200, Michal Hocko wrote:
> On Tue 18-10-16 11:54:35, Aristeu Rozanski wrote:
> > 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.

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

* Re: [PATCH] IPC: account for kmem usage on mqueue and msg
       [not found]           ` <CAFtQ=dr2zGqeHtw84UGP8615TaWg92_n7nZPfn2qZkxDA1zN5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2016-10-19  7:55             ` Michal Hocko
  0 siblings, 0 replies; 5+ messages in thread
From: Michal Hocko @ 2016-10-19  7:55 UTC (permalink / raw)
  To: Stefan Schimanski
  Cc: Alexey Dobriyan, Aristeu Rozanski, cgroups-u79uwXL29TY76Z2rM5mHXA,
	Andrew Morton, Davidlohr Bueso, Johannes Weiner, Vladimir Davydov

On Wed 19-10-16 09:46:58, Stefan Schimanski wrote:
> 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. 

> On Tue, Oct 18, 2016 at 9:30 PM, Alexey Dobriyan <adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
> 
> > On Tue, Oct 18, 2016 at 08:26:19PM +0200, Michal Hocko wrote:
> > > On Tue 18-10-16 11:54:35, Aristeu Rozanski wrote:
> > > > 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.
> >

-- 
Michal Hocko
SUSE Labs

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

end of thread, other threads:[~2016-10-19  7:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-18 15:54 [PATCH] IPC: account for kmem usage on mqueue and msg Aristeu Rozanski
     [not found] ` <1476806075-1210-1-git-send-email-arozansk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-10-18 18:26   ` Michal Hocko
     [not found]     ` <20161018182619.GB27792-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2016-10-18 18:44       ` Aristeu Rozanski
2016-10-18 19:30       ` Alexey Dobriyan
     [not found]         ` <CAFtQ=dr2zGqeHtw84UGP8615TaWg92_n7nZPfn2qZkxDA1zN5Q@mail.gmail.com>
     [not found]           ` <CAFtQ=dr2zGqeHtw84UGP8615TaWg92_n7nZPfn2qZkxDA1zN5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-10-19  7:55             ` Michal Hocko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.