memcg: enable accounting for pids in nested pid namespaces
Subsystems (2)
PATCH 1/1 memcg: enable accounting for pids in nested pid namespaces
init_pid_ns.pid_cachep have enabled memcg accounting, though this setting was disabled for nested pid namespaces.
--- kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/pid_namespace.c +2 -1
@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cachep(unsigned int level)mutex_lock (&pid_caches_mutex);/* Name collision forces to do allocation under mutex. */ if (!*pkc) - *pkc =kmem_cache_create (name, len,0 ,SLAB_HWCACHE_ALIGN ,0 ); + *pkc =kmem_cache_create (name, len,0 , +SLAB_HWCACHE_ALIGN |SLAB_ACCOUNT ,0 );mutex_unlock (&pid_caches_mutex);/* current can fail, but someone else can succeed. */ return READ_ONCE (*pkc);
Signature · 1 line
1.8.3.1
A message that is not in the archive (sent off-list or not yet received): 7b777e22-5b0d-7444-343d-92cbfae5f8b4-5HdwGun5lf+gSpxsJD1C4w@public.gmane.org
Roman Gushchin
Acked-byQuoted 25 lines · Vasily Averin
init_pid_ns.pid_cachep have enabled memcg accounting, though this setting was disabled for nested pid namespaces.
Signed-off-by Vasily Averin <[email protected]>--- kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/pid_namespace.c +2
-1@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cachep(unsigned int level)mutex_lock (&pid_caches_mutex);/* Name collision forces to do allocation under mutex. */ if (!*pkc) - *pkc =kmem_cache_create (name, len,0 ,SLAB_HWCACHE_ALIGN ,0 ); + *pkc =kmem_cache_create (name, len,0 , +SLAB_HWCACHE_ALIGN |SLAB_ACCOUNT ,0 );mutex_unlock (&pid_caches_mutex);/* current can fail, but someone else can succeed. */ return READ_ONCE (*pkc);Signature · 1 line
1.8.3.1
It looks good to me! It makes total sense to apply the same rules to the root and non-root levels.
Btw, is there any reason why this patch is not included into the series?
Thanks!
Quoted 30 lines · Roman Gushchin
Quoted 25 lines · Vasily Averin
init_pid_ns.pid_cachep have enabled memcg accounting, though this setting was disabled for nested pid namespaces.
Signed-off-by Vasily Averin <[email protected]>--- kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/pid_namespace.c +2
-1@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cachep(unsigned int level)mutex_lock (&pid_caches_mutex);/* Name collision forces to do allocation under mutex. */ if (!*pkc) - *pkc =kmem_cache_create (name, len,0 ,SLAB_HWCACHE_ALIGN ,0 ); + *pkc =kmem_cache_create (name, len,0 , +SLAB_HWCACHE_ALIGN |SLAB_ACCOUNT ,0 );mutex_unlock (&pid_caches_mutex);/* current can fail, but someone else can succeed. */ return READ_ONCE (*pkc);Signature · 1 line
1.8.3.1It looks good to me! It makes total sense to apply the same rules to the root and non-root levels.
Quoted 3 lines
Acked-by Roman Gushchin <[email protected]>Btw, is there any reason why this patch is not included into the series?
It is a bugfix and I think it should be added to upstream ASAP. Another patches adds a new functionality, they can cause questions or objections and anyway can wait.
Thank you,
Vasily Averin
A message that is not in the archive (sent off-list or not yet received): 38945563-59ad-fb5e-9f7f-eb65ae4bf55e-5HdwGun5lf+gSpxsJD1C4w@public.gmane.org
Quoted 31 lines · Vasily Averin
Quoted 30 lines · Roman Gushchin
Quoted 25 lines · Vasily Averin
init_pid_ns.pid_cachep have enabled memcg accounting, though this setting was disabled for nested pid namespaces.
Signed-off-by Vasily Averin <[email protected]>--- kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/pid_namespace.c +2
-1@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cachep(unsigned int level)mutex_lock (&pid_caches_mutex);/* Name collision forces to do allocation under mutex. */ if (!*pkc) - *pkc =kmem_cache_create (name, len,0 ,SLAB_HWCACHE_ALIGN ,0 ); + *pkc =kmem_cache_create (name, len,0 , +SLAB_HWCACHE_ALIGN |SLAB_ACCOUNT ,0 );mutex_unlock (&pid_caches_mutex);/* current can fail, but someone else can succeed. */ return READ_ONCE (*pkc);Signature · 1 line
1.8.3.1It looks good to me! It makes total sense to apply the same rules to the root and non-root levels.
Quoted 5 lines
Quoted 3 lines
Acked-by Roman Gushchin <[email protected]>Btw, is there any reason why this patch is not included into the series?
It is a bugfix and I think it should be added to upstream ASAP.
Then it would be really useful to add some details on why it's a bug, what kind of problems it causes, etc. If it has to be backported to stable, please, add cc stable/fixes tag.
Thanks!
Quoted 34 lines · Roman Gushchin
Quoted 33 lines · Vasily Averin
Quoted 32 lines · Roman Gushchin
Quoted 25 lines · Vasily Averin
init_pid_ns.pid_cachep have enabled memcg accounting, though this setting was disabled for nested pid namespaces.
Signed-off-by Vasily Averin <[email protected]>--- kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/pid_namespace.c +2
-1@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cachep(unsigned int level)mutex_lock (&pid_caches_mutex);/* Name collision forces to do allocation under mutex. */ if (!*pkc) - *pkc =kmem_cache_create (name, len,0 ,SLAB_HWCACHE_ALIGN ,0 ); + *pkc =kmem_cache_create (name, len,0 , +SLAB_HWCACHE_ALIGN |SLAB_ACCOUNT ,0 );mutex_unlock (&pid_caches_mutex);/* current can fail, but someone else can succeed. */ return READ_ONCE (*pkc);Signature · 1 line
1.8.3.1It looks good to me! It makes total sense to apply the same rules to the root and non-root levels.
Acked-by Roman Gushchin <[email protected]>
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Btw, is there any reason why this patch is not included into the series?
It is a bugfix and I think it should be added to upstream ASAP.
Then it would be really useful to add some details on why it's a bug, what kind of problems it causes, etc. If it has to be backported to stable, please, add cc stable/fixes tag.
I mean, in this case we already decided to account pids, but forget to do it. In another cases we did not have final decision about accounting.
I doubt we specially denied accounting for pids frem nested pid namespaces, especially because they consumes more memory.
We can expect that all pids are accounted -- but it does not happen in fact.
A message that is not in the archive (sent off-list or not yet received): cd6680e3-edd0-88fa-bb83-b9f2d5a65d5b-5HdwGun5lf+gSpxsJD1C4w@public.gmane.org
Christian Brauner
Acked-byQuoted 43 lines · Vasily Averin
Quoted 34 lines · Roman Gushchin
Quoted 33 lines · Vasily Averin
Quoted 32 lines · Roman Gushchin
Quoted 25 lines · Vasily Averin
init_pid_ns.pid_cachep have enabled memcg accounting, though this setting was disabled for nested pid namespaces.
Signed-off-by Vasily Averin <[email protected]>--- kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/pid_namespace.c +2
-1@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cachep(unsigned int level)mutex_lock (&pid_caches_mutex);/* Name collision forces to do allocation under mutex. */ if (!*pkc) - *pkc =kmem_cache_create (name, len,0 ,SLAB_HWCACHE_ALIGN ,0 ); + *pkc =kmem_cache_create (name, len,0 , +SLAB_HWCACHE_ALIGN |SLAB_ACCOUNT ,0 );mutex_unlock (&pid_caches_mutex);/* current can fail, but someone else can succeed. */ return READ_ONCE (*pkc);Signature · 1 line
1.8.3.1It looks good to me! It makes total sense to apply the same rules to the root and non-root levels.
Acked-by Roman Gushchin <[email protected]>Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Btw, is there any reason why this patch is not included into the series?
It is a bugfix and I think it should be added to upstream ASAP.
Then it would be really useful to add some details on why it's a bug, what kind of problems it causes, etc. If it has to be backported to stable, please, add cc stable/fixes tag.
Quoted 6 lines
I mean, in this case we already decided to account pids, but forget to do it. In another cases we did not have final decision about accounting.
I doubt we specially denied accounting for pids frem nested pid namespaces, especially because they consumes more memory.
We can expect that all pids are accounted -- but it does not happen in fact.
As Roman said you should probably explain this in the cover letter and essentially justify why this should be backported. The thing with changes such as this is that it's easy for someone to reply and go "noone noticed for <n> years so why do we care now?". Otherwise:
Christian
Michal Koutný
Reviewed-byQuoted 2 lines · Vasily Averin
init_pid_ns.pid_cachep have enabled memcg accounting, though this setting was disabled for nested pid namespaces.
Good catch.
Cursory grep of user_namespace.c and nsproxy.c suggests it's the only case of namespace-induced new cache.
Christian Brauner
Acked-byQuoted 5 lines · Vasily Averin
init_pid_ns.pid_cachep have enabled memcg accounting, though this setting was disabled for nested pid namespaces.
Signed-off-by Vasily Averin <[email protected]>---
Not sure I already acked this but looks good,
v2 cover memcg: enable accounting for pids in nested pid namespaces
In reply to Vasily AverinPid was one the first kernel objects enabled for memcg accounting, see 5d097056c9a0 ("kmemcg: account certain kmem allocations to memcg")
init_pid_ns.pid_cachep marked by SLAB_ACCOUNT and we can expect that any new pids in the system are memcg-accounted.
Though recently I've noticed that it is wrong. nested pid namespaces creates own slab caches for pid objects, nested pids have increased size because contain id both for all parent and for own pid namespaces. The problem is that these slab caches are _NOT_ marked by SLAB_ACCOUNT,as a result any pids allocated in nested pid namespaces are not memcg-accounted.
Pid struct in nested pid namespace consumes up to 500 bytes memory, 100000 such objects gives us up to ~50Mb unaccounted memory. This allow container to exceed assigned memcg limits.
For me this issue lookslike bug and I would like to ask to push this fix both to upstream and to stable
Vasily Averin (1):
memcg: enable accounting for pids in nested pid namespaces
kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/1 memcg: enable accounting for pids in nested pid namespaces
In reply to Vasily AverinCommit 5d097056c9a0 ("kmemcg: account certain kmem allocations to memcg") enabled memcg accounting for pids allocated from init_pid_ns.pid_cachep, but forgot to adjust the setting for nested pid namespaces.
As a result, pid memory is not accounted exactly where it is really needed, inside memcg-limited containers with their own pid namespaces.
Pid was one the first kernel objects enabled for memcg accounting. init_pid_ns.pid_cachep marked by SLAB_ACCOUNT and we can expect that any new pids in the system are memcg-accounted.
Though recently I've noticed that it is wrong. nested pid namespaces creates own slab caches for pid objects, nested pids have increased size because contain id both for all parent and for own pid namespaces. The problem is that these slab caches are _NOT_ marked by SLAB_ACCOUNT, as a result any pids allocated in nested pid namespaces are not memcg-accounted.
Pid struct in nested pid namespace consumes up to 500 bytes memory, 100000 such objects gives us up to ~50Mb unaccounted memory, this allow container to exceed assigned memcg limits.
--- kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/pid_namespace.c +2 -1
@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cachep(unsigned int level)mutex_lock (&pid_caches_mutex);/* Name collision forces to do allocation under mutex. */ if (!*pkc) - *pkc =kmem_cache_create (name, len,0 ,SLAB_HWCACHE_ALIGN ,0 ); + *pkc =kmem_cache_create (name, len,0 , +SLAB_HWCACHE_ALIGN |SLAB_ACCOUNT ,0 );mutex_unlock (&pid_caches_mutex);/* current can fail, but someone else can succeed. */ return READ_ONCE (*pkc);
Signature · 1 line
1.8.3.1
Quoted 21 lines · Vasily Averin
Commit
5d097056c9a0("kmemcg: account certain kmem allocations to memcg") enabled memcg accounting for pids allocated from init_pid_ns.pid_cachep, but forgot to adjust the setting for nested pid namespaces.
As a result, pid memory is not accounted exactly where it is really needed, inside memcg-limited containers with their own pid namespaces.Pid was one the first kernel objects enabled for memcg accounting. init_pid_ns.pid_cachep marked by
SLAB_ACCOUNTand we can expect that any new pids in the system are memcg-accounted.Though recently I've noticed that it is wrong. nested pid namespaces creates own slab caches for pid objects, nested pids have increased size because contain id both for all parent and for own pid namespaces. The problem is that these slab caches are _NOT_ marked by
SLAB_ACCOUNT, as a result any pids allocated in nested pid namespaces are not memcg-accounted.Pid struct in nested pid namespace consumes up to 500 bytes memory, 100000 such objects gives us up to ~50Mb unaccounted memory, this allow container to exceed assigned memcg limits.
Quoted 6 lines
Fixes 5d097056c9a0 ("kmemcg: account certain kmem allocations to memcg")Signed-off-by Vasily Averin <[email protected]>Reviewed-by Michal Koutný <[email protected]>Acked-by Roman Gushchin <[email protected]>
Dear Andrew,
could you please pick up this patch and add
Thank you,
Vasily Averin
Quoted 45 lines · Vasily Averin
Commit
5d097056c9a0("kmemcg: account certain kmem allocations to memcg") enabled memcg accounting for pids allocated from init_pid_ns.pid_cachep, but forgot to adjust the setting for nested pid namespaces.
As a result, pid memory is not accounted exactly where it is really needed, inside memcg-limited containers with their own pid namespaces.Pid was one the first kernel objects enabled for memcg accounting. init_pid_ns.pid_cachep marked by
SLAB_ACCOUNTand we can expect that any new pids in the system are memcg-accounted.Though recently I've noticed that it is wrong. nested pid namespaces creates own slab caches for pid objects, nested pids have increased size because contain id both for all parent and for own pid namespaces. The problem is that these slab caches are _NOT_ marked by
SLAB_ACCOUNT, as a result any pids allocated in nested pid namespaces are not memcg-accounted.Pid struct in nested pid namespace consumes up to 500 bytes memory, 100000 such objects gives us up to ~50Mb unaccounted memory, this allow container to exceed assigned memcg limits.
Fixes 5d097056c9a0 ("kmemcg: account certain kmem allocations to memcg")Signed-off-by Vasily Averin <[email protected]>Reviewed-by Michal Koutný <mkoutny-IBi9RG/[email protected]>Acked-by Roman Gushchin <[email protected]>--- kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/pid_namespace.c +2
-1@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cachep(unsigned int level)mutex_lock (&pid_caches_mutex);/* Name collision forces to do allocation under mutex. */ if (!*pkc) - *pkc =kmem_cache_create (name, len,0 ,SLAB_HWCACHE_ALIGN ,0 ); + *pkc =kmem_cache_create (name, len,0 , +SLAB_HWCACHE_ALIGN |SLAB_ACCOUNT ,0 );mutex_unlock (&pid_caches_mutex);/* current can fail, but someone else can succeed. */ return READ_ONCE (*pkc);