Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1541601pxb; Thu, 16 Sep 2021 09:33:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwjI+Pjeqbs4/NDACh9cx65X9FlGu5Sv8bG1HBMkVkmxpIGbqceUqjo5Z6/R0qDgp7+ijb X-Received: by 2002:a5e:d513:: with SMTP id e19mr4950639iom.82.1631809995401; Thu, 16 Sep 2021 09:33:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809995; cv=none; d=google.com; s=arc-20160816; b=wannjNPTblpDk8koCebkOGlFw7gty2jnb8MzBduLrRvTDb+YBpx2IGSJth+P7uOT/X WomOJ1YHNgkW+ZaX0bbwHD1Or2jIqDTkb7GJ1OwwqV18FpV6h+KuqEzkA0vnKeH5aJY+ qOEku4LWjcnL9uJl35pEd1lfLlmMRHO9rAQtlnRa0tJwE3M+ESmOOz+bK1v0Q59ZIS8I xyl4Kf8p3CWEyloCBWVMTTxhXOn5X8RYXE/web7DsGon1ADRX/Wi8Rj75SIVTxlmaeDh ApwrWTS1aTxNd+tdvfkJUzh3h5fxVfXx4DIebSBWk8xOC9OPPLDj4YrVWyofCaP+ZAgz VSwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Mwj+Q1i0qxf9pnnORvtWcjOjLxkF8FmXvXam7s1WeLY=; b=vrz2S7IUOsQ3D87OBZBvAIOXOnf6ziYncA9SrDJ6gornNCjDU4Px0LdgkpkC96REhn AOMZzm/APkz1DCNTH8aKxm9Ce6tVCvDOpZ3JNaG9O7DD+lR4AJ3723IuC/j2dRVQpeEI mFo+sm9yWCet/MwNLeYErkvn2RgmgQPAOMeYvPF1SyAc1S4PBm4+xupUkS24AIn9LtRF EIiWQADvy244p6EsCjf2XOS5bfaf6UaJSMZDy8Qh8IPqe5AD8DtK/vHRVhsetnKh7Ocf t1cXBbwFh/edmUhQGVE8dxppjTbLx8Bx9euILphq7t+cyFD/8HJrJrxrKBujFvRQSl8i J1BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q54cdi+M; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si2754833ilk.74.2021.09.16.09.33.03; Thu, 16 Sep 2021 09:33:15 -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=@linuxfoundation.org header.s=korg header.b=q54cdi+M; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242976AbhIPQca (ORCPT + 99 others); Thu, 16 Sep 2021 12:32:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:59350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240889AbhIPQX5 (ORCPT ); Thu, 16 Sep 2021 12:23:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7626760F8F; Thu, 16 Sep 2021 16:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808972; bh=Lx/7dvfq/ZH0FLfRLQXCRbj4o1l2TjiKGWN5OXRUYgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q54cdi+M30pqyDq3V/Dmv3x+dQav8vQLVLmVRGL98o+czBMZwfpbtiycHPwTOWrat EN6naV+CAjY+Me+rE3tt4ALWNxCylB3sML6Swi5XqysQ8geFN/7nPeCwtdAph2utep FYBJ6jk6vHdmAVlALNjz8GMZGetaNpRMYCEbjYTg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vasily Averin , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Shakeel Butt , Christian Brauner , Roman Gushchin , Michal Hocko , Johannes Weiner , Andrew Morton , Linus Torvalds Subject: [PATCH 5.10 291/306] memcg: enable accounting for pids in nested pid namespaces Date: Thu, 16 Sep 2021 18:00:36 +0200 Message-Id: <20210916155804.021257012@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vasily Averin commit fab827dbee8c2e06ca4ba000fa6c48bcf9054aba upstream. 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_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. Link: https://lkml.kernel.org/r/8b6de616-fd1a-02c6-cbdb-976ecdcfa604@virtuozzo.com Fixes: 5d097056c9a0 ("kmemcg: account certain kmem allocations to memcg") Cc: stable@vger.kernel.org Signed-off-by: Vasily Averin Reviewed-by: Michal Koutný Reviewed-by: Shakeel Butt Acked-by: Christian Brauner Acked-by: Roman Gushchin Cc: Michal Hocko Cc: Johannes Weiner Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cac 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);