Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4128882pxv; Mon, 26 Jul 2021 22:35:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzC+aFv6nw4CmWbzUfWVvy2N2NPQAsH8rQ6UBEkduSx+w+3Mn95ghTgQs5JtJ5hbJbDMbYi X-Received: by 2002:a05:6402:4cb:: with SMTP id n11mr25488247edw.292.1627364147851; Mon, 26 Jul 2021 22:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627364147; cv=none; d=google.com; s=arc-20160816; b=FTwm2PKMVbSQRbRZPCjMNn4PrkEpepO6J71xJi3BW0pU/jLkV3Z5czqlGbGmm11gtB YZHfJ4AQazaCTJRTrGGPLyk0wgXPfoWbe3FvCWb4/zy09VbejU3PbwCGzGYw6cGH4Aqr 5Vk0HoTzS5itWHlgOg8fg/oHIeLXtPmWVoIgbqBP+RtxpM/viCWZJBFarQYKS8UPvMLh 2ZkvtafnqlNfsupQCKCGGnf3VxpupKi4/wsBQOuUYIsalMLXel7D5L0+jAmS17uL0/wK 7GdueK1snyRpqHW6aLmVWGYk5Hj/eoHbsJ1xsdUVu6ydjtDjY3U0aP6f4HaRJzDUUals ZOsg== 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=bgm9OS9KolAL5uXELhf+0mY9tqnepOoZ0HrSZvp8ULM=; b=qwojff+c8X4p70y6lULKspEFOVceS92nxIWtT+GXQ1eNUW8/VqSU3wWSBb/icMhsCz LtucIJTh+18rTdDGyY+t4xSqmxFMMZDBKHFGDOPLzUgPIhmBn79HB9KQhXnTN7KHLyVd WDervVYuzN8JWSfYnEK+zta7ZHbYivUy38amEcUEklSd6DzNybo8ENeQQIFW49h1rlZ0 eY1k9DeB39QGE/ux4+StWdu0ascgtlMCC7dh2WvyB/xojPbXbF0KnR1dcSKiSEtjbkF+ c6ESKlKLeZCOezYA2LbjNm6v/L8ROQWw7hce9sHUZ0D8eBu3SZbGJmxBECqQvcnkAR+K IZeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=mryP5ZAM; 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 v19si2012108edr.353.2021.07.26.22.35.24; Mon, 26 Jul 2021 22:35: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=mryP5ZAM; 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 S235284AbhG0FdQ (ORCPT + 99 others); Tue, 27 Jul 2021 01:33:16 -0400 Received: from relay.sw.ru ([185.231.240.75]:40086 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235224AbhG0FdN (ORCPT ); Tue, 27 Jul 2021 01:33:13 -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=bgm9OS9KolAL5uXELhf+0mY9tqnepOoZ0HrSZvp8ULM=; b=mryP5ZAMsjNiRUaeLfk wjMaHKHdFfhWFXul5TtTUUie85cIgYHlzCYIm51LadlGPv4I/UrEJzQ9QVLU3a482hlaSgF7kdPTu nsg0g92VHHTwqdUuguYdbIkB0SO6Q7h8xjO7/uO8JxXMMnRy8Z7o9cX6iASwQikm28/twRvP/xk=; Received: from [10.93.0.56] by relay.sw.ru with esmtp (Exim 4.94.2) (envelope-from ) id 1m8FiL-005LW3-1c; Tue, 27 Jul 2021 08:33:13 +0300 From: Vasily Averin Subject: [PATCH v7 01/10] memcg: enable accounting for mnt_cache entries To: Andrew Morton Cc: cgroups@vger.kernel.org, Michal Hocko , Shakeel Butt , Johannes Weiner , Vladimir Davydov , Roman Gushchin , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <6f21a0e0-bd36-b6be-1ffa-0dc86c06c470@virtuozzo.com> Message-ID: <045db11f-4a45-7c9b-2664-5b32c2b44943@virtuozzo.com> Date: Tue, 27 Jul 2021 08:33:12 +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 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 --- 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