Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp11486iob; Wed, 27 Apr 2022 17:30:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDUbjRRpB2+8Z4KcA6xzEpj2C5OZQAvaSaCW5LJbtd/Hh3Ooj5Wi6LOjMTKVnk/4QGCkXI X-Received: by 2002:a05:6402:1941:b0:413:2555:53e3 with SMTP id f1-20020a056402194100b00413255553e3mr33062973edz.164.1651105832255; Wed, 27 Apr 2022 17:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651105832; cv=none; d=google.com; s=arc-20160816; b=Z3n6QEg9i+6RQ7wzZw0OKE8+oKuKCKr0+9OojL7V7yfEKxvK29XrpYuQG/p+SKOfPT qnKkSZzz6sN+/C+SvoHNfVdH/EZ5Ab/flMpTzg4SkezrNPMEHf3TrKTi+uiffE/B533H XEekG878JnfMFlPEm+gBko5KwtbikKpEUQnSCS4gOWAU8s8oCZCV4DRymzRUHr4bJGwA C8udGWgrS4VqZz+vg0mfxUkohzFuzYWsPLhbPzAlE+nBfJ+cxw2vnlp787TMI+NdqVmt APSqLFIPhRWB7TKjI44ROO/a3Pee/nCukR6RN7WM2XQ9YfJ0ayW/k8wBU4mGwieqMMic fFvw== 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=YptwFdA8KWuDmjvuchBNuhhYcNiTn83Pm656usmn0sI=; b=SJRlGQp1nQaC39HZMoNWXNwu13C+dEa8TTdC3aTBoXhkPXmvg+aMulc8hKF7iyFSen apIrfwxay0Czw+Rgi2k6w1sHg8Jmbtd0mAK791Aoab/tJfxBbCRuWIoOv9ZUWHToj+uQ wQwUanOLaQd2BxliH83xABG8PFqR7aoZFsPNzhQhLHlnoR4ealn2zYWO1UBjhcFIrb6X LuIsqwme+J9ywa6oRmL5nz/f16VJDXtaaw3G1EDoROg2x4TnD6MjKomJM772T9r5/lXN 3GlZWZtjXNcmebpgNJEXrwTtl4tz74ubzb4008K+ifKI8U2PjQRE1rO2pVhw8+/McoNt vgSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xurUMpP3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m7-20020a056402430700b0041d824862d1si3574340edc.39.2022.04.27.17.28.55; Wed, 27 Apr 2022 17:30:32 -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=@linux.dev header.s=key1 header.b=xurUMpP3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbiD0Wjb (ORCPT + 99 others); Wed, 27 Apr 2022 18:39:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232266AbiD0Wj2 (ORCPT ); Wed, 27 Apr 2022 18:39:28 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 660CD6383; Wed, 27 Apr 2022 15:36:12 -0700 (PDT) Date: Wed, 27 Apr 2022 15:36:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1651098970; 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=YptwFdA8KWuDmjvuchBNuhhYcNiTn83Pm656usmn0sI=; b=xurUMpP3QLqUoZxw1BdoFkYM+0wVMIHfRfnM/Miz+pyrSnam+pUfOqzeu4w7WEtz+vscdO t8sZhvk29FJHTf9oMznLUlDzxrKSBESrMWIxTbOsTmuGq6MX7UWPvgVN2r6Q4pckJigj3y prcDwZAQTSSNCJlRUCceBDukatZZNz4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Vasily Averin Cc: Shakeel Butt , Michal =?iso-8859-1?Q?Koutn=FD?= , Vlastimil Babka , kernel@openvz.org, Florian Westphal , LKML , Michal Hocko , Cgroups , netdev , "David S. Miller" , Jakub Kicinski , Paolo Abeni Subject: Re: [PATCH memcg v4] net: set proper memcg for net_init hooks allocations Message-ID: References: <33085523-a8b9-1bf6-2726-f456f59015ef@openvz.org> <20220427122232.GA9823@blackbody.suse.cz> <6b18f82d-1950-b38e-f3f5-94f6c23f0edb@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6b18f82d-1950-b38e-f3f5-94f6c23f0edb@openvz.org> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Thu, Apr 28, 2022 at 01:16:53AM +0300, Vasily Averin wrote: > 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. It's way out of scope of this patch, but I think we need to stop using NULL as root_mem_cgroup/system scope indicator. Remaining use cases will be like end of cgroup iteration, active memcg not set, parent of the root memcg, etc. We can point root_mem_cgroup at a statically allocated structure on both CONFIG_MEMCG and !CONFIG_MEMCG. Does it sound reasonable or I'm missing some important points? Thanks!