Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4975760ioa; Wed, 27 Apr 2022 15:52:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoaXPCUc41Ymy2umPkBkS4sBs9PDvSYj+GlxtA4qWQGZlgFrFXQMe/56lWQVqxFA+DHlyr X-Received: by 2002:a17:90b:388a:b0:1d2:a380:e622 with SMTP id mu10-20020a17090b388a00b001d2a380e622mr35354131pjb.22.1651099934451; Wed, 27 Apr 2022 15:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651099934; cv=none; d=google.com; s=arc-20160816; b=Wbhm3xnUGnwpcN596fQSsRanhSoy4D3fyyjLyvY75Cje56Fo1dZamFllURwMHQ7xZS cqbexP43ReCCgv+wE3+uMfXYNYG8vUS9okTGjhlqhS4nifq50Adx97jNdLe093O3yqSG WAvJdV8+gDvXpSHMq/g9rg74rPQLMNDa0oO8xyVYp6f5I/fzBhcwMTY7PfGfIZmKqLsD FFOtuenLD09poN4heH8D1oYf+d7WejgGNgvypCGBStH28pmqiXoKAIq1eFt/5dXnMIOE juLCLOAJ7bF2FtFizx1IxRaH/U3pLdy7SWydMCXpCsUARdiWS2+xTSIUQICI9yq87uX0 N2ZQ== 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=oLug1+azcE2h7QMeDbpYAnTwrafPSTpRFVPk0zNJveg=; b=egkcVfuzyRu83TV5NBxEOkesTJXfb3PNdvvOGL8C0XOR1xSbzCYM9wV7knAIXSQwHl dxHzE54PwKHg/9XkofVHDR3IVnMOPlc5jl5fjq4chiLnsil7730k3dHPZQ/q0F9ny+KG MxeSkk/DbSUbbYu7p4ERUfT/e0D5Uja2yJVfg8JhOrTvwoiqxS70qtIvG6ch5Co1ZGdB 6nIvdHmEhBoLolZTA9JRpSKiOtaH4vBopWdk931UfJEIY/HcT9tqf43uqmBZyZ4Q2dWZ pePYdgfsTa40VN4yNVHxPN4oV8UKI9v0DWxpjeXccJi8SqCmgkRiFvSOfRN7OHvIU1VL phPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b="zI/nSf1n"; 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 m6-20020a6562c6000000b003ab7c9b8288si2520663pgv.228.2022.04.27.15.51.56; Wed, 27 Apr 2022 15:52:14 -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="zI/nSf1n"; 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 S231598AbiD0WZS (ORCPT + 99 others); Wed, 27 Apr 2022 18:25:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232043AbiD0WZO (ORCPT ); Wed, 27 Apr 2022 18:25:14 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39ED62AE19 for ; Wed, 27 Apr 2022 15:22:00 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id y3so5996469ejo.12 for ; Wed, 27 Apr 2022 15:22:00 -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=oLug1+azcE2h7QMeDbpYAnTwrafPSTpRFVPk0zNJveg=; b=zI/nSf1n1K3Do1i5nBCb7lwViY+DJKmUvfVcoGHl/Q5SvQj83PNn1mVYoRuClPrpw9 sCkAImuE2tFKtQFVPcYA9jGml9m/Bwy/ymA5Te4m1zi4dRCXKacQNmNJgYeS0VEfkWbh FvpiNqvdCThOvFYOiROhJZSsBkCxP0ox1W6C1im3DrClwe4LGTwoTkmKjqIyNiDE7bF0 IWrLpdiZfx31n46ZBikenK9K101cENCfFgSuYqLOkJ+QkFHBJEC++7GoEDz9r43mo8AA LxJWR0R9yV0SBiYBa/bFhSnWkwE1pEHgs0W4l9FVYG8LeYNpO4bMEe33NvulIrzx7+7e S/ew== 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=oLug1+azcE2h7QMeDbpYAnTwrafPSTpRFVPk0zNJveg=; b=1vlm2r18JoAyCNA3TYQ6LDP+OhL7r8xjpTX8B5V0Hs9TvBpBr2CH4t2yNwXSCOvxsp oJHUgSA9Cm9aDrLsNi0vUsDQV/HmPTod8C5xxwpn2YgXUAKp3XTFcU8uo9qHSbpp0kmk txH5xH7lOZnkBrjr0xVoaV+yWy1sGdpEKrD1vHnFz+gjNsVxZ2C6y5L8g5BybILTtfow l4EoA1JO6Pxm7rkliVkG4nkqMJTfunCkTYVoMewmyS8/0hmp0HJYtwlN2BwqSAjbUlVX JuflzcbQff9i/Jp1XASKs+59TQ5CiP8N8YGmbUktKjiLrVlPkRcAyzJ1cWtSfHkPWbYj 8JHA== X-Gm-Message-State: AOAM533Xr7cDgvr4gx6FtXfkLF9OCMJ3NxpYB7q0Xh36f5Jcnb/4C4BQ RIqSlnBiG5bqY471fsH3c0ykQLizCngtfRrD X-Received: by 2002:a2e:a593:0:b0:24d:b9a6:b85c with SMTP id m19-20020a2ea593000000b0024db9a6b85cmr5137954ljp.309.1651097815894; Wed, 27 Apr 2022 15:16:55 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.177]) by smtp.gmail.com with ESMTPSA id a5-20020a2e9805000000b0024f12f0eb37sm999061ljj.95.2022.04.27.15.16.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Apr 2022 15:16:55 -0700 (PDT) Message-ID: <6b18f82d-1950-b38e-f3f5-94f6c23f0edb@openvz.org> Date: Thu, 28 Apr 2022 01:16:53 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH memcg v4] net: set proper memcg for net_init hooks allocations Content-Language: en-US To: Shakeel Butt , =?UTF-8?Q?Michal_Koutn=c3=bd?= Cc: Vlastimil Babka , Roman Gushchin , kernel@openvz.org, Florian Westphal , LKML , Michal Hocko , Cgroups , netdev , "David S. Miller" , Jakub Kicinski , Paolo Abeni References: <33085523-a8b9-1bf6-2726-f456f59015ef@openvz.org> <20220427122232.GA9823@blackbody.suse.cz> From: Vasily Averin In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 4/27/22 18:06, Shakeel Butt wrote: > On Wed, Apr 27, 2022 at 5:22 AM Michal Koutný wrote: >> >> On Tue, Apr 26, 2022 at 10:23:32PM -0700, Shakeel Butt wrote: >>> [...] >>>> >>>> +static inline struct mem_cgroup *get_mem_cgroup_from_obj(void *p) >>>> +{ >>>> + struct mem_cgroup *memcg; >>>> + >>> >>> Do we need memcg_kmem_enabled() check here or maybe >>> mem_cgroup_from_obj() should be doing memcg_kmem_enabled() instead of >>> mem_cgroup_disabled() as we can have "cgroup.memory=nokmem" boot >>> param. Shakeel, unfortunately I'm not ready to answer this question right now. I even did not noticed that memcg_kmem_enabled() and mem_cgroup_disabled() have a different nature. If you have no objections I'm going to keep this place as is and investigate this question later. >> I reckon such a guard is on the charge side and readers should treat >> NULL and root_mem_group equally. Or is there a case when these two are >> different? >> >> (I can see it's different semantics when stored in current->active_memcg >> (and active_memcg() getter) but for such "outer" callers like here it >> seems equal.) Dear Michal, I may have misunderstood your point of view, so let me explain my vision in more detail. I do not think that NULL and root_mem_cgroup are equal here: - we have enabled cgroups and well-defined root_mem_cgroup, - this function is called from inside memcg-limited container, - we tried to get memcg from net, but without success, and as result got NULL from mem_cgroup_from_obj() (frankly speaking I do not think this situation is really possible) If we keep memcg = NULL, then current's memcg will not be masked and net_init's allocations will be accounted to current's memcg. So we need to set active_memcg to root_mem_cgroup, it helps to avoid incorrect accounting. > I was more thinking about possible shortcut optimization and unrelated > to this patch. > > Vasily, can you please add documentation for get_mem_cgroup_from_obj() > similar to get_mem_cgroup_from_mm()? Also for mem_cgroup_or_root(). > Please note that root_mem_cgroup can be NULL during early boot. Ok, thank you for the remark, I'll improve it in next patch version. Thank you, Vasily Averin