2021-07-27 05:35:48

by Vasily Averin

[permalink] [raw]
Subject: [PATCH v7 01/10] memcg: enable accounting for mnt_cache entries

The kernel allocates ~400 bytes of 'strcut mount' for any new mount.
Creating a new mount namespace clones most of the parent mounts,
and this can be repeated many times. Additionally, each mount allocates
up to PATH_MAX=4096 bytes for mnt->mnt_devname.

It makes sense to account for these allocations to restrict the host's
memory consumption from inside the memcg-limited container.

Signed-off-by: Vasily Averin <[email protected]>
---
fs/namespace.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index ab4174a..c6a74e5 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -203,7 +203,8 @@ static struct mount *alloc_vfsmnt(const char *name)
goto out_free_cache;

if (name) {
- mnt->mnt_devname = kstrdup_const(name, GFP_KERNEL);
+ mnt->mnt_devname = kstrdup_const(name,
+ GFP_KERNEL_ACCOUNT);
if (!mnt->mnt_devname)
goto out_free_id;
}
@@ -4222,7 +4223,7 @@ void __init mnt_init(void)
int err;

mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct mount),
- 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
+ 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL);

mount_hashtable = alloc_large_system_hash("Mount-cache",
sizeof(struct hlist_head),
--
1.8.3.1


2021-07-27 06:46:23

by Shakeel Butt

[permalink] [raw]
Subject: Re: [PATCH v7 01/10] memcg: enable accounting for mnt_cache entries

On Mon, Jul 26, 2021 at 10:33 PM Vasily Averin <[email protected]> wrote:
>
> The kernel allocates ~400 bytes of 'strcut mount' for any new mount.

*struct mount*

> Creating a new mount namespace clones most of the parent mounts,
> and this can be repeated many times. Additionally, each mount allocates
> up to PATH_MAX=4096 bytes for mnt->mnt_devname.
>
> It makes sense to account for these allocations to restrict the host's
> memory consumption from inside the memcg-limited container.
>
> Signed-off-by: Vasily Averin <[email protected]>

Reviewed-by: Shakeel Butt <[email protected]>

2021-07-27 07:23:24

by Christian Brauner

[permalink] [raw]
Subject: Re: [PATCH v7 01/10] memcg: enable accounting for mnt_cache entries

On Tue, Jul 27, 2021 at 08:33:12AM +0300, Vasily Averin wrote:
> The kernel allocates ~400 bytes of 'strcut mount' for any new mount.
> Creating a new mount namespace clones most of the parent mounts,
> and this can be repeated many times. Additionally, each mount allocates
> up to PATH_MAX=4096 bytes for mnt->mnt_devname.
>
> It makes sense to account for these allocations to restrict the host's
> memory consumption from inside the memcg-limited container.
>
> Signed-off-by: Vasily Averin <[email protected]>
> ---

Looks good. Thank you!
Acked-by: Christian Brauner <[email protected]>

I wonder how much this increases reported memory consumption when you
boot full system containers that run systemd and a bunch of systemd
services that each use a separate mount namespace.