Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp989090pxb; Fri, 22 Apr 2022 16:05:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8xmUF3oEDtGZimaRhdEijZm1Nx1iydfMYh+KAn9RWXncntMAotHm1x4pF6/ocak088qfN X-Received: by 2002:a05:6870:2314:b0:e2:a480:eb4d with SMTP id w20-20020a056870231400b000e2a480eb4dmr2905827oao.133.1650668754854; Fri, 22 Apr 2022 16:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650668754; cv=none; d=google.com; s=arc-20160816; b=s2U+gSw+uKF+4gavCXqNF92Mbped+5Zofyk8yHSkt2r6crQzvOX3Uok0MmrRiDBN+h AiBqYxluKRGFZV4+K7ljnhfwp7D0MlL2DPeRlT3L3a0hciPKPT6Sq4N4HQ/3pvNplBAO ZomVCp7H7bb/AP7G9G0QK/CxAbvSlIZXoATQAN8+UIUxKV+ALdzg6Bm/4B984wDSujUL T9uJtr3Un+MKsqfJkaT9Qea9aW0dDKZ5ZluoSqYssyQ6JN7VWA1qOSJM9jXdrlYd5doC Zxb9JV8kMrnaw275OvzXddytR+YgFS4LvP9jhlDKkav5hYaZI853U9YmOKTuOgijmmm9 7keA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2FeuhW6y4os5v9CoDi1x5cL69WTrNP7orQRjD5u2f2Q=; b=fzqIR+IjePvjhjpsRXg75p89Yz04bNhnVp/q0NCso34cRwzHK7ze7sKZ2xXt28eAMi 9LJeC2HL4VZhs9WXjv3ZxY12BGUkNSlT5CaBJoY3PgXOcUxdLkY+I+YKwE+1vFPXwYst HU1nrW2EZDwrXQqQ4xlDzBqyLm4K5IiKyY0c7etmpXufb1U0PB0KQdlF2fZWajjNG3hH 2eYNPzWc9s1kutteM8flyvsnkJ8Sye68Y8THOf/s5PwrgRTkHarJfgXsiHdANTl/dLXk Q8QLAqJlrGo0tkpsgjAAl2ZXU4Vkum+U9wD+vvOVPnWfo+jQzbbQYlJNtg3oiK90DAhz JOdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SWA5JCif; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f3-20020a056870898300b000e2db731693si3703354oaq.66.2022.04.22.16.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 16:05:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SWA5JCif; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DD5265B3C1; Fri, 22 Apr 2022 14:35:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbiDVVhu (ORCPT + 99 others); Fri, 22 Apr 2022 17:37:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbiDVVhk (ORCPT ); Fri, 22 Apr 2022 17:37:40 -0400 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FDF6400EDA for ; Fri, 22 Apr 2022 13:38:40 -0700 (PDT) Received: by mail-oi1-f169.google.com with SMTP id r85so10313081oie.7 for ; Fri, 22 Apr 2022 13:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2FeuhW6y4os5v9CoDi1x5cL69WTrNP7orQRjD5u2f2Q=; b=SWA5JCifyGGgXC8kg9oqcVEfzGpcJyubvgXISY/tkiQ4LkAnBvdJQ4x+SDJdCcN5r5 l/D5Xwmleml/wGOTyuQey0sip6/0Tgoq+rQ7CHZro/fqIgNVa0LsvarIkgGhhvY5j1sF LMm1oOI3X0eDdolQ9LpFcFBcvkgDAo4IEFQp7an7GZ4F5A6E9vw8lZlu+PJZ8/F/XeaE 2XrN/+haQevXPxaL9uHcm3fCWmwsIiDq4XpsMffkJ/1dAHzee/+nBWc5FxrRuv2Yv75v ot9Gi+ioqe4rUavjZ2Ml02hMsz+UFQFITKvVGI/dulXXz+ZeW0uqaldMetwuQxNGpPe6 t/zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2FeuhW6y4os5v9CoDi1x5cL69WTrNP7orQRjD5u2f2Q=; b=4MlbXWArR+Cz5opcS7HSSeCoGSQj45gUh9z4EzJW5/GXYFRuDmhtJfbZ402RTEc05t i0b6351yxsOWMwyxD5wkySPv9CfaRgMXOOoctl7RUdLnQmUgYw/xhT3jDpJKSsrghD/H 5w+UBBT8UyvuCMFUelxWKA4W92W8yH1nFYsGR/Rxu4g5TeUA679jqJGNEjARqOd5iycp 5uHBn7KcQU+XBQ8GvZc8qdE1sYMRcVXd2gDIk+2Ws42GXzF4ZNGYH4LuUWSyUBr80gyu lzV2Ovm+ORFWNdw6VozdZrX+TXy9uBH+rl+CzpZBYv//BsdzlZaAwheHwzGLiO1ekxJ5 RyyQ== X-Gm-Message-State: AOAM531LqcwCdunnjzn1vPzpPhBhFfIFupUIL0mBd0l8F8glU6+Ih2x0 2kONGQVbLKO9hZMCVS4y/ZTsRWRApapG5NaDL7cgve41SRg= X-Received: by 2002:a17:90b:1d84:b0:1d0:6472:e0a3 with SMTP id pf4-20020a17090b1d8400b001d06472e0a3mr18058060pjb.207.1650658963307; Fri, 22 Apr 2022 13:22:43 -0700 (PDT) MIME-Version: 1.0 References: <46c1c59e-1368-620d-e57a-f35c2c82084d@linux.dev> <55605876-d05a-8be3-a6ae-ec26de9ee178@openvz.org> <964ae72a-0484-67de-8143-a9a2d492a520@openvz.org> In-Reply-To: From: Shakeel Butt Date: Fri, 22 Apr 2022 13:22:32 -0700 Message-ID: Subject: Re: [PATCH memcg RFC] net: set proper memcg for net_init hooks allocations To: Vasily Averin Cc: Vlastimil Babka , Roman Gushchin , kernel@openvz.org, LKML , netdev , Cgroups , Michal Hocko , Florian Westphal , "David S. Miller" , Jakub Kicinski , Paolo Abeni Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL 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, Apr 22, 2022 at 1:09 PM Vasily Averin wrote: > > On 4/22/22 23:01, Vasily Averin wrote: > > On 4/21/22 18:56, Shakeel Butt wrote: > >> On Sat, Apr 16, 2022 at 11:39 PM Vasily Averin wrote: > >>> @@ -1147,7 +1148,13 @@ static int __register_pernet_operations(struct list_head *list, > >>> * setup_net() and cleanup_net() are not possible. > >>> */ > >>> for_each_net(net) { > >>> + struct mem_cgroup *old, *memcg = NULL; > >>> +#ifdef CONFIG_MEMCG > >>> + memcg = (net == &init_net) ? root_mem_cgroup : mem_cgroup_from_obj(net); > >> > >> memcg from obj is unstable, so you need a reference on memcg. You can > >> introduce get_mem_cgroup_from_kmem() which works for both > >> MEMCG_DATA_OBJCGS and MEMCG_DATA_KMEM. For uncharged objects (like > >> init_net) it should return NULL. > > > > Could you please elaborate with more details? > > It seems to me mem_cgroup_from_obj() does everything exactly as you say: > > - for slab objects it returns memcg taken from according slab->memcg_data > > - for ex-slab objects (i.e. page->memcg_data & MEMCG_DATA_OBJCGS) > > page_memcg_check() returns NULL > > - for kmem objects (i.e. page->memcg_data & MEMCG_DATA_KMEM) > > page_memcg_check() returns objcg->memcg > > - in another cases > > page_memcg_check() returns page->memcg_data, > > so for uncharged objects like init_net NULL should be returned. > > > > I can introduce exported get_mem_cgroup_from_kmem(), however it should only > > call mem_cgroup_from_obj(), perhaps under read_rcu_lock/unlock. > > I think I finally got your point: > Do you mean I should use css_tryget(&memcg->css) for found memcg, > like get_mem_cgroup_from_mm() does? Yes.