From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFB16C433FE for ; Sat, 21 May 2022 16:37:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 459956B0078; Sat, 21 May 2022 12:37:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B9DD6B007B; Sat, 21 May 2022 12:37:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 234826B007D; Sat, 21 May 2022 12:37:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0CEA36B0078 for ; Sat, 21 May 2022 12:37:40 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D756233C26 for ; Sat, 21 May 2022 16:37:39 +0000 (UTC) X-FDA: 79490306238.17.F0D1961 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) by imf07.hostedemail.com (Postfix) with ESMTP id 36B8E4000F for ; Sat, 21 May 2022 16:37:30 +0000 (UTC) Received: by mail-lj1-f171.google.com with SMTP id s5so12624025ljd.10 for ; Sat, 21 May 2022 09:37:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:from:subject:to:cc :references:content-language:in-reply-to:content-transfer-encoding; bh=xrngHl+k++nVK8AbvZFVt0lPwWgRKfDuqq3cdMG2V38=; b=f1PXoIqYpQV8rPyrcOXuJMO+8R6A7YB7wOl2JgT1Hf6DAW3jEWx8DiwYevJN9foxuT xqiD1JUsuSwtjJZzckPQ3HIyQb9qTI5GEoRhiia9vtQ1x5RRZdszPcxAfZwYVEI5c33b VjnW9ysQLT9rOXQIiehcO96AGCYWBcl4Amg6kyIghtr3Q0+4ub1xxGeYiUIjoUksEB7o X/6VCEapIUnJBuwQ/DxpPiakNFhwFkl9PWhuGlK64PbQVDgPjgD5RGN8Q/2bPlNgcAPY 6q7Eymqt7gNxIWnXR/Qc5Ho3xK7NewmCD2fraMyhTaUzx2AQl+FnXT2wNDTbKpRYFgAj gQMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:references:content-language:in-reply-to :content-transfer-encoding; bh=xrngHl+k++nVK8AbvZFVt0lPwWgRKfDuqq3cdMG2V38=; b=YKuYUfqpuALup0FSSa6h7uowhuNs0mfM8KIJy0EUGVN47rxLT3JaPUMq/2/elZsXby I8SiDh1zmXMT/bvqkhPL8m2A7bDtMoytYO4NgHDVLyrn/jClNKWDArrtYcg/csrUDRst f9YwywNkG2rdnMDkgm4HLU/W1vi0UZFg3HZmAsoDKejIvyVwdCCQeYYsLGlijBmFK5Vl kC3kifSud5bRN1uPWKiomFdtS966cNOiXHuaNGtZkaf/Lqt2plraQcFrFgsx2dCxQD6n hr2PSoTMmVC/wIQ7T3JgKrn+yDRbD2pRljTUqfhGj12HrJRbyIL5n6K5rScrprWdZX6l ZM+A== X-Gm-Message-State: AOAM530Mhqk/PNO0nQC9V8NYLSRJZIyxOtS3AUuQbPCUxqc0mTVCuRH9 YewwsU7pdjv13nk0DQO7Jvq+zQ== X-Google-Smtp-Source: ABdhPJyK+2dAF2mDmvzbdrtAY2ubkJvsKXq+zufNECKywzZuKACWqwQFPtM6ejdRbkkXoekoqH7oSw== X-Received: by 2002:a2e:a493:0:b0:253:d23f:16d9 with SMTP id h19-20020a2ea493000000b00253d23f16d9mr8212181lji.446.1653151058102; Sat, 21 May 2022 09:37:38 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.185]) by smtp.gmail.com with ESMTPSA id f5-20020ac24e45000000b0047255d21141sm1116573lfr.112.2022.05.21.09.37.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 May 2022 09:37:37 -0700 (PDT) Message-ID: Date: Sat, 21 May 2022 19:37:36 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 From: Vasily Averin Subject: [PATCH mm v2 1/9] memcg: enable accounting for struct cgroup To: Andrew Morton Cc: kernel@openvz.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Roman Gushchin , =?UTF-8?Q?Michal_Koutn=c3=bd?= , Vlastimil Babka , Michal Hocko , cgroups@vger.kernel.org References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: 36B8E4000F X-Stat-Signature: 338hpu84554u8az3dtx7kzsrqji7wwp9 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=f1PXoIqY; spf=pass (imf07.hostedemail.com: domain of vvs@openvz.org designates 209.85.208.171 as permitted sender) smtp.mailfrom=vvs@openvz.org; dmarc=pass (policy=none) header.from=openvz.org X-Rspamd-Server: rspam03 X-HE-Tag: 1653151050-959281 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Creating each new cgroup allocates 4Kb for struct cgroup. This is the largest memory allocation in this scenario and is epecially important for small VMs with 1-2 CPUs. Common part of the cgroup creation: Allocs Alloc $1*$2 Sum Allocation number size -------------------------------------------- 16 ~ 352 5632 5632 KERNFS 1 + 4096 4096 9728 (cgroup_mkdir+0xe4) 1 584 584 10312 (radix_tree_node_alloc.constprop.0+0x89) 1 192 192 10504 (__d_alloc+0x29) 2 72 144 10648 (avc_alloc_node+0x27) 2 64 128 10776 (percpu_ref_init+0x6a) 1 64 64 10840 (memcg_list_lru_alloc+0x21a) percpu: 1 + 192 192 192 call_site=psi_cgroup_alloc+0x1e 1 + 96 96 288 call_site=cgroup_rstat_init+0x5f 2 12 24 312 call_site=percpu_ref_init+0x23 1 6 6 318 call_site=__percpu_counter_init+0x22 '+' -- to be accounted, '~' -- partially accounted Accounting of this memory helps to avoid misuse inside memcg-limited containers. Signed-off-by: Vasily Averin Reviewed-by: Roman Gushchin Reviewed-by: Michal Koutný Acked-by: Shakeel Butt --- kernel/cgroup/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index adb820e98f24..7595127c5b3a 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -5353,7 +5353,7 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name, /* allocate the cgroup and its ID, 0 is reserved for the root */ cgrp = kzalloc(struct_size(cgrp, ancestor_ids, (level + 1)), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!cgrp) return ERR_PTR(-ENOMEM); -- 2.36.1