Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3264189lfo; Mon, 23 May 2022 00:16:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhCjhd9h/H9w9/PoxdhaxowuQCfz4Zue1lkWV8wLlu4B66cG1bYTeI4mRIdU+xhI80fPfR X-Received: by 2002:a17:90a:e388:b0:1df:ac20:df7d with SMTP id b8-20020a17090ae38800b001dfac20df7dmr25715977pjz.208.1653290206021; Mon, 23 May 2022 00:16:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653290206; cv=none; d=google.com; s=arc-20160816; b=VHoJ5mdHjPkD4VYOHUJgnx+Fbrtwo2Di5NcY9Sp1wl5cFVLwTG0DF/MVhfmIbZCOL1 LGzWCEBYS7oPxpSvU72qaFngMyQGdEIc17Ocbd/06A6JHKLk1Nl1Q5nz4Nf/wT94gwdt V46TxNVu8zR3d7ODtnJTuLURTBLiAvgRwpgGe0pluIts1942joR4wI5Qx+rFipXG4dod Cqsaptp+LfTqCH52u1CU6tmZBbwyvUIPAdUi+VCFRW39Ivl9RDxAwVQJiKPjGR8WuuhY 1GyZ8XJFVgksgmNUuNdnInDWSdHRqwWF6V1T07N20RF7addMtth+aMxq+fbHo/iLZMmz 4U/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:dkim-signature:date; bh=j1Ic3mvDcYYQoaAM4Rtpe+PbHlC8Anf6qFpf3CmzxYQ=; b=aSG86ZBHnpKlSaKfZB0aCtoAK5XsJuquzQVTbVm2UBUoTl64qECPg3SoFC2k7pqSwz 528JaRKIJXAKrPr4cGMVjxxswmnlm7Gkn+HG8LMaY+GaZ9vjr3YtUJksl/BAumLwnZAz byXfAJAfSclSKg9psPjNAHO7nNCDQaEGTIDQRzvGeFEDf2wYY0doShzbm+0QGLh5pXiG FeOkZT0wNxsEjXf32Z23uIPiXhyBRCtTDQqvz3XPUD1cuMA3XvUBoW/PblEdCdD1JaSy uE5yxXPzKtlQBis8PhGWEoary+6nRbaw6IbJdKpJv7wEgpahvaenYbuR9dLsFnwlSTnf lvyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Jjxd1bc+; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 16-20020a630410000000b003c1cf871642si8885495pge.389.2022.05.23.00.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:16:46 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Jjxd1bc+; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 382E38DDE1; Sun, 22 May 2022 23:34:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233862AbiEUAzy (ORCPT + 99 others); Fri, 20 May 2022 20:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229922AbiEUAzw (ORCPT ); Fri, 20 May 2022 20:55:52 -0400 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0BD664EB; Fri, 20 May 2022 17:55:48 -0700 (PDT) Date: Fri, 20 May 2022 17:55:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1653094547; h=from:from: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; bh=j1Ic3mvDcYYQoaAM4Rtpe+PbHlC8Anf6qFpf3CmzxYQ=; b=Jjxd1bc+QrIggNSu2l7tf8IPCa1bRlt3WS5aeT268REna6NQ17GRbKKQPSyDhaVU5KuBra TcOl+XDU3h6qALxunUSdmvjO3JqONsYr0wgZotdDpYjyoB3jKE9sAAx62c5K+PT/Tn3lA6 rbtlUnfktOIkoI+kh59UVVpEItAQx0I= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Vasily Averin Cc: Michal =?iso-8859-1?Q?Koutn=FD?= , Shakeel Butt , kernel@openvz.org, linux-kernel@vger.kernel.org, Vlastimil Babka , Michal Hocko , cgroups@vger.kernel.org Subject: Re: [PATCH 3/4] memcg: enable accounting for struct cgroup Message-ID: References: <20220519165325.GA2434@blackbody.suse.cz> <740dfcb1-5c5f-6a40-0f71-65f277f976d6@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 20, 2022 at 11:16:32PM +0300, Vasily Averin wrote: > On 5/20/22 10:24, Vasily Averin wrote: > > On 5/19/22 19:53, Michal Koutn? wrote: > >> On Fri, May 13, 2022 at 06:52:12PM +0300, Vasily Averin wrote: > >>> 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. > >> > >> What do you mean by this argument? > >> > >> (On bigger irons, the percpu components becomes dominant, e.g. struct > >> cgroup_rstat_cpu.) > > > > Michal, Shakeel, > > thank you very much for your feedback, it helps me understand how to improve > > the methodology of my accounting analyze. > > I considered the general case and looked for places of maximum memory allocations. > > Now I think it would be better to split all called allocations into: > > - common part, called for any cgroup type (i.e. cgroup_mkdir and cgroup_create), > > - per-cgroup parts, > > and focus on 2 corner cases: for single CPU VMs and for "big irons". > > It helps to clarify which allocations are accounting-important and which ones > > can be safely ignored. > > > > So right now I'm going to redo the calculations and hope it doesn't take long. > > common part: ~11Kb + 318 bytes percpu > memcg: ~17Kb + 4692 bytes percpu > cpu: ~2.5Kb + 1036 bytes percpu > cpuset: ~3Kb + 12 bytes percpu > blkcg: ~3Kb + 12 bytes percpu > pid: ~1.5Kb + 12 bytes percpu > perf: ~320b + 60 bytes percpu > ------------------------------------------- > total: ~38Kb + 6142 bytes percpu > currently accounted: 4668 bytes percpu > > Results: > a) I'll add accounting for cgroup_rstat_cpu and psi_group_cpu, > they are called in common part and consumes 288 bytes percpu. > b) It makes sense to add accounting for simple_xattr(), as Michal recommend, > especially because it can grow over 4kb > c) it looks like the rest of the allocations can be ignored > > Details are below > ('=' -- already accounted, '+' -- to be accounted, '~' -- see KERNFS, '?' -- perhaps later ) > > common part: > 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) > > 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 I'm curios, how do you generate these data? Just an idea: it could be a nice tool, placed somewhere in tools/cgroup/... Thanks!