Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3576088pxv; Mon, 19 Jul 2021 03:48:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/YlrExwukY/GhDiwWYZ2scj/apf5ZfyDMPEjB1RXKA5ZYGq9U8Vk93XLR2rw47aJtIuNg X-Received: by 2002:a17:906:6050:: with SMTP id p16mr17154780ejj.43.1626691727306; Mon, 19 Jul 2021 03:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626691727; cv=none; d=google.com; s=arc-20160816; b=SRilXZTrSErEmuZ1rpqkqPCdXFGsbzr5CZNtQlPevzs+VIrxS8M3kSbdX99A+VfIH2 GTdhNCX8G4c5s3+ytA3jvKD+fSZIH6izpMnYsrZDuQKZ2OywpIa2B8HLOwNOr4QRPHGu o/Qce9dQCWpl8o4wLjoFo93vlzjvFs4LRWBHNMD0t33Ri6sHwAWqDrrfwBAGTfxVG2AE K20jCssdRqwFAWW9JTJRTAGdKenbftjLkJSXgn+uwR5lORDRr65hzPQ/6BsdiFEL6ks0 mbb8OXDqkEmD++sV9iUJOO0PDltvDBhizb+PG0mPdE18EbIcAK0w9aE/H33RGFR11gXy KpsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from:dkim-signature; bh=Ccnjp3FPBm3dwMYx93pYsjJGsGokrnefzYE+aVs2CiQ=; b=bEZS0lhAo+X+WdXEMRywvvv4TuBAcrvEQnzFP017LqqYf0L4+OR53GqG2ABcQ/g1eR B+oUG+JkazTIDBR0zbLL5q5liGKd9+5jEk+0mbsnGCLuD7jVjmansQVbQ8nbGB+S/7Rx v54/+EHdKeEMYw8W4lC8jPEhatyYJskK9G0Gl6ALOI0N1gGO26niDTCGrAClMeFFvQmN 5iq+p1LWTpwx9CFnk0NyIO4DdfZXXN3XmgsBXZB475UOQgNK2cWZfaQx9da57iHwhxoD pJs4dfv+A32hi123AkPnLOHOnZ5gzDRRTzseJ1q5I+WWai+JURMe/1xpBacUGc6CfhAf HvKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=x1Yhh5rv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jt22si13858405ejc.635.2021.07.19.03.48.24; Mon, 19 Jul 2021 03:48:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=x1Yhh5rv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236635AbhGSKFf (ORCPT + 99 others); Mon, 19 Jul 2021 06:05:35 -0400 Received: from relay.sw.ru ([185.231.240.75]:44852 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236397AbhGSKE7 (ORCPT ); Mon, 19 Jul 2021 06:04:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Date:Message-ID:Subject :From; bh=Ccnjp3FPBm3dwMYx93pYsjJGsGokrnefzYE+aVs2CiQ=; b=x1Yhh5rvbixmGXUoHUM HbzcgGvOB8QJEGZ0mE5+ApeKEarvMRL6f0xBJLoCffDGp6kymDV10o72K4EA6bvG3Z7TmiLWejWwH jQdMALfM1mxR7K+40utDLRBYf7q4J7c/pZiu2e00xmZtfRc9YZ6JolDHzKAtG2n/nYy5pBzk4VQ=; Received: from [10.93.0.56] by relay.sw.ru with esmtp (Exim 4.94.2) (envelope-from ) id 1m5QmI-004Rht-Cx; Mon, 19 Jul 2021 13:45:38 +0300 From: Vasily Averin Subject: [PATCH v5 12/16] memcg: enable accounting of ipc resources To: Andrew Morton Cc: cgroups@vger.kernel.org, Michal Hocko , Shakeel Butt , Johannes Weiner , Vladimir Davydov , Roman Gushchin , Alexey Dobriyan , Dmitry Safonov <0x7f454c46@gmail.com>, Yutian Yang , linux-kernel@vger.kernel.org References: Message-ID: Date: Mon, 19 Jul 2021 13:45:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Vasily Averin --- 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 6810276..a0d0577 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 971e75d..1a8b9f0 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 748933e..ab749be 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; -- 1.8.3.1