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, }, {