From patchwork Thu Jun 6 15:22:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michal_Koutn=C3=BD?= X-Patchwork-Id: 13688669 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 29A66C27C54 for ; Thu, 6 Jun 2024 15:22:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE9C76B009F; Thu, 6 Jun 2024 11:22:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D71556B00A0; Thu, 6 Jun 2024 11:22:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C428C6B00A3; Thu, 6 Jun 2024 11:22:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A76C66B009F for ; Thu, 6 Jun 2024 11:22:46 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EE7611216B4 for ; Thu, 6 Jun 2024 15:22:45 +0000 (UTC) X-FDA: 82200831090.27.B93A12D Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf28.hostedemail.com (Postfix) with ESMTP id B614BC001A for ; Thu, 6 Jun 2024 15:22:43 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=BQxB4xYn; dkim=pass header.d=suse.com header.s=susede1 header.b=aVlpbnyK; spf=pass (imf28.hostedemail.com: domain of mkoutny@suse.com designates 195.135.223.131 as permitted sender) smtp.mailfrom=mkoutny@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717687364; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j5CJatTeD21yKGIUJTDlFh+ocnDWoH1DBubszi9zcsQ=; b=ydl9EQz2QtlTGjaIcxk+e27Tg5ogjeNPba6ZnoPpZah0ZPup65mb9rtKKBiQ2NuahtE4tP tonRDcGVzeyWWkRfIlZdKD4nldCK4Tp0149QdZC4mupuruXTAJ56wv7s1D/zXYENr/DBGX nFO3irEPebUZQU88govLGPb3OBMLoRU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=BQxB4xYn; dkim=pass header.d=suse.com header.s=susede1 header.b=aVlpbnyK; spf=pass (imf28.hostedemail.com: domain of mkoutny@suse.com designates 195.135.223.131 as permitted sender) smtp.mailfrom=mkoutny@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717687364; a=rsa-sha256; cv=none; b=jlBNzbUsMrqI0R7Uj4fLnk//yA+reJsWhl+7ns8uZ5njNzuIyCkapMTJ8KD5L7DqqfTDuO gJ0TGDqRWfTO2NpSFA9/sMoX8E7VaA+dWxT+Qe0IlF/QUwwluew5QSKimtM3sKQipe+fbc 87KOOZZa/MBMIOkdkX/fxmmNFaYIBgE= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DA8721F8D7; Thu, 6 Jun 2024 15:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1717687362; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j5CJatTeD21yKGIUJTDlFh+ocnDWoH1DBubszi9zcsQ=; b=BQxB4xYncgHBg7CFyGBNxGNf3U0Nzbm4D1ja0Yd4OeyVvGC1XxjEkjIXrlxwOmCv7vrLmd te4p0pHWGsX5ginj03huzP7ibP2aBsFSjSqlrt/yQ2kvvseuvBxUHKvCB/R16LUrRaiL7/ VdjYdKiiEkcZWUID1GbtY4N5+QWtvS8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1717687361; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j5CJatTeD21yKGIUJTDlFh+ocnDWoH1DBubszi9zcsQ=; b=aVlpbnyKESZ9aMiNPzz0Sit5DrguUMJbMFg7aNVKokIlBxORZABlAGMMMA4RB35v3aKsJY hTBDUBw0TPK4ZU0qWIyrXw5mSyJ3I+PX4c8+oTXyuXG/6kLzU4bp64Bkrhk5tsooahiEF5 hBeMO7elzrTLaX//Rh5CPWTEeCec934= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C4FD513A96; Thu, 6 Jun 2024 15:22:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uM74L0HUYWbGbwAAD6G6ig (envelope-from ); Thu, 06 Jun 2024 15:22:41 +0000 From: =?utf-8?q?Michal_Koutn=C3=BD?= To: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , "Jan Kratochvil (Azul)" Subject: [RFC PATCH v5 1/3] memcg: Add memory.max.effective attribute Date: Thu, 6 Jun 2024 17:22:30 +0200 Message-ID: <20240606152232.20253-2-mkoutny@suse.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240606152232.20253-1-mkoutny@suse.com> References: <20240606152232.20253-1-mkoutny@suse.com> MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B614BC001A X-Stat-Signature: zwoub6hmf4fnxybjxwgej4mbrywdt1o8 X-Rspam-User: X-HE-Tag: 1717687363-140863 X-HE-Meta: U2FsdGVkX181QV1dv08dNspvDHLWLjFf8z4lSFatQDJRNfkO4cNDBFwAl6MMVbFEHXBdPCXJZnSV74uIT6xc1EcjNKfLmX+ChfVz4MI9cxP/er1H1/vf3skLWZFYpcqZ2mINu6DH9vqDIXcd7oqULuoF8RqreRy4af+8hdcT+SYVBuuqP0SGc3MghfLYzpsbdAzDG/DdV2TuCua8qC6cllXn4qSRW1QFmlazZcz+PUst4FF4oMfDpvQsfv1cW6zvQlk1kj3doilJ2Y7wsUZGtZyR065vCzWBO88k1ob0t2ZW5zkMkkF8juUVzD791HGzYWA0v2ort3q2NLcfJNI9Jna0tvHWAKzrpp9wuyACism71c/tsMMNqAipDmt0QgCnmbFDBnw7H0dLpuTIOR8rWtVuaem7MXchHgBPh1oUPM2d/E2a3CjqlMJZ5xXGT4bKPXwyxyBlnt6Y9lIQ+uWIyq3y9SjVD9n5zbftka0tmjiFTQSLc0T8dWVatrIxTygk7q+DqJb5V4+2oj6scoK/N4j52CiahJ58znOjf1twOwdE8Y0SXd9A2NnPXvlpzq8jGg3AW+n5y1jBXIhMgkJn3rfsBlLOWp7jllnf8EvOHRPtDVqi9Vv4rmL3iyeEIzm4efz37cvnq+l/nKxX4WDX92jFd3iLzJ+R4uONrz1G67hkoqRrB5zzhaB0ox/BY/7w3c3M5zr8iwIddYeAFhx1dWYlYgoYqMfS9BXo7IZdOA9T/01yXbdeG4oKCMSeVoSPRTkcjhQiIKJr+8MM/q44rgVtBr0Uj9jPQyJMkjtqcrjEx71901/efP6kqwaWJ1eL0noE539INvomKCQ+w2NgK98rRivsmeHPQMSNnwe/ySdCrRq7jmGaB6YUbQq6ouT7xlLDoZ72bPn+7zg0fH1vDP1tzeKe0ioHQI9n7bRRxaKW0aVdmPtVcRPO5JQjnarFGpqlLW6kxhhBTT9cKvO ZwhhK9Y5 9RV4rcfYQ3p67vx1GdXiMlRiZkl56Wul9choWzMJrRUjrAXLR1t5jeHNCzhan4jUJGhpmyePaWfbZLmVXQe92goploY0lpDSpikFKNrHAidvgcMzFYhNpiI88k36g3Yr1bJc7CdjZ/LmSUuRMM8lpcv7sgOPP/oSbeOhxlK5w5QYzVaLYttegRud127nqmf84WPMONQyQ+mY4mv9qdNJZkZ4n1CgbM0UAiJsblOtSC6KXr4eEyYp/GMB8RS6JCTxTI9WudLedwbVO5K68Y2Mq96rCbLqt45FRSpPEPEGxQc3NL6dmHN5cWyFT/3WbQZm9zFdThl3R/Bfr4T7zCoh7zu29LUPGKlh6nlLuW10APo+4r0IdPOHLlS/KgM5Y/N4VAhyBAwiGFvWkHyk= 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: Some applications use memory cgroup limits to scale their own memory needs. Reading of the immediate membership cgroup's memory.max is not sufficient because of possible ancestral limits. The application could traverse upwards to figure out the tightest limit but this would not work in cgroup namespace where the view of cgroup hierarchy is incomplete and the limit may apply from outer world. (cgroup v1 used memory.stat:hierarchical_memory_limit to report the value but there's no such counterpart in cgroup v2 memory.stat.) Introduce a new memcg attribute file that contains the effective value of memory limit for given cgroup (following cpuset.cpus.effective pattern). Signed-off-by: Jan Kratochvil (Azul) [ mkoutny: rewrite commit message, split out memory.swap.max] Signed-off-by: Michal Koutný --- Documentation/admin-guide/cgroup-v2.rst | 6 ++++++ mm/memcontrol.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 8fbb0519d556..988f26264054 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1293,6 +1293,12 @@ PAGE_SIZE multiple when read back. Caller could retry them differently, return into userspace as -ENOMEM or silently ignore in cases like disk readahead. + memory.max.effective + A read-only file that provides effective value of cgroup's hard usage + limit. It incorporates limits of all ancestors, even those not visible + in cgroupns. The value change in this file generates a file modified + event. + memory.reclaim A write-only nested-keyed file which exists for all cgroups. diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7fad15b2290c..86bcec84fe7b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7065,6 +7065,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. @@ -7259,6 +7272,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,