Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6829531iob; Wed, 11 May 2022 06:20:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6U1N0UFjpISWvDzEgQecZ9+DfD4tkF/cVUhYXkPf79ypALDHwLubhtTRq7h13so0REnIU X-Received: by 2002:a05:6402:d05:b0:425:b7ab:776e with SMTP id eb5-20020a0564020d0500b00425b7ab776emr28912392edb.142.1652275220738; Wed, 11 May 2022 06:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652275220; cv=none; d=google.com; s=arc-20160816; b=DJwYJXvn0t+2bn/1VKRr8+SpLpC5aSSQyI83y3B2LNkhSJ0MNhwm6IdTFYa1peUGIm ZufoRuinlwDu2ruMj9y3sWOafDXKP62Z9b+e4zS+HD1puBBtBeUmpy0TjrWM28OeXPM4 gAC3c9XEAfCxYdXRtB1uHXavzkZq9s6I+CeFSxGXX0uPmG51VrF9TrySqDgnkE+/a7Wz GxOgw/nix04NgqJ7aZVc33piTkQt8nn9ya2BXUCYQZrDCnjCXcG82KToLI9Tp9Hdc914 1mOQPQi1WT665A5epVsXUIsg2HogdkgOrXXnhZKgpnajp9dz1CV/rX3mC96SoUJPQAzv 7pEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=KG2LP7lqw9uskhHUdz+/neRzxuQzhpKu6yMc7xnK/Nw=; b=0J+GyZt0lHyhHaP6JbYoxiUHC2B+LDVYUujAYtmZxYvHVmuoLzlstGgLgqQYfceikN BoZ8FVZev9+50CQIm+PAIBnX7IDcMO9jUe8nWzw2hLaf5n8oRZ38FyH7EYHaBI1+n1OF hhS5IwEqoa5oSv9IfvU5+a64dryfIuLoDJE7MQhTLoBjyVhWe1eH7U+idnRdVDhQcgzJ sdfoUvbtdJyf3uRFwGTghm6Cd8yEECgbV+rTy7slKpxK7gO4mG4hsEsyPiP9/72mk1oW py1iE522RtUXUx/Vi3My/LanJb9rlUXdJQsj+uO+cjvK3r+fHjWncg4dNvG2o0rmdzGG m/Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=ymECTCTf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc7-20020a1709071c0700b006f3a3d0956fsi2660189ejc.473.2022.05.11.06.19.56; Wed, 11 May 2022 06:20:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=ymECTCTf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236628AbiEKGBt (ORCPT + 99 others); Wed, 11 May 2022 02:01:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234147AbiEKGBp (ORCPT ); Wed, 11 May 2022 02:01:45 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1DA132EE3 for ; Tue, 10 May 2022 23:01:43 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id u23so1724571lfc.1 for ; Tue, 10 May 2022 23:01:43 -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:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=KG2LP7lqw9uskhHUdz+/neRzxuQzhpKu6yMc7xnK/Nw=; b=ymECTCTfY6HysdomwfmKw5QWUX/LYJLfLVPUX3cID7988CkBbdzv4Aku3xtSvlHixS mLEUKjlqqEjDC/D0dqLnlo2CRSmatHUUKoX0cT2CfKO7C856mRyrIXYdTvYhusfPWxLA qgK4HNLVdHR50zn89GYGFuYzzQIPmwysOCOoGl0fi6a9fVknY6UH33Yk/lLXJvqdaKZC tphhA4klMvM9w/djtKoUNrB6JxH51OCpzoP6u8mQ2MulTxFfP9ygmlYJ2tbJQw5owmHm oC8clKUaILQ+G8AYEjejlZG6vDBahYAeBM+8p9Y3+ALCzbkyKzV6zMJwTti7o7nYmmsO mYrA== 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:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=KG2LP7lqw9uskhHUdz+/neRzxuQzhpKu6yMc7xnK/Nw=; b=soQ+vxYFiKNiU67yoTqToVf/2xVGQxDXQ+uQ2/7MgIwrd+6UBVRDtFOkfrp5nLieP2 PnMlnVmHgWsSr1QzlhWvUeS5EiI6z5Fitah9iobjWKuJlGcJw49+5VkQrRhPiGXq0Qyu e177Sn5kqsn9VCpSbeA5Z50GQHytC9mCTKZTBti4WjHRCGHOWgubrOuPWnJEEspz3nA/ 9Kd8IH7JbrGhXuKaMZ40rb/jKCKOJ7DHfOJDQggJO4v1eiD5a6mPiomxI6UzvO3D8TT3 F1MN4rMpeCgTRl4gz02TxP9QouZE86qvarYktaVMONmrh1wXKy12PiGBOBCeeVKv8QMe TTuA== X-Gm-Message-State: AOAM531miLRkzaQPfjq7qTWYWmmORidhAR/b/dC0duBTZPvC3l0Fd70u OUlG6xFwe36N2lucWJk3UI6MFg== X-Received: by 2002:a19:6905:0:b0:472:4d89:c49b with SMTP id e5-20020a196905000000b004724d89c49bmr18645249lfc.137.1652248901942; Tue, 10 May 2022 23:01:41 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.177]) by smtp.gmail.com with ESMTPSA id v26-20020a2e925a000000b00250749dab23sm167874ljg.99.2022.05.10.23.01.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 May 2022 23:01:41 -0700 (PDT) Message-ID: <0eec6575-548e-23e0-0d99-4e079a33d338@openvz.org> Date: Wed, 11 May 2022 09:01:40 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: kernfs memcg accounting Content-Language: en-US To: Roman Gushchin Cc: =?UTF-8?Q?Michal_Koutn=c3=bd?= , Vlastimil Babka , Shakeel Butt , kernel@openvz.org, Florian Westphal , linux-kernel@vger.kernel.org, Michal Hocko , cgroups@vger.kernel.org, Greg Kroah-Hartman , Tejun Heo References: <7e867cb0-89d6-402c-33d2-9b9ba0ba1523@openvz.org> <20220427140153.GC9823@blackbody.suse.cz> <7509fa9f-9d15-2f29-cb2f-ac0e8d99a948@openvz.org> <52a9f35b-458b-44c4-7fc8-d05c8db0c73f@openvz.org> From: Vasily Averin In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 5/11/22 06:06, Roman Gushchin wrote: > On Wed, May 04, 2022 at 12:00:18PM +0300, Vasily Averin wrote: >> From my point of view it is most important to account allocated memory >> to any cgroup inside container. Select of proper memcg is a secondary goal here. >> Frankly speaking I do not see a big difference between memcg of current process, >> memcg of newly created child and memcg of its parent. >> >> As far as I understand, Roman chose the parent memcg because it was a special >> case of creating a new memory group. He temporally changed active memcg >> in mem_cgroup_css_alloc() and properly accounted all required memcg-specific >> allocations. > > My primary goal was to apply the memory pressure on memory cgroups with a lot > of (dying) children cgroups. On a multi-cpu machine a memory cgroup structure > is way larger than a page, so a cgroup which looks small can be really large > if we calculate the amount of memory taken by all children memcg internals. > > Applying this pressure to another cgroup (e.g. the one which contains systemd) > doesn't help to reclaim any pages which are pinning the dying cgroups. > > For other controllers (maybe blkcg aside, idk) it shouldn't matter, because > there is no such problem there. > > For consistency reasons I'd suggest to charge all *large* allocations > (e.g. percpu) to the parent cgroup. Small allocations can be ignored. I showed in [1] other large allocation: " number bytes $1*$2 sum note call_site of alloc allocs ------------------------------------------------------------ 1 14448 14448 14448 = percpu_alloc_percpu: 1 8192 8192 22640 ++ (mem_cgroup_css_alloc+0x54) 49 128 6272 28912 ++ (__kernfs_new_node+0x4e) 49 96 4704 33616 ? (simple_xattr_alloc+0x2c) 49 88 4312 37928 ++ (__kernfs_iattrs+0x56) 1 4096 4096 42024 ++ (cgroup_mkdir+0xc7) 1 3840 3840 45864 = percpu_alloc_percpu: 4 512 2048 47912 + (alloc_fair_sched_group+0x166) 4 512 2048 49960 + (alloc_fair_sched_group+0x139) 1 2048 2048 52008 ++ (mem_cgroup_css_alloc+0x109) " [1] https://lore.kernel.org/all/1aa4cd22-fcb6-0e8d-a1c6-23661d618864@openvz.org/ = already accounted ++ to be accounted first + to be accounted a bit later There is no problems with objects allocated in mem_cgroup_alloc(), they will be accounted to parent's memcg. However I do not understand how to handle other large objects? We could move set_active_memcg(parent) call from mem_cgroup_css_alloc() to cgroup_apply_control_enable() and handle allocation in all .css_alloc() However I need to handle allocations called from cgroup_mkdir() too and badly understand how to do it properly. Thank you, Vasily Averin