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, From patchwork Thu Jun 6 15:22:31 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: 13688671 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 A9780C27C54 for ; Thu, 6 Jun 2024 15:22:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 732BB6B00A2; Thu, 6 Jun 2024 11:22:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B9826B00A3; Thu, 6 Jun 2024 11:22:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5828E6B00A4; Thu, 6 Jun 2024 11:22:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1DF2E6B00A2 for ; Thu, 6 Jun 2024 11:22:47 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BC9FE160A56 for ; Thu, 6 Jun 2024 15:22:46 +0000 (UTC) X-FDA: 82200831132.24.241A5B1 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf10.hostedemail.com (Postfix) with ESMTP id 900A8C0028 for ; Thu, 6 Jun 2024 15:22:43 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=PYVS50ct; dkim=pass header.d=suse.com header.s=susede1 header.b=Gu9CsrXI; spf=pass (imf10.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=Z0Kc8Bd03I/KnkB6dRr+g2P2M/m8COOx/mJJqEqwMus=; b=fnwrCYmRt8soh8N2RXWEUCpK62g4o44XKI1sd23/43OJhW5lDNZkwt22cjZ2mqhz301kf0 T7Qsn8OjC0W3lcBKm51GlCvkHm25EDhC1df4LvJEbPCUhuqxAq9E8sy0qI7g39ut6KKptN BR6IsxTeJNi5czMApTg9glNscVb156o= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=PYVS50ct; dkim=pass header.d=suse.com header.s=susede1 header.b=Gu9CsrXI; spf=pass (imf10.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=6LWYUvlSFQwPlPoxLRPX8vr3xe61DRFmkW/XLR4Z+XCfhQS/hoie4+r9wvfN31bcaWUNjd H/CkOpf5TN8mlq0OsKm0ScN80wsW1SgrV3bk44jneGbxvPTVluKgorMsTB7OiN7YAUeqcW VlD1E2JoP2W31vMUbJigEJV/SlQ6m4g= 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 E56F51F911; 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=Z0Kc8Bd03I/KnkB6dRr+g2P2M/m8COOx/mJJqEqwMus=; b=PYVS50ct27fZ1kFviVdI2+iaasghsghfsADIf6ykfOUJo1I3S/eUVwK+sM8FFPr9GlUr05 OgXekOse/MmOmiV61qCtZkX/YYsGJKIQwuu65vR4kUPsvYykLkdDY4IFv6YnGnxAo6tdRc gzjNcNb+jiv9DLM/1aNmU6nR2j27N0k= 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=Z0Kc8Bd03I/KnkB6dRr+g2P2M/m8COOx/mJJqEqwMus=; b=Gu9CsrXIVDQN/4p87XZxcHzZVpgZZghmoeVrajfUjsncBrYYZALOXtavU4d69nLIyeaEw7 1upqOVOe6ahh0CGtZnKoUBO8i8trQiD0ZmjfhwrDgquqBEHYWDaTkRdP4eWmWJ7GuOaSRB Dg24BMzTwpRJGjEj4ckfD2sEe2RFLUk= 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 D397D13A97; 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 AP2DM0HUYWbGbwAAD6G6ig (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 2/3] memcg: Add memory.swap.max.effective like hierarchical_memsw_limit Date: Thu, 6 Jun 2024 17:22:31 +0200 Message-ID: <20240606152232.20253-3-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-Stat-Signature: 18kg8t154h11ytr4tbc9mfrm6w1fg5gi X-Rspamd-Queue-Id: 900A8C0028 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1717687363-706530 X-HE-Meta: U2FsdGVkX1/dR/VC6ZPOnCWSXF92O1OfVmDPZk9iwDkzsw4amP/RV9f1AXCc7fvZ0fkmYdnCZhrYiGV4G4wXiDRO0TbG+ZwAH9qRncYZBT5I+umXyRwYfTIg03HXXHeiAcOhkBEbc0S2iZK+Kfjihx2XvJPr8C1Z6n9F25rx5l0tiy7eGTmfSoq8vZXmlXkrFGqOR11IiMEQLtY0k61ue8lq21gNBNm0H18hY7iaNTKWAhYzAWpjCiUksVYycllN/hPbzQ7iwg4SUlSoSIV+g30K3Qls00S5UZALWxgpy6kkNHPls+bPl/xW1RVzResH+QxXWyxwHO7yHWEQZgVsJ6jqWWbel0kvmcwcNY5pppz4MWED3u0KfwQxwGmwFhvprvEBuvuAC7ES9VJucZ3lm7MknwtMGf0PQ2hVlRlgH9zp/nx1NrbS5rd1e5bH6bxwcNpJkpOljVxS/JIbMhTfqq4sc77vw3HmVwSnx6P873Xe+TrWrcx7Z5uWrcA7KUq8rSh7W10wa0dZB5/FNWyCmjAdM6wHjkWE+hPu6XA4PK/XSdjDLwCIwICXv+1c3dTV/YFmy6KVqi4LIg9komFpPYtol9ret4CjgahhVJf9yRdR9S6bv0DNoWxbP6qalvkckagg6MfsgZI/alN4Q4xVLstnvj7zfzASHRq5IqT1nmINmZDQlT+g6IbcE+5TmII61x8E40847/sDrMY0Tkh5VcLBgTYWNzIWtXdSl9TZptHGnEzveJKnj99DPYeim0PqtTi0yl13GVqmnNbjeaUEo8B+8zWVWHhd6gb4xlTgt0ZUy21nyBig4m+XZmBctSCEOx86OfDjXErM/xI8kwCISvRumBYXZsekrhJTep0YeC7p92tQ7BN6okdNqnTehrEkhFx8pnASWcSN/zYtI0ahL3YzFGysGQdKyhDDiYPezx90Ki25+R2FnbfilET++XAeVbiEVLedhr0IlMzw5eT dZSiUcp0 OOBt1cSjBBd3TbFk5S07KKXvs0wKqdglnJWSKwQQnRGd2I8UTPuFT0iLs3GD/ZVwik5L4bAETVhjxdki1bWyWWGuXEqOWqZ7btrWgP93k/XcFmLciCmJEhszbdY9Czoa/8FPy/Q3BkjKFVFdIglxD+ajC46yxEikrWKM9MZGte7U9nse6uyrv+YeNdvjyOCR7FRZj00n+XUuyh2WQcA0x+8K1PgLZJz4WbTKQgteR3DheBsxAePurTgR+jgQp7k5We5GYIJqmd3EZ40uegH2FgWjG5G/Bt/pDfSVGT5hAncpfKOCs6fbLMcvp8p3KdCLpj5WF6TT7ZP3uQv8upZLO1E7mgHXjyW3om+k4yirjHx96qT41hwkM46EoMBwOav3ihX9sDxkN78891ZCN16xFtpZ5vy5s9YwozPrnsY/LWeBrfA6f+cuh6vRMaw== 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: cgroup v1 used memory.stat:hierarchical_memsw_limit to report the value of effecitve memsw limit. cgroup v2 has no combined charing but swap.max limit, add a new memcg attribute file that contains the effective value of memory limit for given cgroup (following cpuset.cpus.effective pattern) for cases when whole hierarchy cannot be traversed up due to cgroupns visibility. Signed-off-by: Jan Kratochvil (Azul) [ mkoutny: rewrite commit message, only memory.swap.max change] Signed-off-by: Michal Koutný --- mm/memcontrol.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 86bcec84fe7b..a889385f6033 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -8279,6 +8279,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); @@ -8311,6 +8324,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, From patchwork Thu Jun 6 15:22:32 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: 13688670 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 1966BC25B75 for ; Thu, 6 Jun 2024 15:22:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 278926B00A0; Thu, 6 Jun 2024 11:22:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2274E6B00A3; Thu, 6 Jun 2024 11:22:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED10D6B00A4; Thu, 6 Jun 2024 11:22:46 -0400 (EDT) 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 C0E186B00A2 for ; Thu, 6 Jun 2024 11:22:46 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3B7031204D3 for ; Thu, 6 Jun 2024 15:22:46 +0000 (UTC) X-FDA: 82200831132.28.78B3407 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf04.hostedemail.com (Postfix) with ESMTP id 0D98540011 for ; Thu, 6 Jun 2024 15:22:43 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=HEBOZkbD; dkim=pass header.d=suse.com header.s=susede1 header.b=HEBOZkbD; spf=pass (imf04.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=3UUD9NkDVTFG0Gsd/Bh0u7L1DDROh8yutruXmygdMJXmGlZsVihF0j+6wJKX8ML+PVaTkE TBRy3IpQ8ewm+xakiOQhBAT0F7Ib6IVDppxhdt9KySu3g8YHnNCyD2s6wy6uvO1UJhXCRg K9yZS6lkQLh6314JvchnRTVPNZPqC5E= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=HEBOZkbD; dkim=pass header.d=suse.com header.s=susede1 header.b=HEBOZkbD; spf=pass (imf04.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=ETytyPpyO/ne7SCX3Wq9PF58dUOe/pCqU+w54NHSJZY=; b=lP6aAQ6ufWVdgLh7oDRVuEAN26Sr4UF6kZ1WKoteOs02NhIiti1H6B8SHOutd8q3oxF+Ig qukVLu09l+YD0z7VJhvFMd3zpoAEHxmDbyM58YGlc09Q/Bh0p8RglaMfSdSrZ+Hefn3VVA N4qcQDdMGb/IOZ5dY/ofWviVRyB/g/g= 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 F2EBA1FB3A; 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=ETytyPpyO/ne7SCX3Wq9PF58dUOe/pCqU+w54NHSJZY=; b=HEBOZkbDPKcmXI4zASPz2S6DI/nP7AL3FnDRJbLlPWsYAT1l+8WVlXcFRqoCM2DMBtHA0t Sp99OGabVzlFxnuI7rqsGABXYYKdja4X+tmblQnS5s4pVn/QkXrgi3C6Ojr/08g83xt2yX T8eJREiDDsTpL6uYmDn2b3a1Qg5TKNo= 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=ETytyPpyO/ne7SCX3Wq9PF58dUOe/pCqU+w54NHSJZY=; b=HEBOZkbDPKcmXI4zASPz2S6DI/nP7AL3FnDRJbLlPWsYAT1l+8WVlXcFRqoCM2DMBtHA0t Sp99OGabVzlFxnuI7rqsGABXYYKdja4X+tmblQnS5s4pVn/QkXrgi3C6Ojr/08g83xt2yX T8eJREiDDsTpL6uYmDn2b3a1Qg5TKNo= 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 E01E313A9E; 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 IGGYNkHUYWbGbwAAD6G6ig (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 3/3] memcg: Notify on memory.max.effective changes Date: Thu, 6 Jun 2024 17:22:32 +0200 Message-ID: <20240606152232.20253-4-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-Queue-Id: 0D98540011 X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: uzso18opd4p1y837obqokscoij9httfa X-HE-Tag: 1717687363-847504 X-HE-Meta: U2FsdGVkX1991Lpl+aHBXRiXkx8ptG3E2uK1vbD1WYfbnu14fwlc+A/xgB4oUHn38aJOifWdTldJ8h/N0yBrXTe3NjZSGHW+iNYEd9vnRxwx3iyYDHRx7X2kz90vlJ4L4nXgOkoDADE6T1gV1cNX4GWJCTIRCT1rx6YYFB+wkfzAMij3ENiqe7Gl8jkCSwFNSOg3V1Uo1JBysSpnbx09oZkW/kBr2jPrOaMY+jQnZsgIr72xB9Hq4IPyumC1AC4gzxW/uoRiASjGhAPAnSE4PEV0Dcf8GVWXed+Ijd9wBwU3I1M6u491aQtkfpMVpoemNI1mvR6YprF4BlufZoI01Pnrq2j+AqYcdMBvr3V5C72TlX+6ZLyYVlNY64v8vGdxbiQznNjr+Y3ABzu3luxLjc6xvqKipO4fvQ2T8nKsYbZ7R/13TBCGNYPj5GhxLSUyiVNvMcUqiAnE8/HtZHLseR5ss/i/uBvrX/gykEu/1V3MV2eEXqUQcSCsUoDuweuuPJnES4eS07gL/vBNTNG6tbp6j3X7vsWUrok2NcpzNfp6XhiVV4wPilWypXqtl8S6K7Vm9V5HfMJKd2ChrXdRd7RBLyjv4tHX7tRoVh/4D0jnPSZunksLDbqMLrWvQpNRuiPsK5LVDu5GeJjngPt9DVJ9H4j3NWsDWAyAF22PKno6z9Eef+W6Ayxy5zVh61vCHIx8C17sXTDZk4TiRKBK2sPsNFmEaRx0RURO9WH2Dhgc7HoMPr+rodiadUC/RB2S26QdpsK5Slh7BXn5IFo50vPkUjRcbBvz4+xbTJXIZ1K4HRe3haQWtFhg677bSLj7LwAz76ufg18hsaOCnoHszY2YIIqQdIV8mIkG6i0Fc344ScZ20ucxOMqXauP8nfn3+XZzmvzoD41IeFH3RaB2geAX38aiVtEMx9Be5rTht1jPULA/K7dFv8NLxB8KRoAq4sggbk2J1VgcgbWNJVy 6E3PNgQX o1ChLnKrQr0k/t/2AMuFVGe55+SKhKGGtt/C/KI2aVkt8qtNdCvH0hVOHPfE/Q9zxWZJwa07xHKfnsCf3OTnDzZN4Izj8zKT0jH0DLLWbhe+j8d4qDAMe2GAnlb6nZA5Yrqy2gS1+H0Lx6XRC3PgR5JyO3MJV8Khu5Wr6G7Xdufsu9L3gU5T/mVWsf+IP4rmdwXnqZ1nX1z7+g3bmXGbm01AAvRFcMhdYNKiV3kxRO4geq8mAfOHUrm2VyGQejK/VBvOOae7bGfSfzLO+soeRe+rWJ0FEm7e+Pep60efvibhdfHqRsUbjttET9YE/ZchkcRi7k8mEptLce4g= 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: When users are interested in cgroup's effective limit, they typically respond to the value somehow and therefore they should be notified when the value changes. Use the standard menchanism of triggering a modification of respective cgroup file. Signed-off-by: Michal Koutný --- include/linux/memcontrol.h | 2 ++ mm/memcontrol.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 030d34e9d117..79ecbbd87c4c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -232,6 +232,8 @@ struct mem_cgroup { /* memory.events and memory.events.local */ struct cgroup_file events_file; struct cgroup_file events_local_file; + /* memory.max.effective */ + struct cgroup_file mem_max_file; /* handle for "memory.swap.events" */ struct cgroup_file swap_events_file; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a889385f6033..72c8e4693506 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7022,6 +7022,7 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); + struct mem_cgroup *iter; unsigned int nr_reclaims = MAX_RECLAIM_RETRIES; bool drained = false; unsigned long max; @@ -7061,6 +7062,14 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, break; } + /* + * Notification about limit tightening, not about coming OOMs, so it + * can be after reclaim. + */ + for_each_mem_cgroup_tree(iter, memcg) { + cgroup_file_notify(&iter->mem_max_file); + } + memcg_wb_domain_size_changed(memcg); return nbytes; } @@ -7275,6 +7284,7 @@ static struct cftype memory_files[] = { { .name = "max.effective", .flags = CFTYPE_NOT_ON_ROOT, + .file_offset = offsetof(struct mem_cgroup, mem_max_file), .seq_show = memory_max_effective_show, }, {