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 X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EEBDC2D0E4 for ; Tue, 24 Nov 2020 11:26:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4B9082076B for ; Tue, 24 Nov 2020 11:26:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="NdgHMtdY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B9082076B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 82AB16B00B9; Tue, 24 Nov 2020 06:26:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D8B76B00BA; Tue, 24 Nov 2020 06:26:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EF5C6B00BB; Tue, 24 Nov 2020 06:26:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id 592226B00B9 for ; Tue, 24 Nov 2020 06:26:15 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1AF75181AEF21 for ; Tue, 24 Nov 2020 11:26:15 +0000 (UTC) X-FDA: 77519083110.24.band32_0005f672736d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id E2F701A4AA for ; Tue, 24 Nov 2020 11:26:14 +0000 (UTC) X-HE-Tag: band32_0005f672736d X-Filterd-Recvd-Size: 3426 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Nov 2020 11:26:14 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1606217173; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jXr6QneDp2gyWm4z+0ntuKNCFM6noV3BZjgwhMClHvw=; b=NdgHMtdY+WJQriDVpq2qkEw/p6UkfzkpoFswP4Q062cvu8TyFR660jrLhYqSA9GXE2xENf eTiTyuE69WbuGPEe6/F60X1SIO4/DVdj0tmK1gZxZlfmi/DV8artIw2P82QJZl9TS6+VL4 9zobRzvA0rtgeB/1ZvaHyVttmRkgnf0= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 14A43AD21; Tue, 24 Nov 2020 11:26:13 +0000 (UTC) Date: Tue, 24 Nov 2020 12:26:12 +0100 From: Michal Hocko To: Aaron Tomlin Cc: linux-kernel@vger.kernel.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] memcg: add support to generate the total count of children from root Message-ID: <20201124112612.GV27488@dhcp22.suse.cz> References: <20201124105836.713371-1-atomlin@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201124105836.713371-1-atomlin@redhat.com> 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: On Tue 24-11-20 10:58:36, Aaron Tomlin wrote: > Each memory-controlled cgroup is assigned a unique ID and the total > number of memory cgroups is limited to MEM_CGROUP_ID_MAX. > > This patch provides the ability to determine the number of > memory cgroups from the root memory cgroup, only. > A value of 1 (i.e. self count) is returned if there are no children. > For example, the number of memory cgroups can be established by > reading the /sys/fs/cgroup/memory/memory.total_cnt file. Could you add some explanation why is this information useful for userspace? Who is going to use it and why a simple scripting on top of cgroupfs is insufficient. > Signed-off-by: Aaron Tomlin > --- > mm/memcontrol.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 29459a6ce1c7..a4f7cb40e233 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -4535,6 +4535,19 @@ static int mem_cgroup_oom_control_write(struct cgroup_subsys_state *css, > return 0; > } > > +static int mem_cgroup_total_count_read(struct cgroup_subsys_state *css, > + struct cftype *cft) > +{ > + struct mem_cgroup *iter, *memcg = mem_cgroup_from_css(css); > + int num = 0; > + > + for_each_mem_cgroup_tree(iter, memcg) > + num++; > + > + /* Returns 1 (i.e. self count) if no children. */ > + return num; > +} > + > #ifdef CONFIG_CGROUP_WRITEBACK > > #include > @@ -5050,6 +5063,11 @@ static struct cftype mem_cgroup_legacy_files[] = { > .write_u64 = mem_cgroup_oom_control_write, > .private = MEMFILE_PRIVATE(_OOM_TYPE, OOM_CONTROL), > }, > + { > + .name = "total_cnt", > + .flags = CFTYPE_ONLY_ON_ROOT, > + .read_u64 = mem_cgroup_total_count_read, > + }, > { > .name = "pressure_level", > }, > -- > 2.26.2 > -- Michal Hocko SUSE Labs