From patchwork Tue Nov 24 10:58:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Tomlin X-Patchwork-Id: 11927929 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 AF6B5C2D0E4 for ; Tue, 24 Nov 2020 10:58:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EEDBA2076E for ; Tue, 24 Nov 2020 10:58:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hDv84MOv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEDBA2076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E95DA6B00AF; Tue, 24 Nov 2020 05:58:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E1DB76B00B0; Tue, 24 Nov 2020 05:58:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C71436B00B1; Tue, 24 Nov 2020 05:58:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0023.hostedemail.com [216.40.44.23]) by kanga.kvack.org (Postfix) with ESMTP id AEAA26B00AF for ; Tue, 24 Nov 2020 05:58:42 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 714EA181AEF10 for ; Tue, 24 Nov 2020 10:58:42 +0000 (UTC) X-FDA: 77519013684.09.crime75_09139ef2736d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 55508180AD80F for ; Tue, 24 Nov 2020 10:58:42 +0000 (UTC) X-HE-Tag: crime75_09139ef2736d X-Filterd-Recvd-Size: 4962 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Nov 2020 10:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606215521; h=from:from: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:content-transfer-encoding; bh=93iiWXlJJ6IXGgnGTBAqbCv2bSJUjXfqZiq9BMzLTt8=; b=hDv84MOvzjT47zoKyNVXUJVXYwMnX+4PHVDDJ2BFf/0Y8jlEIGyL6wsrHU1j4hiKyTjiW4 1OjlIowrwY9yQbA7S3yLaINQzZOEelJ7aNmPuNxVkUNDw1TqAYya4b8hdioaasmX2mMPbK UrW+FBFb6JMM4Sy+AxsWz/gT9dB7U5Q= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-BPbwX3wNMeOD8tlXWZ_QMw-1; Tue, 24 Nov 2020 05:58:39 -0500 X-MC-Unique: BPbwX3wNMeOD8tlXWZ_QMw-1 Received: by mail-wr1-f72.google.com with SMTP id k1so6727677wrg.12 for ; Tue, 24 Nov 2020 02:58:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=93iiWXlJJ6IXGgnGTBAqbCv2bSJUjXfqZiq9BMzLTt8=; b=ASaAOM2ZgsjRNzojnbXEb67JuqF95AKSQe9gR0mJsusrAjmVBF+mm2T77tYOVNBoT1 vesFhYZyyo/c3YBTj/kGgZF6SvBhTcbklmXsFSxrwvqnYcAJ6izSeFCU9lQUzjqmSkSO 056AZ6WOGQlphQwGrhjg5Sw45qD5RfyguhXs9gNWbkaDxoIo39VLtpi5j1dfcCfil1UH mvJcCxWffX0uZlYPY2zOTg1t2msZyFpGe47LshFt3z3jMTqaMzD5+6npf4ggyIYi6zIe 1d3DvOvsxjr8/sNBOGa0BajJkP7jZHFi3ttvlPsLl3stQozW3gYqVdj6swpGjnnWfuQJ eQcg== X-Gm-Message-State: AOAM530FodFmnUOUZrmwTVMPdFIwjRNRHMjYIarzeGDOf6PApoYghvai zsksKBVEde+MCzOA2m6eUPemN/X0Kh4/P2/jcsQS2wjK20jeosevqOARYiNR6sPFM7XNo/A9OcI atbFzdXiN1w== X-Received: by 2002:adf:b78d:: with SMTP id s13mr4473681wre.383.1606215518067; Tue, 24 Nov 2020 02:58:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEy0NaSDK6xRfNiQMCFfdk60eQ8DmNfigWwS2jLBAhm8rLw3v70xbgbAFeeO+jjelCbnI1dg== X-Received: by 2002:adf:b78d:: with SMTP id s13mr4473660wre.383.1606215517859; Tue, 24 Nov 2020 02:58:37 -0800 (PST) Received: from localhost (cpc111767-lutn13-2-0-cust344.9-3.cable.virginm.net. [86.5.41.89]) by smtp.gmail.com with ESMTPSA id p4sm25611598wrm.51.2020.11.24.02.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 02:58:37 -0800 (PST) From: Aaron Tomlin To: linux-kernel@vger.kernel.org Cc: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] memcg: add support to generate the total count of children from root Date: Tue, 24 Nov 2020 10:58:36 +0000 Message-Id: <20201124105836.713371-1-atomlin@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=atomlin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: 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: 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. 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", },