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 A4888C433EF for ; Mon, 13 Jun 2022 05:34:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3901D8D0150; Mon, 13 Jun 2022 01:34:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 318E68D0142; Mon, 13 Jun 2022 01:34:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16C1D8D0150; Mon, 13 Jun 2022 01:34:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 043378D0142 for ; Mon, 13 Jun 2022 01:34:45 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id DA0CA60BC8 for ; Mon, 13 Jun 2022 05:34:44 +0000 (UTC) X-FDA: 79572098088.01.5BEB0B4 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by imf19.hostedemail.com (Postfix) with ESMTP id 8A7281A0083 for ; Mon, 13 Jun 2022 05:34:44 +0000 (UTC) Received: by mail-lf1-f53.google.com with SMTP id w20so7079448lfa.11 for ; Sun, 12 Jun 2022 22:34:44 -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=vVFg1kFJ1ZrAuYqNU+G4M2YG4vffoF6tfug6s1kVYgc=; b=Tu0ulCRi9G/dXEAfgaijmX0Oo+JHLmSXnmrJ+MEuxOIvzY3vhXf0LacSOeN87REMdt 0EqL9howlhfqHTYOCyGIVa5yxvuBcSAQ+J5glfRzw1ieygNZvfqcNJp/hQEadqGHIoBk cVwK70e7kA/PCPZ5d4ZK0wPzt33x/rXcNf75GLCkQJ4/9yah+076fyA0Mwtpd4DFVtTE OEe7Av8QYdWetO9Jfkjje1xVuCyvJXcNowOmDKUgUK2/xylEl0nTMyJoPhlRkQlkUliw H6ZJSkmEBCbS2XIUcoiGJCr8kg+4ug0gZ3OfnLNzV6l/B7ci7LgBuBznFgJr3hgP3NQw hYDA== 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=vVFg1kFJ1ZrAuYqNU+G4M2YG4vffoF6tfug6s1kVYgc=; b=Q1w2TA0VilnW2GPc3c+to6xNJ1RYFv1NOka1Z70Jq/A91cl4ETk3a5aTZcU8UQBdBF OA7Z/6tN93RCUoD98cwXIalBU7QURi3IAUsvv4kC9zi6/hlBte0cgKSv3j6Z86mZDiO5 344T+6oZRSx9KrHTdIXd691r4oQsuukzYVXI3C7ZF8Bqfq759khbVSNICNeySjFD4pGN p358i94hNiRHOUNmwk73i367lOxo08XsLF+uc8GB1Za1qL06b8AcAFcJhUIXzPP3ONIU OE4u64LePYxKABE9aHpKeBdLlHnnaXJ5WFWHYctmpaoamhTkJt98tbdpY85bhK6pTpDk 7zKA== X-Gm-Message-State: AOAM532Q8f1zzT/DNC8Va/ChuJnluLkr4Yx07nJDai4jZX6QfawwuAwX A/vtFPGHrUTfwviecow4AM+T7w== X-Google-Smtp-Source: ABdhPJz9g22UtbqUqRQrAPjssQkh/JLrsa/hrQftvJymHjpwcOduOutW0vw/76d3RMB9I39vIXRfzw== X-Received: by 2002:a19:5f1d:0:b0:478:f072:8dc9 with SMTP id t29-20020a195f1d000000b00478f0728dc9mr35072871lfb.440.1655098483186; Sun, 12 Jun 2022 22:34:43 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id p13-20020ac246cd000000b0047db8b30670sm845259lfo.136.2022.06.12.22.34.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:34:42 -0700 (PDT) Message-ID: <4c393a46-f6cf-ce8a-7771-81cbbc9ca278@openvz.org> Date: Mon, 13 Jun 2022 08:34:42 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 From: Vasily Averin Subject: [PATCH mm v4 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 , Muchun Song , cgroups@vger.kernel.org References: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655098484; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vVFg1kFJ1ZrAuYqNU+G4M2YG4vffoF6tfug6s1kVYgc=; b=olY40OoHv/p0rc4R39jPA7vLYhDqtSVBPLs1SqkZj4edK9TBIQuebRJLjVdhuj10o99JmY dE00msGDAUu8MAxoe402Z3Ewuc1mLZBZ5RueDVCo5Z/BdQuGaZJ6amADKeS3CYBmijgB06 lhbI1pqjWgKqxuO6gXQe+9cscsbQZgc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=Tu0ulCRi; dmarc=pass (policy=none) header.from=openvz.org; spf=pass (imf19.hostedemail.com: domain of vvs@openvz.org designates 209.85.167.53 as permitted sender) smtp.mailfrom=vvs@openvz.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655098484; a=rsa-sha256; cv=none; b=gLiJfT+9be2VskApEGmpdoXs8WuIiJ5PJvT83YQn6AYr0H7W4oy42QW6dMzY+ZLzZa+2qn zc2KQiv5s0qxxVbUUCMFJ53cTl9r6ZQxdWz+XV33M1pITedgtZ+ND7Fb7tc1PewMXuW9La UnP8tk48cFNhXFbtbMNJpnFZjQQr0U0= X-Stat-Signature: apizg3pd11gw398sozw4f8fkzkepwmfp X-Rspamd-Queue-Id: 8A7281A0083 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=Tu0ulCRi; dmarc=pass (policy=none) header.from=openvz.org; spf=pass (imf19.hostedemail.com: domain of vvs@openvz.org designates 209.85.167.53 as permitted sender) smtp.mailfrom=vvs@openvz.org X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1655098484-639539 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 Reviewed-by: Muchun Song --- 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 90a654cb8a1e..9adf4ad4b623 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