From patchwork Mon Jul 22 22:53:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13739203 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 72721C3DA59 for ; Mon, 22 Jul 2024 22:53:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDC0E6B0083; Mon, 22 Jul 2024 18:53:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B64FB6B0088; Mon, 22 Jul 2024 18:53:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A06666B0089; Mon, 22 Jul 2024 18:53:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 811C16B0083 for ; Mon, 22 Jul 2024 18:53:43 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1D475121A86 for ; Mon, 22 Jul 2024 22:53:43 +0000 (UTC) X-FDA: 82368892326.10.1B3EF5E Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) by imf24.hostedemail.com (Postfix) with ESMTP id 02364180036 for ; Mon, 22 Jul 2024 22:53:39 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=q+ryCMk2; spf=pass (imf24.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721688775; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=8sJwcAqpBiYi821c2Fxl1tovp9YkMU1/UiqUIEtndtA=; b=MMBBoOyAUdgK6QS4S1+ECWRu8mReNC4yuzgBm5nqHrAzeWWGww/4Oug2Cj29caHklrTaFN inLeYN31xA/uYdOjHlu5GBlcpHPeaIFZO6JRMM29qtpGXFn/9GK2UTXFcy8FazyzAIC1Cx mYEHFRP84kieY0oHh3xfF98gJO59PqE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721688775; a=rsa-sha256; cv=none; b=HJOHTDszZUwBJ7Fq1DtW0waUZt7YggBRafwkZBQeFfqRZfK8DISZ3+Z+yb1OfYtBuF+hfj QnljUUivz2lh37HHL23rNezK4NrQhdcPcNppPlwBUfuO19rF03sje63cyGMD4jGwaXduCx QZF7ljrFvqQAmrchMO2lvWd+AQG9pfw= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=q+ryCMk2; spf=pass (imf24.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721688818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=8sJwcAqpBiYi821c2Fxl1tovp9YkMU1/UiqUIEtndtA=; b=q+ryCMk283FwBMLX6O+k0tRZUIoK+vY1U7KunrRpvdrBVkgIxujDh6a8hTFNIj2sT6z3cE luiDeDDF0TYV+axoK/nYChqYM1tPD8pDQJc8JKY+8eX1qdW/S3eTom2gzZvzjii2IQbnL4 TloVih+CMWIcFja7lo9M9FnIjBw0BCA= X-Envelope-To: hannes@cmpxchg.org X-Envelope-To: mhocko@kernel.org X-Envelope-To: roman.gushchin@linux.dev X-Envelope-To: muchun.song@linux.dev X-Envelope-To: gthelen@google.com X-Envelope-To: kernel-team@meta.com X-Envelope-To: linux-mm@kvack.org X-Envelope-To: linux-kernel@vger.kernel.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song Cc: Greg Thelen , Facebook Kernel Team , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] memcg: expose children memory usage for root Date: Mon, 22 Jul 2024 15:53:06 -0700 Message-ID: <20240722225306.1494878-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 02364180036 X-Stat-Signature: 3ps5hbj6sfmhewrhp47rw5djgumx641r X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1721688819-71495 X-HE-Meta: U2FsdGVkX18YQI0bM5gpXGcgHdKmq8jr5aunLOpVy0iVNdL4jESWE37utSRpkAghLqIpzFgpW5Gi26yp5Y8QXGlG0R8mnVbeZWVeG5se5ZY2ewxNJxOfVro5fYjT6YV91jMFqNvRZceoBohxg47j+NrMEGNBhLpjslXeUrhhBWVDT8KEh1zYUzWPWzbnv+zSLbT3w44QDCRoyNh7IAm8gKTi3VDtNmjc5s4qxxqnj+IUeChdzPgNNwf6Ua4QX5nR9LGPmtCfSATc0FIfM0u1F1SjMevOubiggjC2P8DeqPntqw0rQgA7br9ISA+n+Uf6FIbcVUOXWm13T4XTdK5wQTu6leDduvxhMrqijsUzMW+JNM8aSKXXVZgNclSecJJb1Wiy+VuiYmL+AsNPnxLcgPi+PHxS6rGt1+IPB5hO+ewWsFYG9p9LxZ0QfBnk5s7WaxJx6td84+Si4YOUiVm26CjFEkRt0WTh3K81EX0F807dcxIztRrxK6tDNaufPFJV3G8VuBEZhsgmkX6++fLM7eZLAKAPZh+LmZTR5/CZeP0plmGRRhXrtujIsbxu4cE9drFEKrwf67bQKSeEcVZEjE51FvYMkHQiOzKfzRCZPX2LCattx/zAWJPT0qoxMDNlbGc8Nyyvbp/fxTOggC+RlIryeAEfTcs/KK+HzJYOLTsqruI7rMGXNAK5slU8Iqfg96CyCjrUmgSc6ntkK8LFC4W4Qy/QYIO4WXXpjSNSip5mVLBePP7i5djmeYulMY8AdczJiqQ3Ba+3tKR25QAsMDfZMywPWCSKdkE0AN1dXyeP+4cmXBZi1OsBzpwojp3kuq1xNLZzznjRSVE7T9h7V56QSUfykMlWlWX2VRu7AxMEORxwCwDHjSKncwQX7y7XVqikBPuIoyzp+szhP+08beg1yfa1dAbYvTCBERop1IefViXCq06+4euLvLS9WtlaUi/LV8+AnMFUTvHxSX2 8/OW9PRU /xOnkCrmaPHClf1ON700Td3B06cjG8JwRbfMaaG/GeVfks5HU1z9xclb4MfJOE2BeXXh99wja3/pkezSqvU6SX7MNTiz2ChA0N0q1Et5aLN0xTiY= 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: List-Subscribe: List-Unsubscribe: Linux kernel does not expose memory.current on the root memcg and there are applications which have to traverse all the top level memcgs to calculate the total memory charged in the system. This is more expensive (directory traversal and multiple open and reads) and is racy on a busy machine. As the kernel already have the needed information i.e. root's memory.current, why not expose that? However root's memory.current will have a different semantics than the non-root's memory.current as the kernel skips the charging for root, so maybe it is better to have a different named interface for the root. Something like memory.children_usage only for root memcg. Now there is still a question that why the kernel does not expose memory.current for the root. The historical reason was that the memcg charging was expensice and to provide the users to bypass the memcg charging by letting them run in the root. However do we still want to have this exception today? What is stopping us to start charging the root memcg as well. Of course the root will not have limits but the allocations will go through memcg charging and then the memory.current of root and non-root will have the same semantics. This is an RFC to start a discussion on memcg charging for root. Signed-off-by: Shakeel Butt --- Documentation/admin-guide/cgroup-v2.rst | 6 ++++++ mm/memcontrol.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 6c6075ed4aa5..e4afc05fd8ea 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1220,6 +1220,12 @@ PAGE_SIZE multiple when read back. The total amount of memory currently being used by the cgroup and its descendants. + memory.children_usage + A read-only single value file which exists only on root cgroup. + + The total amount of memory currently being used by the + descendants of the root cgroup. + memory.min A read-write single value file which exists on non-root cgroups. The default is "0". diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 960371788687..eba8cf76d3d3 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4304,6 +4304,11 @@ static struct cftype memory_files[] = { .flags = CFTYPE_NOT_ON_ROOT, .read_u64 = memory_current_read, }, + { + .name = "children_usage", + .flags = CFTYPE_ONLY_ON_ROOT, + .read_u64 = memory_current_read, + }, { .name = "peak", .flags = CFTYPE_NOT_ON_ROOT,