Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp978869pxb; Fri, 22 Apr 2022 15:49:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOCoI+mV1Bnm2/ntvbgyN/qF2n4FpOJ/BTkKOGOIIj6OfPK422aQXRV6PjwvT+EVeb5Miq X-Received: by 2002:a17:902:7e0d:b0:156:47a4:a7c4 with SMTP id b13-20020a1709027e0d00b0015647a4a7c4mr6968985plm.141.1650667754464; Fri, 22 Apr 2022 15:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650667754; cv=none; d=google.com; s=arc-20160816; b=w8hilOGxxpDwSXEl1SpeJ1XDntVLI/wY9DBCRLjq8vN+7WY0WNH/8ovftELGhcrjUw S5wYHkxVH69QPTpa4jlEE9hAEmHG/xZSo3Of0DnUUrA3eL9/HOY8F5YsiECCli05yLnJ Vc9wV3CZmdyxGfkTv4laWVSVceQjAHrrvw5Tt3ThPSIAAxJ68IlJnDC0gPvFzmSnL7tI ZnCf3eTNTLanzoHlYMz7E2GcWFRqU6/Chvdqu8f9mJ3tzB+qaPupNTGOro9iYYTn/0n4 iQhvlAM+3+lNnY1fuOX5MroxAvXauJEPv28N/y5AKEGg8t+5NxGhmq9+SjuUOyobouLC zSlw== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=B9p0FoMPwzRixWYKVWEjx56sWOvt3enSLFG849SajN4=; b=CG3CI4nJHis8kLqN5hXC23Ai/yfLDG9qFll1VPuf5SrzebIsZmB2MHqhTOmTYmFo/2 9uSWbpqMbgvHDi61IYfmYWCDOW8VBV0iFGV4qqpKqwcGc421hGn/fVUpWYB5Eh77QeQA NBKo26ZE1O1DC96rbwFm89G2Zpw1+AfE71exiowQvG5VHkV/qcW7JbTZkSdpEEcDXu8c ifWgUJQLRVwBchu3d72L2aMAWqCImslPbCNcc5dqfbQ37cyl31LeyWKj4mLoHWZFB6Vv ifQ8TrcL3dkg5Sk316/th0XirV5EHgMKG0QJex3AjaWsGtyyglOVQfh5DuZ/Svg5RQnb WrTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b="i1xRqM/A"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l11-20020a637c4b000000b003a3a5d9062esi9858029pgn.460.2022.04.22.15.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 15:49:14 -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=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b="i1xRqM/A"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0F2BE3FFE65; Fri, 22 Apr 2022 13:38:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229550AbiDVUTV (ORCPT + 99 others); Fri, 22 Apr 2022 16:19:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbiDVUTM (ORCPT ); Fri, 22 Apr 2022 16:19:12 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C35921132F4 for ; Fri, 22 Apr 2022 13:13:38 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id w1so16137878lfa.4 for ; Fri, 22 Apr 2022 13:13:38 -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 :from:to:cc:references:in-reply-to:content-transfer-encoding; bh=B9p0FoMPwzRixWYKVWEjx56sWOvt3enSLFG849SajN4=; b=i1xRqM/AQD7+zHlviCXpKPZZPH+NCey1cLY0YH9FoGiR73p/X6PTLSYWksAgy2XKmM ksiRnL7gx+oyU+FNTO7SF58wlUemyiGD7RFZqO8+RoT1p8NIqoBwjr6bNOASrAsJ1UPa YEjor8or6jM8yb19a+Jv4wMbSUGBGFj1fsk8zUp+BhH4KT4geUPppJf+2cvULcwK594C Ify1KqH7eFxQGny0PELELVDTWBxzSbVh/a4r+fXHN5VQ7XPgWdPBC0veaqgeUbtBqSrI TFb6ms3NcP0CuGTa6PRcEB1utLkbyV3aUe24o+fgprm8x3rB5dwmvLiOnq5fX0atxqYg xUkg== 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:from:to:cc:references:in-reply-to :content-transfer-encoding; bh=B9p0FoMPwzRixWYKVWEjx56sWOvt3enSLFG849SajN4=; b=PWTwnuQZJhXGu87hZhI3ZnvkqQkEIfXG05oJQry0TvR/OXR4hNf8Lx5vnMYXwe9LPz qR3m4WCXZ7RJSMIyhOc1mjKo7VgyjA7LiVjubhUiTE2jcM3Ck9qQq6MM8ZOt6sloLmAm VAS7F0NluTrVYpt654xNb1/wsoOhB2OEvqUMZIWDCn68iqMYnb9tvDMqm2MSUbiHPL0R zhP9LhzPtCCpKtA0LPsliMyONtD6Y7auTN23eImNHg265S04HEg0TMeVb17WEzzgsMC2 l0PSDY+t3A6yILmV3bUVIZ7bmfVMmjOpjYtqReHL1zohsNLw2YMSYbNwf3Gsd7en4JwD AnWw== X-Gm-Message-State: AOAM532BKTEY8fll3p7LjPwXbsErov6iGtqWmR3GJYCzPEIszSjsmIKU 7ZntKoyfvyl0H/WC6HajD7JXvQ== X-Received: by 2002:a19:6759:0:b0:46b:b99f:a7ac with SMTP id e25-20020a196759000000b0046bb99fa7acmr4160108lfj.312.1650658143962; Fri, 22 Apr 2022 13:09:03 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.177]) by smtp.gmail.com with ESMTPSA id a12-20020a19fc0c000000b00471c63ea0fcsm336510lfi.6.2022.04.22.13.09.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Apr 2022 13:09:03 -0700 (PDT) Message-ID: Date: Fri, 22 Apr 2022 23:09:01 +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 RFC] net: set proper memcg for net_init hooks allocations Content-Language: en-US From: Vasily Averin To: Shakeel Butt Cc: Vlastimil Babka , Roman Gushchin , kernel@openvz.org, LKML , netdev , Cgroups , Michal Hocko , Florian Westphal , "David S. Miller" , Jakub Kicinski , Paolo Abeni 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: <964ae72a-0484-67de-8143-a9a2d492a520@openvz.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE 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 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? Thank you, Vasily Averin