From patchwork Mon Feb 12 04:10:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 13552689 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 E1C24C48297 for ; Mon, 12 Feb 2024 04:10:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E9F86B006E; Sun, 11 Feb 2024 23:10:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1989F6B0071; Sun, 11 Feb 2024 23:10:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 061766B0072; Sun, 11 Feb 2024 23:10:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E9C006B006E for ; Sun, 11 Feb 2024 23:10:54 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6F3411C0D60 for ; Mon, 12 Feb 2024 04:10:54 +0000 (UTC) X-FDA: 81781826028.06.347CFD2 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2138.outbound.protection.outlook.com [40.107.101.138]) by imf24.hostedemail.com (Postfix) with ESMTP id 87626180005 for ; Mon, 12 Feb 2024 04:10:51 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=azul.com header.s=selector2 header.b=eRZAwcZV; dmarc=pass (policy=quarantine) header.from=azul.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf24.hostedemail.com: domain of jkratochvil@azul.com designates 40.107.101.138 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=1707711051; 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=r3uBIHwv+BfoHqYFROcBHHrXJVitym7MFHUUjXhjehg=; b=q1WM/ePzrWnjIHGW1eHJdpmQos1oFGfvHoxrvWJ9tHil7qzHPkUU4DnZecXT9lOSrmITvK Jqwfs1QSomIEKVVvq9nt4Zbw6/SDxh9CdFLqvM4/SAU7A11rnva8+GCZZjgO6SHRfIzObp H+ijxDVHIbDTOlyQBpjHpnYi7ga6QGo= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=azul.com header.s=selector2 header.b=eRZAwcZV; dmarc=pass (policy=quarantine) header.from=azul.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf24.hostedemail.com: domain of jkratochvil@azul.com designates 40.107.101.138 as permitted sender) smtp.mailfrom=jkratochvil@azul.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1707711051; a=rsa-sha256; cv=pass; b=wie1a1spyTWQMmq74uBxgLDzQyvfRIHD/HuQU7ZLUeCPh3tzXdljRBY9rw4sPNQivg4iIc F4FVfLe4nZSGoMhBTsdTXgYICtexco2pPis88rYO9Vfdg1fIRPiKkyzs9P9Bg+qK+V0dle CzhU4Le1M1XFrniZVNRfn6nLVanTk7s= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZCi+9OQ9C9CncNsKhDXFwx4NlzXCcHyq8QyiHoj7ritm6j9/FzdumR8/01dIiDAsCkHV0v/T7YnoXWkUC3JPRZwlvQCRvP+bFzMFZjQUWF6IZqvl+nfFHY/CNSHmH4rVuLg2Db9nCPvhuM+LBzDT2cjggSaflYEfqSfz6AtxIQ7TSW3DeVK/rT8HyMBiALsncUJAEF7IzvWZdN4brPfs2cpTmW9hPYIKWKQUQcIIaWOcYK5SGnyq2HgByulerRFrwuAHtDbI7BaJEDbYXVHImNVieVdseB6wT4mT6jxH4Hi5ydfdhX49fODStfsrWargRukB43VdyzwyDNlWTSJF9Q== 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=r3uBIHwv+BfoHqYFROcBHHrXJVitym7MFHUUjXhjehg=; b=SGQJITmA/dRv1OkUDQ6o1jpJAqpnP1Clar8Ls/Bmon5Mul+mejCCXd8n2UTc7s9xQwzjUDLXmIzyrupCosbuJmXZMN3zxbFxqzZeL3refG4FAUaPlXRJWUpjkDb8giR/oPgYzTugGT1eYKT5bTtkfTTZL1sKSfq20Mung7TFElMhuMGjTVQttF4K657GR6Q+P5s5ZHIdYm1nYB+Hp8ApBp4NfgBzt3RpmK1KFzl6n23uHiXCI8ojxO7EEW6BCLmwPLqEbibRKmhHC44u/iD75Ha70M+wP2h4OhKR+leJKJi5BFPP1OseWkpVrb6zd5Hy9tpvQfKajP5p3S2xxwvWFw== 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=r3uBIHwv+BfoHqYFROcBHHrXJVitym7MFHUUjXhjehg=; b=eRZAwcZVYLY3u6k01MVW+2STybv0QRyLQPgrXqjZWInUSyP5je23+fzEnuSsj1RRBpvPtYPeEsDuMuvrFxRmMDeXx9bNz4GRUtCPh9AlP7gXoUF7OSn3MX8wzwCjun+slgf0rXXTZhpDK/FesE5j0gZdUOHQtGQzDzAECqP3Mp9KKtLv6FxcHK5vsD2YhnlAjzIGQTliNnoJk6AoKhoQl9Nph69Q+5AWECQ/MTUxl3tb8mBtq+wkuD6GkI8n4UWBBubX/vwrrB+UL6ym/sCj9laXRzzpGjnXPbDwNbzhS7mQr4PGIrXKaB8tqHrL7X4aVO2Ms72XRfZsq40h1e6L9A== Received: from CH2PR11MB4342.namprd11.prod.outlook.com (2603:10b6:610:3b::19) by PH7PR11MB6859.namprd11.prod.outlook.com (2603:10b6:510:1ef::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.39; Mon, 12 Feb 2024 04:10:44 +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; Mon, 12 Feb 2024 04:10:44 +0000 Date: Mon, 12 Feb 2024 12:10:38 +0800 From: "Jan Kratochvil (Azul)" To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, containers@lists.osdl.org, Waiman Long Subject: [PATCH v2] Port hierarchical_{memory,swap}_limit cgroup1->cgroup2 Message-ID: Content-Disposition: inline User-Agent: Mutt/2.2.12 (2023-09-09) X-ClientProxiedBy: VI1PR10CA0102.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:28::31) To CH2PR11MB4342.namprd11.prod.outlook.com (2603:10b6:610:3b::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR11MB4342:EE_|PH7PR11MB6859:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ca32c8c-f966-483b-2ab5-08dc2b809534 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: kc6ZF9NuOB5szM0OzwTB3mWbd/t9/H9doYRLWLbKIs7O5x7Kfez+o0FSJC//ATpzRJLgoj3H0Dpf1d7TNkk59XS0Q2aHDxsfg+61akMAaoLxL48bh4k080Z8lHYvDsgiTE8b/hJFozlXEZJHyYp9TFXYvJ/esrBZjL0jwEVN2HtuRO2CjrIvhZT2KD9vJ9i2X38syJ4FzulcirBqMw6KB7kuJQo0s7hUIQ3dLJxIgVVM2U8iY0DK1fv0WrnEzIVLHm9fDxDTKJjDGYfXvZzOr+N88gzURkLZrdM5TsighSHDwiLAsKhzWflzivM8aYxVDPQfk21HEUa21+YfwtyUQaUCG15lQjm+WveyR71DBS6Rxp12sB4GO0ePZ0aAnrl+IFAEGVBTZo+MG6ZIRFVZk6nC3gViKlX8A2pwaFwjvGf47a4O4DqFFA+CV+oMJkuvS6AxKJF+TDxAXimDxokk5FkoO1nc+3NR1m3e9aV/Q5/8TUIxZeGZ8G6XrsDq+WesQhi4iinq5bSkYIY5FQyqNRTLbrRREkh7c3aAskTUEOc= 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)(396003)(376002)(136003)(366004)(39840400004)(346002)(451199024)(1800799012)(64100799003)(186009)(2906002)(8676002)(8936002)(5660300002)(38100700002)(83380400001)(86362001)(6506007)(66946007)(66476007)(6916009)(6666004)(66556008)(316002)(6486002)(478600001)(9686003)(6512007)(966005)(41300700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S0NPgBbkTK4CLtXIZZPaqlk9IhE5++Q0YCmtGlM7iIuOAuIIRniMIPyuvORaiyCdUV2I341rEVWpWELw9vB8MkNfaC2pBDfTUcW17NmMcnlkE2O4k+RlmcOxaSKk4nslfcFc/W2/Z5cZxrErbR93xYTLW80EBJJ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R+qwbDG5/0xyNF0wCKHsJA9Rq3HfsYiMiqjoaAUWvfxO2yrWLfIKZiTCrV2o9rRWNfDcw8JoKiBgTc+vMeq2KDIWsjV5HReFdu86q20ixmoBrHZ2rWbRFTx2WRvywSr0+jNFwiOryuG5Q/ccQsvsiLtw1qCSpJSS9p/IvecYsfZHO5l/urehNWMXMRMUdj8/L+WSF7YaStCcTfLKb3br9EM0LkeSmLKqcnznY9IL722fW0IArXJmHTnEOP4l9fD3utAO58LE1/n1KGq+MtilqxP3RUGo+8QBwmcfim5c10FmirzWuoh+EaMTxFVs59ChvvsfJCxMbCb3umFb8ti1nWYzm0y7wCIOzWs8bXztpI0BzAA== X-OriginatorOrg: azul.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ca32c8c-f966-483b-2ab5-08dc2b809534 X-MS-Exchange-CrossTenant-AuthSource: CH2PR11MB4342.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2024 04:10:44.1288 (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: y6Iid77jxILCwwFEg+YWqNg4e3b5Ev/fvYhk6NwEzML0wLGux5970HdMuTV6+uY6G9v7jHZ9SUzdfhvUzTDhKw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB6859 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 87626180005 X-Stat-Signature: kd8jwsa3ywiiqbdd4m83e61qucn9psmd X-Rspam-User: X-HE-Tag: 1707711051-343857 X-HE-Meta: U2FsdGVkX19Z3AwO/hC4xywgKlw19yVurj4INjxBtwwCZCbevDOUzVksJINJxVWnZjf0M6p8VIS3Uydut7omDQxsj4IHR1D4hBWmQFSY3BOiEILm8GHWECr1mJ/i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neWUAn89ob41QXMQUP2A71+lAnc+T75HFmmKwcocjnaGLY6E3ha131GJctCtNT 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) already 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, this is just a copy-paste of the cgroup1 code while changing s/memsw/swap/ as that is what cgroup1 vs. cgroup2 tracks. I have added it to the end of "memory.stat" to prevent possible compatibility problems with existing code parsing that file. Jan Kratochvil Signed-off-by: Jan Kratochvil (Azul) mm/memcontrol.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 46d8d0211..2631dd810 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1636,6 +1636,8 @@ static inline unsigned long memcg_page_state_local_output( static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) { int i; + unsigned long memory, swap; + struct mem_cgroup *mi; /* * Provide statistics on the state of the memory subsystem as @@ -1682,6 +1684,17 @@ static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) memcg_events(memcg, memcg_vm_event_stat[i])); } + /* Hierarchical information */ + memory = swap = PAGE_COUNTER_MAX; + for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) { + memory = min(memory, READ_ONCE(mi->memory.max)); + swap = min(swap, READ_ONCE(mi->swap.max)); + } + seq_buf_printf(s, "hierarchical_memory_limit %llu\n", + (u64)memory * PAGE_SIZE); + seq_buf_printf(s, "hierarchical_swap_limit %llu\n", + (u64)swap * PAGE_SIZE); + /* The above should easily fit into one page */ WARN_ON_ONCE(seq_buf_has_overflowed(s)); }