From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8F20C07E9D for ; Sat, 24 Sep 2022 03:20:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D904780039; Fri, 23 Sep 2022 23:20:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3FA580016; Fri, 23 Sep 2022 23:20:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C078780039; Fri, 23 Sep 2022 23:20:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AE74A80016 for ; Fri, 23 Sep 2022 23:20:21 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 85D6A1C638F for ; Sat, 24 Sep 2022 03:20:21 +0000 (UTC) X-FDA: 79945525842.02.89FB95A Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf13.hostedemail.com (Postfix) with ESMTP id 1E0F520011 for ; Sat, 24 Sep 2022 03:20:20 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id i15-20020a17090a4b8f00b0020073b4ac27so1865874pjh.3 for ; Fri, 23 Sep 2022 20:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date; bh=zdaZUg3/Ml2ij6XPZD2qg9IOy8atuUvae1lDmHhGEaU=; b=UnG1HqbKS/mgMg2dkwoqyo9cxa/2p7p+q8MDbzDOgljy0JmBKN0AWL+/mahBJ/oE4b /9QD89ZRZ9yccoJzfPy1SQYt46FZAHzGDAXYLKiMDDVay1UH7uAAzk0Pnp4PMrM/DYFA qct+9CeD/c4KcYv4qvhJlG7CUUdSyifL0o4iXE3JixbsRu10MtIcZU1pnh/dg3IaJDGW l/o4f/rGLnfGtadyK68xaOvEpWZxNrSqawqgdBi7N/MUUR7Q7HiQSxZMg6C29UfLCrcf Cc6YLDBbmkNwdTZc1eALtudTSBzGRjfP7tPAUl52zchsEqh82XFo68pJm7Ob1HOBZZ7b +ttA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date; bh=zdaZUg3/Ml2ij6XPZD2qg9IOy8atuUvae1lDmHhGEaU=; b=1LbUQnF07VnuzTrb9FZcuwEv1SOvVCUHVt/NHH8BXELApTYxLUJcv6pCUXQzI99xqc 7sDISyj9mD6UzQGH+D/xTF4Z3cIaES1AghvIQi0jp6u/PW4RZs83jUM+W9q3O84tQOJ6 WrWzniQoti6wYru3twjyTrz8Y6A+eVHrhuUMbh6Wi1ascqzO1vFE+WSioSr+iJYWKatA /mWLWRzfwjOJant++L5k6G35ygM14l2QqoXYDNWGi9xevD0nXAHFcWHwieS4Ai5LIa+k wQoSp1iBi0BlNMYWw/QNfqbnXNH2dt4xpqIgTM5g0RjuDTs+m93dFpjm8uLiMTEXntAO iUaQ== X-Gm-Message-State: ACrzQf1zZco6balALh7O1rkbU6DlXmtcX7Xfy4mjY4CwWIE2N28pC66M HSQ/On7+K5x1nrKkkhmBtR0= X-Google-Smtp-Source: AMsMyM5q0D4IBPE+GYfOG2nQqyklGERs9XUlFfWm9EZr1G063EsXvtnS95wpHmmMGpSeA2bakubf+g== X-Received: by 2002:a17:903:22c2:b0:178:3c7c:18af with SMTP id y2-20020a17090322c200b001783c7c18afmr11513864plg.134.1663989619818; Fri, 23 Sep 2022 20:20:19 -0700 (PDT) Received: from localhost (2603-800c-1a02-1bae-a7fa-157f-969a-4cde.res6.spectrum.com. [2603:800c:1a02:1bae:a7fa:157f:969a:4cde]) by smtp.gmail.com with ESMTPSA id y10-20020a17090a2b4a00b001fab208523esm2302079pjc.3.2022.09.23.20.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 20:20:19 -0700 (PDT) Date: Fri, 23 Sep 2022 17:20:18 -1000 From: Tejun Heo To: Yafang Shao Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, songmuchun@bytedance.com, akpm@linux-foundation.org, lizefan.x@bytedance.com, cgroups@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH bpf-next 10/10] bpf, memcg: Add new item bpf into memory.stat Message-ID: References: <20220921170002.29557-1-laoar.shao@gmail.com> <20220921170002.29557-11-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220921170002.29557-11-laoar.shao@gmail.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663989621; a=rsa-sha256; cv=none; b=ewbV6dgm6a7aI4mdlniFuX8vJT+04IdC2ekE633nh5z4mD3Ke1+wkYcslMBiz+GM6597Pf U2iTOIQPdi+WPTzmQs1+aWZI0osIo51ORMpo5FCYUxAwlnB5fmfiMzvxbFN4eLqyC0ImnL PHRoszY9BgI84eRKTgqJLLtgxtRhkDk= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=UnG1HqbK; spf=pass (imf13.hostedemail.com: domain of htejun@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=htejun@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663989621; h=from:from:sender:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zdaZUg3/Ml2ij6XPZD2qg9IOy8atuUvae1lDmHhGEaU=; b=4My5wVQOiuxU2XdZAOCHStTrJdhKT2q59fSDoPK6mP8I0RxSN3EcxG/xmd/bIMve6aQvp3 jpZgSXU+7ksS5AdpdUWf0LzH/Uqo00QY0POitnh9bN8oPce2G37ngmWlInbzaqkOasJ8NJ EMGuRMvGseMHpBT/ch4W9dW1N15pKyw= X-Rspamd-Queue-Id: 1E0F520011 X-Rspamd-Server: rspam07 X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=UnG1HqbK; spf=pass (imf13.hostedemail.com: domain of htejun@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=htejun@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) X-Stat-Signature: fwk356iij885h4ep6uj6oqofbha9s4zp X-HE-Tag: 1663989620-69399 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hello, On Wed, Sep 21, 2022 at 05:00:02PM +0000, Yafang Shao wrote: > A new item 'bpf' is introduced into memory.stat, then we can get the memory > consumed by bpf. Currently only the memory of bpf-map is accounted. > The accouting of this new item is implemented with scope-based accouting, > which is similar to set_active_memcg(). In this scope, the memory allocated > will be accounted or unaccounted to a specific item, which is specified by > set_active_memcg_item(). Imma let memcg folks comment on the implementation. Hmm... I wonder how this would tie in with the BPF memory allocator Alexei is working on. > The result in cgroup v1 as follows, > $ cat /sys/fs/cgroup/memory/foo/memory.stat | grep bpf > bpf 109056000 > total_bpf 109056000 > After the map is removed, the counter will become zero again. > $ cat /sys/fs/cgroup/memory/foo/memory.stat | grep bpf > bpf 0 > total_bpf 0 > > The 'bpf' may not be 0 after the bpf-map is destroyed, because there may be > cached objects. What's the difference between bpf and total_bpf? Where's total_bpf implemented? It doesn't seem to be anywhere. Please also update Documentation/admin-guide/cgroup-v2.rst. > Note that there's no kmemcg in root memory cgroup, so the item 'bpf' will > be always 0 in root memory cgroup. If a bpf-map is charged into root memcg > directly, its memory size will not be accounted, so the 'total_bpf' can't > be used to monitor system-wide bpf memory consumption yet. So, system-level accounting is usually handled separately as it's most likely that we'd want the same stat at the system level even when cgroup is not implemented. Here, too, it'd make sense to first implement system level bpf memory usage accounting, expose that through /proc/meminfo and then use the same source for root level cgroup stat. Thanks. -- tejun