Message ID | 1675312377-4782-1-git-send-email-zhaoyang.huang@unisoc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp37283wrn; Wed, 1 Feb 2023 20:44:48 -0800 (PST) X-Google-Smtp-Source: AK7set+mz8URcpfMR9t+nWKJ+dlVyPquOj9n8F4C4VMi5MVxyB81NPhFOuUmMHGdx306uISR/DnB X-Received: by 2002:a05:6a20:3d90:b0:be:a7f8:78a6 with SMTP id s16-20020a056a203d9000b000bea7f878a6mr6602019pzi.42.1675313088249; Wed, 01 Feb 2023 20:44:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675313088; cv=none; d=google.com; s=arc-20160816; b=NsDWN+4z1UvyECH8lU5DPEvMunSHYpCicVf8vHF+PJiIobF9MbQ6gEAWvfekV3cblc TOl/5fqqHOPoCgn0wqbqlcwOAxQq9aQ+Pm8qw4fbh9WkV8VJTBFDOrQBWXbvEW9nop2C ARpZDt0PvA1wA1M+FXxCWNdoAco4qkTWEjjH48qjhzMRh8UpsGNl0SIbwltEDf7JfO37 OMRmWr64kjc7iJUJogEJl7SXXuMoO/FeCmdfYFR/QQv9n6TyC2UG5PtS777mj7B4Q0Sz r53rebCmhkX/N+UGnVfkkOWI/h1Rtx25MX15By/WE/NDWgfecLYWLFc4h8MIHPU5wqCX 1PJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:to:from; bh=9zftTJyo+H9K1r6E5yAXCXs7UTciLw39EYmR8nDDyRo=; b=RTwyPBam54b+fWlnmcyFIcKcplyfgGncmxgjS9aFCsx4Sv/pjWsynovMQera3QNavy 0fQm73OnrCYnfVljZqyNOtCP5vo0oEIy8LcAkQ+5DugFLbVK8MShDU6vJRh5iB1RVZz3 gJSRKGrRz7apLh+Da/p0ifvf2sNud62IIkwos9MDADyQmMMm3nrvq9kcq/Kp0I9ueanH ayDm7K/LDrL5TARowPdmhDVsPmMZP69mPMuy4U9tZf+wf4HSww9uycXzD3zRtkFRVyF7 XplexnVCK+8+NS1omZ+zW0wSsauRLEJpgXxhuuDlOXtwii0t1VddyOxT59+9swadab2w 3Tcg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 13-20020a170902c14d00b00194c90ca330si21251385plj.335.2023.02.01.20.44.36; Wed, 01 Feb 2023 20:44:48 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbjBBEdZ (ORCPT <rfc822;il.mystafa@gmail.com> + 99 others); Wed, 1 Feb 2023 23:33:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229955AbjBBEdX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 1 Feb 2023 23:33:23 -0500 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16338577D9 for <linux-kernel@vger.kernel.org>; Wed, 1 Feb 2023 20:33:19 -0800 (PST) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTP id 3124XE5W017671; Thu, 2 Feb 2023 12:33:14 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.74.65) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 2 Feb 2023 12:33:10 +0800 From: "zhaoyang.huang" <zhaoyang.huang@unisoc.com> To: Andrew Morton <akpm@linux-foundation.org>, Johannes Weiner <hannes@cmpxchg.org>, Peter Zijlstra <peterz@infradead.org>, Michal Hocko <mhocko@kernel.org>, Roman Gushchin <roman.gushchin@linux.dev>, Shakeel Butt <shakeelb@google.com>, <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>, <cgroups@vger.kernel.org>, Zhaoyang Huang <huangzhaoyang@gmail.com>, <ke.wang@unisoc.com> Subject: [PATCH] mm: introduce entrance for root_mem_cgroup's current Date: Thu, 2 Feb 2023 12:32:57 +0800 Message-ID: <1675312377-4782-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.74.65] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 3124XE5W017671 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756693096625286881?= X-GMAIL-MSGID: =?utf-8?q?1756693096625286881?= |
Series |
mm: introduce entrance for root_mem_cgroup's current
|
|
Commit Message
zhaoyang.huang
Feb. 2, 2023, 4:32 a.m. UTC
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com> Introducing memory.root_current for the memory charges on root_mem_cgroup. Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com> --- mm/memcontrol.c | 5 +++++ 1 file changed, 5 insertions(+)
Comments
On Wed, Feb 1, 2023 at 8:34 PM zhaoyang.huang <zhaoyang.huang@unisoc.com> wrote: > > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com> > > Introducing memory.root_current for the memory charges on root_mem_cgroup. Why and how are you planning to use it?
On Thu, Feb 2, 2023 at 2:30 PM Shakeel Butt <shakeelb@google.com> wrote: > > On Wed, Feb 1, 2023 at 8:34 PM zhaoyang.huang <zhaoyang.huang@unisoc.com> wrote: > > > > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com> > > > > Introducing memory.root_current for the memory charges on root_mem_cgroup. > > Why and how are you planning to use it? root_mem_cgroup is lack of such statistic entry for debug purpose, which is the counterpart of memory.current within other memcgs
On Thu 02-02-23 12:32:57, zhaoyang.huang wrote: > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com> > > Introducing memory.root_current for the memory charges on root_mem_cgroup. Charges are not currently accounted for the root memcg universally. See try_charge which is used for all user space and skmem charges. I am not 100% sure about objcg based accounting because there is no explicit check for the root memcg but this might be hidden somewhere as well. That means that the patch as is doesn't really provide and usable value. The root exemption has been removed in the past but that has been reverted due to a regression. See ce00a967377b ("mm: memcontrol: revert use of root_mem_cgroup res_counter") for more. > Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com> > --- > mm/memcontrol.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index ab457f0..158d4232 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -6681,6 +6681,11 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, > > static struct cftype memory_files[] = { > { > + .name = "root_current", > + .flags = CFTYPE_ONLY_ON_ROOT, > + .read_u64 = memory_current_read, > + }, > + { > .name = "current", > .flags = CFTYPE_NOT_ON_ROOT, > .read_u64 = memory_current_read, > -- > 1.9.1
On Thu, Feb 2, 2023 at 12:27 AM Michal Hocko <mhocko@suse.com> wrote: > > On Thu 02-02-23 12:32:57, zhaoyang.huang wrote: > > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com> > > > > Introducing memory.root_current for the memory charges on root_mem_cgroup. > > Charges are not currently accounted for the root memcg universally. See > try_charge which is used for all user space and skmem charges. I am not > 100% sure about objcg based accounting because there is no explicit > check for the root memcg but this might be hidden somewhere as well. Yes in __get_obj_cgroup_from_memcg(). However the reason to use try_charge_memcg() to bypass root check was to avoid the race with reparenting. More details in c5c8b16b596e ("mm: memcontrol: fix root_mem_cgroup charging"). > > That means that the patch as is doesn't really provide and usable value. > The root exemption has been removed in the past but that has been > reverted due to a regression. See ce00a967377b ("mm: memcontrol: revert > use of root_mem_cgroup res_counter") for more. > One advantage I can see is if someone is looking for usage for all top containers (alive or zombie) but I wanted to know if that was the real motivation behind the patch.
On Thu 02-02-23 10:24:08, Shakeel Butt wrote: > On Thu, Feb 2, 2023 at 12:27 AM Michal Hocko <mhocko@suse.com> wrote: > > > > On Thu 02-02-23 12:32:57, zhaoyang.huang wrote: > > > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com> > > > > > > Introducing memory.root_current for the memory charges on root_mem_cgroup. > > > > Charges are not currently accounted for the root memcg universally. See > > try_charge which is used for all user space and skmem charges. I am not > > 100% sure about objcg based accounting because there is no explicit > > check for the root memcg but this might be hidden somewhere as well. > > Yes in __get_obj_cgroup_from_memcg(). However the reason to use > try_charge_memcg() to bypass root check was to avoid the race with > reparenting. More details in c5c8b16b596e ("mm: memcontrol: fix > root_mem_cgroup charging"). Thanks for the pointer! > > That means that the patch as is doesn't really provide and usable value. > > The root exemption has been removed in the past but that has been > > reverted due to a regression. See ce00a967377b ("mm: memcontrol: revert > > use of root_mem_cgroup res_counter") for more. > > > > One advantage I can see is if someone is looking for usage for all top > containers (alive or zombie) but I wanted to know if that was the real > motivation behind the patch. Isn't that just a global stats that we already display via /proc files?
On Thu, Feb 02, 2023 at 09:27:39AM +0100, Michal Hocko wrote: > On Thu 02-02-23 12:32:57, zhaoyang.huang wrote: > > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com> > > > > Introducing memory.root_current for the memory charges on root_mem_cgroup. > > Charges are not currently accounted for the root memcg universally. See > try_charge which is used for all user space and skmem charges. I am not > 100% sure about objcg based accounting because there is no explicit > check for the root memcg but this might be hidden somewhere as well. root_mem_cgroup has no corresponding obj_cgroup: see memcg_online_kmem(). Thanks
On Fri, Feb 03, 2023 at 09:58:56AM +0100, Michal Hocko wrote: [...] > > > > One advantage I can see is if someone is looking for usage for all top > > containers (alive or zombie) but I wanted to know if that was the real > > motivation behind the patch. > > Isn't that just a global stats that we already display via /proc files? > Things are a bit complicated for kernel memory. Let's take a simple example where there are no processes in the root memcg. In this case the user memory stats should be similar to the global stats under /proc because we always charge user memory. However the kernel memory has to be opted-in to be accounted. So, we have a lot of allocations which are in the global stats but not in the memcg stats. We can traverse the top level memcgs to get kernel stats and subtract it from the global stats which will give the sum of zombie kernel memory and unaccounted kernel memory. For debugging and history/analysis purpose, differentiating between zombie and unaccounted makes sense.
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ab457f0..158d4232 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6681,6 +6681,11 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, static struct cftype memory_files[] = { { + .name = "root_current", + .flags = CFTYPE_ONLY_ON_ROOT, + .read_u64 = memory_current_read, + }, + { .name = "current", .flags = CFTYPE_NOT_ON_ROOT, .read_u64 = memory_current_read,