Commit 18319498 authored by Vasily Averin's avatar Vasily Averin Committed by Linus Torvalds

memcg: enable accounting of ipc resources

When user creates IPC objects it forces kernel to allocate memory for
these long-living objects.

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

This patch enables accounting for IPC shared memory segments, messages
semaphores and semaphore's undo lists.

Link: https://lkml.kernel.org/r/d6507b06-4df6-78f8-6c54-3ae86e3b5339@virtuozzo.comSigned-off-by: default avatarVasily Averin <vvs@virtuozzo.com>
Reviewed-by: default avatarShakeel Butt <shakeelb@google.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Andrei Vagin <avagin@gmail.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Dmitry Safonov <0x7f454c46@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Roman Gushchin <guro@fb.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Yutian Yang <nglaive@gmail.com>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 30acd0bd
...@@ -147,7 +147,7 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params) ...@@ -147,7 +147,7 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params)
key_t key = params->key; key_t key = params->key;
int msgflg = params->flg; int msgflg = params->flg;
msq = kmalloc(sizeof(*msq), GFP_KERNEL); msq = kmalloc(sizeof(*msq), GFP_KERNEL_ACCOUNT);
if (unlikely(!msq)) if (unlikely(!msq))
return -ENOMEM; return -ENOMEM;
......
...@@ -514,7 +514,7 @@ static struct sem_array *sem_alloc(size_t nsems) ...@@ -514,7 +514,7 @@ static struct sem_array *sem_alloc(size_t nsems)
if (nsems > (INT_MAX - sizeof(*sma)) / sizeof(sma->sems[0])) if (nsems > (INT_MAX - sizeof(*sma)) / sizeof(sma->sems[0]))
return NULL; return NULL;
sma = kvzalloc(struct_size(sma, sems, nsems), GFP_KERNEL); sma = kvzalloc(struct_size(sma, sems, nsems), GFP_KERNEL_ACCOUNT);
if (unlikely(!sma)) if (unlikely(!sma))
return NULL; return NULL;
...@@ -1855,7 +1855,7 @@ static inline int get_undo_list(struct sem_undo_list **undo_listp) ...@@ -1855,7 +1855,7 @@ static inline int get_undo_list(struct sem_undo_list **undo_listp)
undo_list = current->sysvsem.undo_list; undo_list = current->sysvsem.undo_list;
if (!undo_list) { if (!undo_list) {
undo_list = kzalloc(sizeof(*undo_list), GFP_KERNEL); undo_list = kzalloc(sizeof(*undo_list), GFP_KERNEL_ACCOUNT);
if (undo_list == NULL) if (undo_list == NULL)
return -ENOMEM; return -ENOMEM;
spin_lock_init(&undo_list->lock); spin_lock_init(&undo_list->lock);
...@@ -1941,7 +1941,7 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid) ...@@ -1941,7 +1941,7 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid)
/* step 2: allocate new undo structure */ /* step 2: allocate new undo structure */
new = kvzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems, new = kvzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems,
GFP_KERNEL); GFP_KERNEL_ACCOUNT);
if (!new) { if (!new) {
ipc_rcu_putref(&sma->sem_perm, sem_rcu_free); ipc_rcu_putref(&sma->sem_perm, sem_rcu_free);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -2005,7 +2005,8 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, ...@@ -2005,7 +2005,8 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops,
if (nsops > ns->sc_semopm) if (nsops > ns->sc_semopm)
return -E2BIG; return -E2BIG;
if (nsops > SEMOPM_FAST) { if (nsops > SEMOPM_FAST) {
sops = kvmalloc_array(nsops, sizeof(*sops), GFP_KERNEL); sops = kvmalloc_array(nsops, sizeof(*sops),
GFP_KERNEL_ACCOUNT);
if (sops == NULL) if (sops == NULL)
return -ENOMEM; return -ENOMEM;
} }
......
...@@ -619,7 +619,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) ...@@ -619,7 +619,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
ns->shm_tot + numpages > ns->shm_ctlall) ns->shm_tot + numpages > ns->shm_ctlall)
return -ENOSPC; return -ENOSPC;
shp = kmalloc(sizeof(*shp), GFP_KERNEL); shp = kmalloc(sizeof(*shp), GFP_KERNEL_ACCOUNT);
if (unlikely(!shp)) if (unlikely(!shp))
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment