Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3342503ioa; Tue, 26 Apr 2022 01:35:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbVj3dJuc2J6FrdVgs0XvU5I7+um4WDd0Jbjm268GORY9lch8KXxU16aN+5XiOI3IvoFER X-Received: by 2002:a17:907:7f0a:b0:6f3:9712:dfed with SMTP id qf10-20020a1709077f0a00b006f39712dfedmr8269083ejc.557.1650962141464; Tue, 26 Apr 2022 01:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650962141; cv=none; d=google.com; s=arc-20160816; b=o6oD6WL8NQzc0ivpyd4l1q9kLhcDzLDs8bEQIn82oniE6s9RyFJtCDzfQ1B7rtNqpw 8rXSDXw8Db5jidi/QRz+cc33yb08eXXH0iM7C/BcDv7ydNqV8vAhdWiZ4iE/Ar8wyuDp cJauL4wi7pzi6wHt5qKI/wh8qBCMCMWCLybfk4/M9SA6hCDO5OhdFImJFY3erK98HBy5 cDwOuDd/3b8iF/QDFbAqVmuUAv6EKKfxAtWYaVfCvvE1v6lY5YYnJ1+0SOU/5MFqG7b0 77zHoAs2QN50K5NdPdACa0nHvH/VNMUd7YHOEKExfIo20ybF0qwzPz3EwMHjndPMwpIG UKkw== 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=ZBYAGN8Bb7OvFzAe7F9Y2LfgGtxk1nTfvTdOaaOXGBo=; b=lPmSmgrQE1k3ENrbLLVae7XNFJm0zgj0Nu77Fsj7B17n/IST2UFxBURLT5liTopQOE i0PZhDXGyFU9ljXI0eTcaiWd9V+Yw6aBgouiJ4NdAwIuecSnbR/vK9NEaTGyVUnsXivh y/mmNKQfol25SFENnoqN0cYxUClIP5o5LD382QXqLi+gGVi5gJG8wRGLf96NSqrkdCSm R2J6Lo2xa1kmghT960Z9NX2s07sz8BhcfVq7PVmEN9WIWvyS+Kgpr3/wCgyBNea88dhD iMC0kw2DSmPdDsrU9UAwrED8R3V+8XWev0ZD8Ny7WwvhoLZT9KmAAMPmGRl9JYy8jFfe wDaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=Jq6JdD8V; 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 p18-20020a170906605200b006e7fe2af1d6si15236947ejj.161.2022.04.26.01.35.16; Tue, 26 Apr 2022 01:35:41 -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=Jq6JdD8V; 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 S237816AbiDZGBT (ORCPT + 99 others); Tue, 26 Apr 2022 02:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237337AbiDZGBR (ORCPT ); Tue, 26 Apr 2022 02:01:17 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1B9637A89 for ; Mon, 25 Apr 2022 22:58:10 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id q14so20534709ljc.12 for ; Mon, 25 Apr 2022 22:58:10 -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=ZBYAGN8Bb7OvFzAe7F9Y2LfgGtxk1nTfvTdOaaOXGBo=; b=Jq6JdD8VzFEq18+o276NScliYwVuNJf4Rn3tazrd5OBUECXdtwysjbVzisP42H7Zfg AzLF13iBPuGB4G8laKbcZXc+vG2Nd6M+Fk6lwgFd3A2z8Y97UPbC0O5FCrHPpHCQfkNj LsXD2YsfDHX3vGdtEbPWrIaeng7NCC/JLJLjHxphWsPsxrCBycx7sWesbCjiyTLJkQcU FFpPWUdRKmtffIo1OD6Dfll3JGIziSw1stDsXiz0KhtuGy3kd9vpS4CwqwZguWcs3uEG CaYqiqwcLSyiA8L314rfaauhH780shmI3tTGilQpxB+MADc1Eq9p/n3OpAQrudz4xvnl +1Kg== 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=ZBYAGN8Bb7OvFzAe7F9Y2LfgGtxk1nTfvTdOaaOXGBo=; b=xNhdX4opOtIrnXanCuyaO74/m5hnacFWafG5XEvmLlZKQ0fv/WDZzSbppYkczOcf1b o2YjjCcYtjlazpbqsMVA3GFUG9TI9JjM47GNiMoL6bEpphqeA5VzOhstU7zxJwIqKLGT BbQhRlTmJoHDRutxe/5DFKYeHvb9xU4EKgTAMzllGq86iU4MJmv92wTnrgqmsJGSYOFO KEP+nd43eGs3ey2ThcuH5BwMsoE5fRQ2+rKnf7Jji+ZihxQtrP1h+bQYOevSQ/55WaCt 7kX/UJIlxUKxKPseWO1EXUS88VYQ9VeFmDFsc7Wn6SSedhRpqfOjZd8pbt/NE4hyb/lI 457Q== X-Gm-Message-State: AOAM533bMNN+vvv1kq9YTbyzjELPyDOxFnric/wDhR/DLCOVbDm886tg pH+CxeLFuzIBoO1fr6MLVDoR5Q== X-Received: by 2002:a2e:8247:0:b0:249:8615:4242 with SMTP id j7-20020a2e8247000000b0024986154242mr13137747ljh.108.1650952689026; Mon, 25 Apr 2022 22:58:09 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.177]) by smtp.gmail.com with ESMTPSA id t23-20020a199117000000b0047204c620b6sm745653lfd.248.2022.04.25.22.58.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Apr 2022 22:58:08 -0700 (PDT) Message-ID: Date: Tue, 26 Apr 2022 08:58:07 +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 v3] net: set proper memcg for net_init hooks allocations Content-Language: en-US To: Roman Gushchin Cc: Vlastimil Babka , Shakeel Butt , kernel@openvz.org, Florian Westphal , linux-kernel@vger.kernel.org, Michal Hocko , cgroups@vger.kernel.org, netdev@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Paolo Abeni References: <20220424144627.GB13403@xsang-OptiPlex-9020> From: Vasily Averin In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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=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/26/22 05:50, Roman Gushchin wrote: > On Mon, Apr 25, 2022 at 01:56:02PM +0300, Vasily Averin wrote: >> + >> +static inline struct mem_cgroup *get_net_memcg(void *p) >> +{ >> + struct mem_cgroup *memcg; >> + >> + memcg = get_mem_cgroup_from_kmem(p); >> + >> + if (!memcg) >> + memcg = root_mem_cgroup; >> + >> + return memcg; >> +} > > I'm not a fan of this helper: it has nothing to do with the networking, > actually it's a wrapper of get_mem_cgroup_from_kmem() replacing NULL > with root_mem_cgroup. > > Overall the handling of root_mem_cgroup is very messy, I don't blame > this patch. But I wonder if it's better to simple move this code > to the call site without introducing a new function? Unfortunately root_mem_cgroup is defined under CONFIG_MEMCG, so we cannot use it outside without ifdefs. > Alternatively, you can introduce something like: > struct mem_cgroup *mem_cgroup_or_root(struct mem_cgroup *memcg) > { > return memcg ? memcg : root_mem_cgroup; > } Thank you for the hint, this looks much better. Vasily Averin