The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at 
https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit 899e3fad3c7990c02edf637cfe882b055b380f7b
Author: Vasily Averin <v...@virtuozzo.com>
Date:   Tue Sep 28 14:16:23 2021 +0300

    ms/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-3ae86e3b5...@virtuozzo.com
    Signed-off-by: Vasily Averin <v...@virtuozzo.com>
    
    Reviewed-by: Shakeel Butt <shake...@google.com>
    Cc: Alexander Viro <v...@zeniv.linux.org.uk>
    Cc: Alexey Dobriyan <adobri...@gmail.com>
    Cc: Andrei Vagin <ava...@gmail.com>
    Cc: Borislav Petkov <b...@alien8.de>
    Cc: Borislav Petkov <b...@suse.de>
    Cc: Christian Brauner <christian.brau...@ubuntu.com>
    Cc: Dmitry Safonov <0x7f454...@gmail.com>
    Cc: "Eric W. Biederman" <ebied...@xmission.com>
    Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
    Cc: "H. Peter Anvin" <h...@zytor.com>
    Cc: Ingo Molnar <mi...@redhat.com>
    Cc: "J. Bruce Fields" <bfie...@fieldses.org>
    Cc: Jeff Layton <jlay...@kernel.org>
    Cc: Jens Axboe <ax...@kernel.dk>
    Cc: Jiri Slaby <jirisl...@kernel.org>
    Cc: Johannes Weiner <han...@cmpxchg.org>
    Cc: Kirill Tkhai <ktk...@virtuozzo.com>
    Cc: Michal Hocko <mho...@kernel.org>
    Cc: Oleg Nesterov <o...@redhat.com>
    Cc: Roman Gushchin <g...@fb.com>
    Cc: Serge Hallyn <se...@hallyn.com>
    Cc: Tejun Heo <t...@kernel.org>
    Cc: Thomas Gleixner <t...@linutronix.de>
    Cc: Vladimir Davydov <vdavydov....@gmail.com>
    Cc: Yutian Yang <ngla...@gmail.com>
    Cc: Zefan Li <lizefa...@bytedance.com>
    Signed-off-by: Andrew Morton <a...@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torva...@linux-foundation.org>
    (cherry picked from commit 18319498fdd4cdf8c1c2c48cd432863b1f915d6f)
    https://jira.sw.ru/browse/PSBM-133990
    Signed-off-by: Vasily Averin <v...@virtuozzo.com>
---
 ipc/msg.c | 2 +-
 ipc/sem.c | 9 +++++----
 ipc/shm.c | 2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/ipc/msg.c b/ipc/msg.c
index 6810276d6bb9..a0d05775af2c 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -147,7 +147,7 @@ static int newque(struct ipc_namespace *ns, struct 
ipc_params *params)
        key_t key = params->key;
        int msgflg = params->flg;
 
-       msq = kmalloc(sizeof(*msq), GFP_KERNEL);
+       msq = kmalloc(sizeof(*msq), GFP_KERNEL_ACCOUNT);
        if (unlikely(!msq))
                return -ENOMEM;
 
diff --git a/ipc/sem.c b/ipc/sem.c
index 971e75d28364..1a8b9f0ac047 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -514,7 +514,7 @@ static struct sem_array *sem_alloc(size_t nsems)
        if (nsems > (INT_MAX - sizeof(*sma)) / sizeof(sma->sems[0]))
                return NULL;
 
-       sma = kvzalloc(struct_size(sma, sems, nsems), GFP_KERNEL);
+       sma = kvzalloc(struct_size(sma, sems, nsems), GFP_KERNEL_ACCOUNT);
        if (unlikely(!sma))
                return NULL;
 
@@ -1855,7 +1855,7 @@ static inline int get_undo_list(struct sem_undo_list 
**undo_listp)
 
        undo_list = current->sysvsem.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)
                        return -ENOMEM;
                spin_lock_init(&undo_list->lock);
@@ -1941,7 +1941,7 @@ static struct sem_undo *find_alloc_undo(struct 
ipc_namespace *ns, int semid)
 
        /* step 2: allocate new undo structure */
        new = kvzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems,
-                      GFP_KERNEL);
+                      GFP_KERNEL_ACCOUNT);
        if (!new) {
                ipc_rcu_putref(&sma->sem_perm, sem_rcu_free);
                return ERR_PTR(-ENOMEM);
@@ -2005,7 +2005,8 @@ static long do_semtimedop(int semid, struct sembuf __user 
*tsops,
        if (nsops > ns->sc_semopm)
                return -E2BIG;
        if (nsops > SEMOPM_FAST) {
-               sops = kvmalloc_array(nsops, sizeof(*sops), GFP_KERNEL);
+               sops = kvmalloc_array(nsops, sizeof(*sops),
+                                     GFP_KERNEL_ACCOUNT);
                if (sops == NULL)
                        return -ENOMEM;
        }
diff --git a/ipc/shm.c b/ipc/shm.c
index 748933e376ca..ab749be6d8b7 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -619,7 +619,7 @@ static int newseg(struct ipc_namespace *ns, struct 
ipc_params *params)
                        ns->shm_tot + numpages > ns->shm_ctlall)
                return -ENOSPC;
 
-       shp = kmalloc(sizeof(*shp), GFP_KERNEL);
+       shp = kmalloc(sizeof(*shp), GFP_KERNEL_ACCOUNT);
        if (unlikely(!shp))
                return -ENOMEM;
 
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to