From patchwork Tue Feb 13 12:36:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 13555069 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 CDBDCC4829A for ; Tue, 13 Feb 2024 12:36:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 668C56B0080; Tue, 13 Feb 2024 07:36:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 624376B0083; Tue, 13 Feb 2024 07:36:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46B6C6B0085; Tue, 13 Feb 2024 07:36:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3340C6B0080 for ; Tue, 13 Feb 2024 07:36:17 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0788AA012B for ; Tue, 13 Feb 2024 12:36:17 +0000 (UTC) X-FDA: 81786728394.24.AFC451E Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2122.outbound.protection.outlook.com [40.107.92.122]) by imf02.hostedemail.com (Postfix) with ESMTP id 435928000B for ; Tue, 13 Feb 2024 12:36:14 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=azul.com header.s=selector2 header.b=S1hFuMtT; dmarc=pass (policy=quarantine) header.from=azul.com; spf=pass (imf02.hostedemail.com: domain of jkratochvil@azul.com designates 40.107.92.122 as permitted sender) smtp.mailfrom=jkratochvil@azul.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707827774; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=8OaIjqPI79Qx00eUjhBIJ6pNzFUVtXCr9JC8O5VwCdM=; b=vZbXbM3eCyULKp8+2gq0G4qiEpu02m/Gsl4GrVE6bWojDZSjaNlpltH1zoeRoXRwSLVzvy BD6RtK+vJg3dAU65l8tm8pql5r2PMpzIsNxYxAkZ2dvEuxktbPg270uh9V4x6ys8vCCUU4 Lb/2BClCDi2xE81r5G84wPZaMnFXyDE= ARC-Authentication-Results: i=2; imf02.hostedemail.com; dkim=pass header.d=azul.com header.s=selector2 header.b=S1hFuMtT; dmarc=pass (policy=quarantine) header.from=azul.com; spf=pass (imf02.hostedemail.com: domain of jkratochvil@azul.com designates 40.107.92.122 as permitted sender) smtp.mailfrom=jkratochvil@azul.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1707827774; a=rsa-sha256; cv=pass; b=CD/mdcM0FuNJ2EpoFDqngtm1RZP5Afjhsv+ECjv7hdSpB1EFKF7cLTbRHRr3ujog2sC+Wg fwr/4Y4PPQ4JG33fdbOpBncOrpkcHO51VO4Pi8w5mYIi7f40/asnZGQ6zii0FBeML6kqc0 xUoeoFQLilUXS9xrwh3XkQgPPO+JW6w= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iwl+5EbwTvugQS1Q7iwAtk9sKF9rhUOCgeAJlxlNdBGyhm8YyYa0MiOl4GwJ/XNWDmMnbQoFtc3Xgs1OwHCQ1/DKj8ZnclLXC/1aR43ZKAxsunR2Qiq1VpkCgmz+lAzijcFSSh2zIp7VxUViaYd8vGjviAen2DVYVvwKSrsTtNAmBqbdDzXWKgJ4rsxbLu1d0XURmPeqjOooY27YiXmGa150GC7C5/lZ+b4vTnNFch1BkgY8JM02Sf7VjXOnF5lcUH5a7AnAldEnOMU+xec2BHLE5i/6zpbefF0V1Qy0nfv/A21JlrdFMP5SlDjzJZTsX7ZsQGqGoAvYi9ku9UYG1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8OaIjqPI79Qx00eUjhBIJ6pNzFUVtXCr9JC8O5VwCdM=; b=Wagn5h6aSxbf++D2xtR4OqVCKnOrHfayGPCUkxYHhCcafXRMC5pVt06m4UY5U5NNCdOfJUF9xkaDKGhMVLjaJIZ/FXV8V9iCCsMqlZQSL3guyCcfRAJHCpygdVrzkiiXRMpUBfsHFVl8YIX7gQRawO/ONaEqQN5wkbRGRpDTIm3mb/V7DecGAfEQLEXZ9rk8/Gl+BuVmAGrvjSlLZxj3cqy+AkIltvtN5Tiu7845k+QXQ+uSkHOBk4V0r9Zw2Hkn4KzmPAfklewvyexxM8qIBdfr1ttLT7mfOOAPew6M0auejNd64aHOkxL6cNH6vTRKdk8LrCixt4WMlFAfTx9xEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=azul.com; dmarc=pass action=none header.from=azul.com; dkim=pass header.d=azul.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=azul.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8OaIjqPI79Qx00eUjhBIJ6pNzFUVtXCr9JC8O5VwCdM=; b=S1hFuMtTlhPgiH1rSyfOGk7RsrpCYueA3t8Rz8/YYNyO7vE367vPaxcvX4xVKZJm2zV4aa2uryWYK9qy9eoFCjofaBixaNbRxbCP0T+2xBar52rZc9TzvkN3nk3Z/IaJIyvS3Dx8NxTKWuQnL0I19upkfpx0GcJ2rMI+s7M2OuysF32a1wE3QQgz4pZEnhFnNnwiqfRW390KuUg2a1jGovpxMLW7wk/TjgZmjKZ9Y5HM1rr3op3vPc80RFXkZPPdY7HekXfU5nOQ+YWDPg7iqsCxWvIy9u4k2sSyZv+tYXnQ2elrBagvocyP9mdre6bDOI7i4pj/emyVWraQauqzmA== Received: from CH2PR11MB4342.namprd11.prod.outlook.com (2603:10b6:610:3b::19) by CY5PR11MB6283.namprd11.prod.outlook.com (2603:10b6:930:21::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.27; Tue, 13 Feb 2024 12:36:10 +0000 Received: from CH2PR11MB4342.namprd11.prod.outlook.com ([fe80::b505:1895:94e1:91c3]) by CH2PR11MB4342.namprd11.prod.outlook.com ([fe80::b505:1895:94e1:91c3%5]) with mapi id 15.20.7270.033; Tue, 13 Feb 2024 12:36:09 +0000 Date: Tue, 13 Feb 2024 20:36:03 +0800 From: "Jan Kratochvil (Azul)" To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Waiman Long , Michal Koutny Subject: [PATCH v3] cgroup2: New memory.max.effective like cgroup1 hierarchical_memory_limit Message-ID: Content-Disposition: inline User-Agent: Mutt/2.2.12 (2023-09-09) X-ClientProxiedBy: VI1PR06CA0140.eurprd06.prod.outlook.com (2603:10a6:803:a0::33) To CH2PR11MB4342.namprd11.prod.outlook.com (2603:10b6:610:3b::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR11MB4342:EE_|CY5PR11MB6283:EE_ X-MS-Office365-Filtering-Correlation-Id: dd5bd3cd-f809-4255-d45e-08dc2c905b06 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Y+TbHQVpxpVUYIH06VDO8b3qI9tMswF/T9qVeaUOTvQcDGmJIYHdo5ciIh8Ath/52wj0HlJ3AO9BjNG7jsDUjYBeLuW5J6OCUc8IsA0q7ZsiFbOAaK/8IuqxtSFhoKr3QcRMNc4ZpOyAQTDOVrDJtwydExDW0DqRX0UjzEmhpxQ3EM/D8/aovMFQuNsYpn1m/lqA7BO2+lCXYcsmW98UvktdZiy5qnbYLLIYpIb/G8rAEYiIZRUjuzHE6dfoafS7UhS6L+ffnUnOKXdb6SRzjznJSgRmw1jO6xcNGnOHfE+C0djuJae8DferlM7M81H2AuFBM/VUExDTOqneYy6+WbXPUzzvS16DWOC+Re3lfjnaJcSGs+lSvZYx+/weRfbzHmMm17kAk4R/L1TcihwodRNJ8AdBhSkiCjMcgYfjzKCQv2tkp9OqLwlLFeGU5MWJbGBHdeP4Ny+gbgqpVS0GoSix9y8uirH2XwjnxREG5rGr8xn8Eb+ejJrWo341xCPO8UM1/PxT8eUl0m1FgOMiJzf5kmfvLMUWww8S1N3jqvs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR11MB4342.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(39850400004)(376002)(346002)(366004)(396003)(1800799012)(64100799003)(186009)(451199024)(6512007)(478600001)(966005)(6506007)(6666004)(6486002)(83380400001)(2906002)(5660300002)(9686003)(66476007)(66946007)(66556008)(8676002)(110136005)(316002)(8936002)(38100700002)(86362001)(41300700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zvqERnlWzLYS7QUyZZehgVVj2q5SAc18ny6Xw4RZkZMc50S45/z9HVGUxZkgmP1hOte7pWI9q32EJs5CXLsCPi0ouE2IiNC2X0HKP2Vnpcrc/xi02bLPmjdQrmuDu4pp+FUSscYe6AbpM0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8X6A23G8AjcKz7J262ieMI16VkR0a7SbkbKcghi8+xBeCdYZetF3i/vVJjVkNbM2Y8Ha81XdnCNZNcWrV+0Ubfgz1cR2NC85atx7EAS3eOaeYLWjE6QXZ3p/xV7QZtwzL9A3DZhz4cbjCg8aB9rK57H+42+Aeb+/N6W4ViXrPHMT+UlN7rgQDFVjUP2GmbTNpruZy0LHirO8NnmnLyXV1jdnFTuuNU+De881nFaRfz370n6Ge+TT3UndeSetp+s4sK6rJe7jA/d9R8JtpYdJz7uZxEjLTNyWGLXMEBZRORcvmNxjCQt4tZ3bEVh8LJQAUiTfPXUYkyZyGwE4AhiS4W+b0VDVDqtsk6hpwbs0ewd9vsEgq3DtW9f34Bg== X-OriginatorOrg: azul.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd5bd3cd-f809-4255-d45e-08dc2c905b06 X-MS-Exchange-CrossTenant-AuthSource: CH2PR11MB4342.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 12:36:09.4959 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: c480eb31-2b17-43d7-b4c7-9bcb20cc4bf2 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4zlAwKsSkuTjHTBzkDhAjrAOX59PedNDE2QgBFec+I3281/I7S9QupMgYoQ2ZHbHU0zqr3UW0dneWX1PUFYLpg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR11MB6283 X-Rspamd-Queue-Id: 435928000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 77u1k44q45zqk558q4qdexat4tab1xdk X-HE-Tag: 1707827774-141091 X-HE-Meta: U2FsdGVkX1+gW/cZMbJCrxJ8ATIQgNNhIdBfkPL9X9VgsN0JjwUcI8xGx5P8pzVU5spAQ3T0AjHa+FCWzif6B0DVTXQzs0JU0DzH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w7E1Fe9OB8hVXVS2ar0uxNaWrcZMrY0itpvuLHmySSqCIbHvLdPQnazKVHppgITW+DFSQIQ16r+T8NObqlPZgz+Gb8ZoVTFm+XIeRZ8SgVa0CUprYEUA3oB6N8L7rqbfzsHoXZImhdXYi0MV57Bq8XfZas/zJ5GPgcqUH0xVtirrqsJZeFwHsRIjMzAuaJ0KWCyWcJc4xLu0H2RE2jYZ6w== 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: Hello, cgroup1 (by function memcg1_stat_format) contains two lines hierarchical_memory_limit %llu hierarchical_memsw_limit %llu which are useful for userland to easily and performance-wise find out the effective cgroup limits being applied. Otherwise userland has to open+read+close the file "memory.max" and/or "memory.swap.max" in multiple parent directories of a nested cgroup. For cgroup1 it was implemented by: memcg: show real limit under hierarchy mode https://github.com/torvalds/linux/commit/fee7b548e6f2bd4bfd03a1a45d3afd593de7d5e9 Date: Wed Jan 7 18:08:26 2009 -0800 But for cgroup2 it has been missing so far. Based on Michal Koutny's idea this patch now implements "memory.max.effective" and "memory.swap.max.effective" files similar to existing "cpuset.cpus.effective". Jan Kratochvil v3: memory.stat fields -> *.max.effective separate files suggested by Michal Koutny v2: hierarchical_memsw_limit -> hierarchical_swap_limit fix found by Waiman Long v1: hierarchical_memory_limit && hierarchical_memsw_limit in memory.stat Signed-off-by: Jan Kratochvil (Azul) mm/memcontrol.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1ed40f9d3..8c4cb5f60 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6845,6 +6845,19 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, return nbytes; } +static int memory_max_effective_show(struct seq_file *m, void *v) +{ + unsigned long memory; + struct mem_cgroup *mi; + + /* Hierarchical information */ + memory = PAGE_COUNTER_MAX; + for (mi = mem_cgroup_from_seq(m); mi; mi = parent_mem_cgroup(mi)) + memory = min(memory, READ_ONCE(mi->memory.max)); + + return seq_puts_memcg_tunable(m, memory); +} + /* * Note: don't forget to update the 'samples/cgroup/memcg_event_listener' * if any new events become available. @@ -7038,6 +7051,11 @@ static struct cftype memory_files[] = { .seq_show = memory_max_show, .write = memory_max_write, }, + { + .name = "max.effective", + .flags = CFTYPE_NOT_ON_ROOT, + .seq_show = memory_max_effective_show, + }, { .name = "events", .flags = CFTYPE_NOT_ON_ROOT, @@ -8040,6 +8058,19 @@ static ssize_t swap_max_write(struct kernfs_open_file *of, return nbytes; } +static int swap_max_effective_show(struct seq_file *m, void *v) +{ + unsigned long swap; + struct mem_cgroup *mi; + + /* Hierarchical information */ + swap = PAGE_COUNTER_MAX; + for (mi = mem_cgroup_from_seq(m); mi; mi = parent_mem_cgroup(mi)) + swap = min(swap, READ_ONCE(mi->swap.max)); + + return seq_puts_memcg_tunable(m, swap); +} + static int swap_events_show(struct seq_file *m, void *v) { struct mem_cgroup *memcg = mem_cgroup_from_seq(m); @@ -8072,6 +8103,11 @@ static struct cftype swap_files[] = { .seq_show = swap_max_show, .write = swap_max_write, }, + { + .name = "swap.max.effective", + .flags = CFTYPE_NOT_ON_ROOT, + .seq_show = swap_max_effective_show, + }, { .name = "swap.peak", .flags = CFTYPE_NOT_ON_ROOT,