Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3786705pxv; Mon, 26 Jul 2021 12:02:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkZe1dhonRy/DhWOg3+JCJAKijXwz8XQSk8qSXFXG/GzgY9mo5rD39IjVXICRq+XRd//7y X-Received: by 2002:a05:6e02:1d0f:: with SMTP id i15mr13096651ila.199.1627326175583; Mon, 26 Jul 2021 12:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627326175; cv=none; d=google.com; s=arc-20160816; b=Pf2s6BsrtRXjXCY6CTaDHDRbhuBPR68QmjBrP0X4w7Qkksd0oIrxLuLpCuaNvosn+t HwIAWoxb6QOhpgs1Ly6e991oMRX1kxXC2sE5l2SX/C3YQuzZUCXJgMxw7Y1BW6HHdAdG Ihe3hWUjCtupnfee9llEkakJobWz0aglptF7GjasnK4fS5h4srNTkbw0GnrB5H7wTbuq CcYrOCW88lQbHGMaqipTNhfDtiomHSfrqfoC5/9AdJoRKhyCn+uge6akcYVhOXEcquVt bdm4EHPT9caAncpWFowHhDmRLdpu/0KhKX2NBSc+71m5+L3RuAEYC9JMZ59kdQSNVlUf IuVQ== 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=eiNBuIzgaaYgNM0ADMjFkIJQJaLTezMyOlN7tECRXyoPlzqTGU3A3UsLxcGoT+G907 PQst2SXpwiZrIuKnpRX1wf352eRr14Zym1QIYUuRymZyzgaEwl8iBGtxkYNWq8M8pfX7 2t7MkTRtC2P3sXID47s88/kNu0HTn2/3kgmQT6u08FTti2OCL8VWzPxw/nBKYuTzP8gt O9yYk2DO5PS1vt8I3ACBvQ9HQLj/Ehk+EaU2k2nAdONog2zoe6vNJ3NylEUDrUoM79GH 6W6tK0NPTC+xlvenlA0pbZccgNJciIKn36ERG6E7eAdh0wtVOpXuErRPewwhMvrOflpQ d3YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=fJg7jHp0; 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 p10si874956iov.66.2021.07.26.12.02.43; Mon, 26 Jul 2021 12:02:55 -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=fJg7jHp0; 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 S233285AbhGZSUq (ORCPT + 99 others); Mon, 26 Jul 2021 14:20:46 -0400 Received: from relay.sw.ru ([185.231.240.75]:55224 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232923AbhGZSUV (ORCPT ); Mon, 26 Jul 2021 14:20:21 -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=fJg7jHp0nLOCKiZRvSW shjBPrvwZFDautLw7asTY58rHCktPPFXvYpeUmXDGP4Llrjo6vcM76twwpiQCwRt4LzY/MYnhlRTp IfRU9n/mBlGXktU/RJIw05ivHFKfA+terzsuXL2OkgTq2FebvFmw+g3OU0PHQOXFWgFdo1gcbrU=; Received: from [10.93.0.56] by relay.sw.ru with esmtp (Exim 4.94.2) (envelope-from ) id 1m85qL-005JUI-1U; Mon, 26 Jul 2021 22:00:49 +0300 From: Vasily Averin Subject: [PATCH v6 07/16] 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: <9bf9d9bd-03b1-2adb-17b4-5d59a86a9394@virtuozzo.com> Message-ID: <8d06c97c-451f-474b-026f-b898e2566daf@virtuozzo.com> Date: Mon, 26 Jul 2021 22:00:48 +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