From patchwork Tue Feb 13 21:56:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 13555743 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 BC57BC48260 for ; Tue, 13 Feb 2024 21:56:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A27A8D0020; Tue, 13 Feb 2024 16:56:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 552CA8D001A; Tue, 13 Feb 2024 16:56:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CC578D0020; Tue, 13 Feb 2024 16:56:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2941D8D001A for ; Tue, 13 Feb 2024 16:56:35 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 06206A219E for ; Tue, 13 Feb 2024 21:56:35 +0000 (UTC) X-FDA: 81788140350.26.C85DC55 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2100.outbound.protection.outlook.com [40.107.236.100]) by imf24.hostedemail.com (Postfix) with ESMTP id 53232180026 for ; Tue, 13 Feb 2024 21:56:32 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=azul.com header.s=selector2 header.b=LVQwYYU9; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=azul.com; spf=pass (imf24.hostedemail.com: domain of jkratochvil@azul.com designates 40.107.236.100 as permitted sender) smtp.mailfrom=jkratochvil@azul.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1707861392; a=rsa-sha256; cv=pass; b=tc7OUW820l+j/E/xJN7y4ukA4WdUKfo+J6hiwYXuHsqbeyqen8dvMg09HrADfsyCoJbZKs 8GYuQln4yFIHwjY2W7mSpZtFZ0O3hRaE4V1Dv/+AlTlcUMrrAMEzfezbIsvr+94itJeEQo CcOHLQlnMp6CQWJjjT92UhUXGg8ipLI= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=azul.com header.s=selector2 header.b=LVQwYYU9; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=azul.com; spf=pass (imf24.hostedemail.com: domain of jkratochvil@azul.com designates 40.107.236.100 as permitted sender) smtp.mailfrom=jkratochvil@azul.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707861392; 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=IbSY+mIhMEBqPxs6kaSUCiP7Ans6rCJhGr04oMsXQyY=; b=c5vjz/GfpkobTb0Jba/6mowVLEMkP6hAEKNAnoW6jtutEPBNCKRquD8Xu2EeKXChZDrD+y 7OB5QuM4S3yTK9PQG8wdFbL93ZOQGDAaEPFNYgDVJ2CP8x/Z5l0aXQSfRK1qzOovuJXhAY VtIp8CBUJ3CGXe14CVu7nW3ZRmRzDKE= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bdTxYjbQAj8aPHiX9aK6NV1vjqsIZF2aHAydCQ4qNOqlQXAaXqSaT1ohVbh2uxDi1Y4wtVoxCtPKTl4eT/qDBCl/rhjri4bTE3MBdgfbFkDMCE6So5XfyYnOjwgSi2V/UJKStfe+dy8BLxXitLcrmFcp4Np7Dju22URaDmhpgvqrMxyvSEfb07sgHuLnv/mJPsmCpjHDmz38P6xuDxqBbau/Te8kxlcLAWbkAJ4jJ9uxIrG3ABnUO+c/+3iFndcl0ytsHYj0Cin4XKdZ0P++xdI7ZHYzD4vkHRRm7jSqHnxcQaGQHLPJth85Nd+4a8jjksrY1smmwT4iABldmGbDKw== 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=IbSY+mIhMEBqPxs6kaSUCiP7Ans6rCJhGr04oMsXQyY=; b=TFhrQzSjZKjaIneMYW+5mBQ2d/IZLKtfc7ZeA5C+yrjuZX11S7nQ8SCVFk0CSLcNdRAjU6V2o1qZbCYLIEqaZddX8YBCpGzpj3yjRHdqeva/XYBH02abfbkN7gurYRNEOd7zIWpZbeCjm5OU4w3i/P2ZDzgQ5udYvFbj1HJYNONHc9ZpqxNJA1s38lyCtxG3Vf2jSoO6V6/Z9JMYDM0Wu2TIJFUgVIqN3F1Hafdl5sWs42yQidHvRZEP1jHCbB7j/7uzb60GY3ELTq/5CxuqsdapWJ0+SHVbbBTlCn5Ie7cLWvWUUbOfKnOpPOJOVqfzYi3jswZ9eTAXwRVfVoE3OA== 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=IbSY+mIhMEBqPxs6kaSUCiP7Ans6rCJhGr04oMsXQyY=; b=LVQwYYU9S1Kt+Wkz+OCOLTXgqXK93xG6vvfMnFcOaf2OzvuwPsBahGwYc+vvr+g8rcHLcWQkK3OG7CDTPJMCgZPd5dAhH63hpbJ/GtBUVcIzmVlJWloGvSHrcYe1ao14nRNkBkjkkyzjaVTi6SwdcPx8jRbcaqS1NpgYjmne6nrRKewe7w31qJuqhTv4gg2LH/m3hvUsrGYsqUqbWaAOavKccSL6GtZX7gkoNLjvkIo878XS4vVAdRwyxxwQvS6Ydvife7nPs/urUOfi+MBFC6SkY9ZQO6drIf6yFkkO9AqARvXg4/3wNxrAVP85CZIxsgaaPMpqdig5ecRDW1kmdA== Received: from CH2PR11MB4342.namprd11.prod.outlook.com (2603:10b6:610:3b::19) by CH0PR11MB5268.namprd11.prod.outlook.com (2603:10b6:610:e3::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.35; Tue, 13 Feb 2024 21:56:27 +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 21:56:26 +0000 Date: Wed, 14 Feb 2024 05:56:20 +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 v4] 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: VI1PR06CA0095.eurprd06.prod.outlook.com (2603:10a6:803:8c::24) To CH2PR11MB4342.namprd11.prod.outlook.com (2603:10b6:610:3b::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR11MB4342:EE_|CH0PR11MB5268:EE_ X-MS-Office365-Filtering-Correlation-Id: bdf0a830-9b0a-4752-3a29-08dc2cdea05e 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: vuhqRv1svc4hrrZNLEdppysYpQGtgMkCfCsXmAVpi/BTmC1GQTy/G3+uqZZZCwqiByouEd1yrQqQxGQc9RTesowGQI0uoasq+gvQ5CvvCcOmQoRRlvEpo3nwQXSydg74LiLcbiiSrzBCU7mZMBmW/vWeRj/eIKF4Jy6nwR9H1tHjeSaunvh+smfzw2tdzOOVXeKil+ncVogTXH7hAOaZcMVjbcqO/d6RlG4BkfBdDPdUHIajF/Mrj0GrH/oZbU3CjB936ZH6bk9+GtYTJa5yizs5kAKM1FXVuQMV1q2jJihVXUOKmMBtSKCh8nuBw7ofYxHbi8IZ8lr7PuvWR7W6whv9trqwUMDi/bNvQvyy/K2FYM2ufwN2bavUSGYu6iYhCu7Hm/OHMOBxoYPcfdu2q8miNIn//Mla4btCl+dNkHKrJSf5QPDnNuwd5RbNTpZ2eH1cFdewom4+oizhN2oCY395Xpe5mwrszPhzCLLG0pIyOLjWfrOFwpkVkm0hdL8Al5RbnzuDCyvTPELjGkMpuDiNkHtCUVBeMmf/vU72zRE= 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)(346002)(376002)(396003)(39850400004)(366004)(136003)(64100799003)(1800799012)(451199024)(186009)(38100700002)(86362001)(966005)(316002)(110136005)(478600001)(8936002)(66946007)(6486002)(66476007)(66556008)(8676002)(2906002)(5660300002)(9686003)(83380400001)(6506007)(6512007)(6666004)(41300700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XhSlqKCQV3V/Pv0WDyFuY/Opjq8vYyLFKUrVWF6npmMApSFWPhgKUIOmt9DwTlNALsyuiIjxuVqNYo0lbpifr6GpJsmn3q5XXqrdOjvf5RxklblEwdmM0piEdLI0fuJJWVGJbu2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zRDDiBvRmIL+RPFOa1DY6YwPBMPUY0/dCH+bA2AM2B4M0OkrGqJ6ty44tArB8RktArYx7EgvfzSal9WGt5gu80GF/01tZE3XKfo+m3bA2KQhYM30FdRoYPAx8QCG7Jln1XKsYR2dghiDXezwZe7KHIw4PDH/7BD21KVZGDhnzHvNPtLPmoRebIMvzOi8He/x3Sx5ZXU8suNhGl8TYpq1QOTCCJh2gkPZAPBNqVGdM/8aLz1PyeOvZQNvtqU0pT6VP4SDlhV+iYZ6mPzkoO+JYd+n2KA8nMJRKIiIFx+OsWHsOYB/uM7urtymBjRSNkDMsLIyJXa49SOBHFGcP5xTCQBVmb6x2c5acJxoAsKuBpC7UdKYHOBG9Do8ehPVP466O5xCAX2g6A4jnWdIRbeHS+oiRGvYHmsjwcGcraNifA== X-OriginatorOrg: azul.com X-MS-Exchange-CrossTenant-Network-Message-Id: bdf0a830-9b0a-4752-3a29-08dc2cdea05e X-MS-Exchange-CrossTenant-AuthSource: CH2PR11MB4342.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 21:56:26.5762 (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: Rh/r1UymEPVwhcVuWKGXv1jbx1ktq47ziXH/P02HbdZKTV0e2D5xq6Im1XISCeVsfZxoBpUtfqI311rTnQRLKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5268 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 53232180026 X-Stat-Signature: 9unzfuto9e9gz6xuzr3ykw3wqaie5dfn X-HE-Tag: 1707861392-614388 X-HE-Meta: U2FsdGVkX18zgaT3HcK8q4fB43VIA0TQQweiiJQFr71lgVOq9+pNlpw3N5vBjcSyeXc2JpxQKiOI1TYwl7n4iK7h1ObdlJN402fycQD5ZbCsV+E4gdR4iRgYWytM+ML7P4ZNOM4uptdPBdVA1/1JmoP0Blg68k8HUWIFr1pLmbXEVXpOJBiXwcj2SWFnlON3jX7DEj3ZsngMhmrUW3jgp5YgNXGI7b6V9ESwFbPfj+Aenf+RKrUSmUCNJrVS706NNeNHqryRiioSN4A50qNvOInUgNsHcyckaagM9PlSTnYLutajdsf1fDJ8Q7tYnCazLP2Qsq+mlIo29Aeugk+C8a/c+d52vrFMpb64zdg1AWPeQ/oxwZ78a9l9iaQiAgXtIH9P9bTc4KOXKxR4UK6bqBVbxAUhlfAjomOW8Rq+kNGMAf4GrafbauV7NdJTj9XY+/kAO+lZ1uRtVcewQvRXBxyR2v9a0zyFRmrUagd0+m7x4iq0WUsIknpe5s1KJWyHfm238JOmtClb33d45tIgw8QFvAyZ973S6lEB1QE7OAXblBwIhC+dWcHenxg5Xg1lj9ZiebIvkpaKYaNQgiBwdUe0DWIuCPuU8EXv7aXoKX7az0GFeKQr1WPBRrY2NjDvkCzwOYLtegEpk8c1wLVDCUxixSG5UGJVGTxeSwbG+HtJtNsL/Lk6nuXSHOryylF3iJJUOi1xRuquaBZtcEaXn4xUwtGLnkreAw1oQ7LQ93GFiFQ9fDm51IFtAkI81EFB0JwzCPLyJB2tGH3xvkjCpi07iAYehFJ6GvwoNCU+tpNZzlE4MZpJTlXqgohmjTE+GebZW9qq0DF4LVqjmuek25O3b8zTT2jnxA1tmq9Zh0gtvuY4qdidadYS67yWDOPfOCyJMYRsbUd6Nt5U+BG/LQ== 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: Implement cgroup2 "memory.max.effective" and "memory.swap.max.effective" files similar to existing "cpuset.cpus.effective". 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. v4: Adjust the commit message. 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,