From patchwork Mon Oct 21 13:00:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13844115 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 2659ED15D89 for ; Mon, 21 Oct 2024 13:00:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83E576B0083; Mon, 21 Oct 2024 09:00:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7EE7E6B0088; Mon, 21 Oct 2024 09:00:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DD966B0089; Mon, 21 Oct 2024 09:00:40 -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 507AB6B0083 for ; Mon, 21 Oct 2024 09:00:40 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 582904194A for ; Mon, 21 Oct 2024 13:00:31 +0000 (UTC) X-FDA: 82697618178.21.FD91B12 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf26.hostedemail.com (Postfix) with ESMTP id DE25B140026 for ; Mon, 21 Oct 2024 13:00:26 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf26.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729515489; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=CHNWaq+3ap265h5FKkB//TFiSM0DsG6B+TY5sw19V5E=; b=NcNmmXkJV+2aP58iytxkKlxkHNeoget9YNE92u2lNH6fiQf4twKo0TX6xmS8bJY9CVOkTs PUy+7mYByGtAnSu0tHTVIDoT72OR+1TEwV24Pt/iAbO9hWdb31SsFpjvVC8Go08oDziQlV h31MrqyQOfYaA2lB3/XyrQ43bqfAXQI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729515489; a=rsa-sha256; cv=none; b=ipfGV2AQe4nhT06yjPhgpd4ovPF5OA11sCK0nDDOHoyiZE3JzO3dvS94IaNWmHE1KsWD8O dO8MQ6oF+EesmP11L3bUYecKiP+jMsN97FxiotwhyMqmbDVSPub4lamj3pAg1qaSDM/chu IAjkJ/HPO2+YhExddGp5UB4zKlsgfrI= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf26.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1BF0DDA7; Mon, 21 Oct 2024 06:01:06 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C20A53F73B; Mon, 21 Oct 2024 06:00:34 -0700 (PDT) From: Ryan Roberts To: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton Cc: Ryan Roberts , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Hocko Subject: [PATCH v2] mm/memcontrol: Fix seq_buf size to save memory when PAGE_SIZE is large Date: Mon, 21 Oct 2024 14:00:26 +0100 Message-ID: <20241021130027.3615969-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: DE25B140026 X-Stat-Signature: 8trq57rzzqqjojf9e983egiu7c8d8tqh X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729515626-660657 X-HE-Meta: U2FsdGVkX18MNgquCW7EX5N2r2f/8ZU8PJB1lWUvchgkV0aL4HGbqnIHYm5Ge/W/5qrqApgNJZmDL+xSnt9x/vs1YsfLejwo1MO33B8Tsu6V8NP3elQ06Wh61Ot/F5Ubk3GSbavgTe5Us1Us4mH9u1caJmkIsNMUKUThsOaUKrx0IYI3I7lTnH/3Pa0eYhRI7sPnv9YX1VBMMRDUObmNDPTIMwWXTR2ta8h8801UHVQIxuFuFy9044GOLnamKfx5heylTzfYh1dmFQE0y3DMdT9mT0JoifhAviD99Nzi2bpSv3+hRAFkpY9EG2g12P8QFb8uMNEObbFiOJB8pS3wY6HeAbptAEAWH2n/v4HVtjxInPafC/fAGaJpbyTcpSyz+0Hld23OU4DPkkIBbYp5JUPAf8NDtZ01H3kpbFiNWc01thGMSioE1VL4a2XMbYmL/suFVLxvF5gb+CZnXVcKWXGGvB0ljq067TgF+1EU/hHFOyUw9O13A+WqY+O+l44ddI2WVmIwTdKTwdwNzTpiAW/qhYsOO3inltGhIwPg0TmmIthQkmvI8zpPNzSHXEOIDR1LST3xKyA+DTfogIO1w0CjKARSPLGc2X/i3KibkFgsPreLflOESdYcKVEK5Ir1KsVbLN1md5lAOBgzxPbHvi+imWaDtJAjzDb3Pw1TsoXHL7gmkw43HlG1ipeRG2pAUfQVduR/y/SThV9RlCwdklxKeuonRuNBWKZGBXA7ZUikNm4zVEQrz79jdAaXHCLRzPYdT/DLpINh2YS8BhgZ+pJky/vpOzsJyBK7XwqSpHA8Cw4mbGkC8YlRjizivGNjq7Uv+p7VxMZ4W+Usz7uuOGFVvXLPr9tdalz2RC8jVCvLU53Af49fbI3rumJJ8dT6p/y1LJeFPieE5FxzcyuJ+kKYNDbYwtWLZNz2SV0PM/04fUlPtQIYTEvFlCNsa394k8N79/nWLJ1oo5fcULI cKbQFBAZ f1XHI/ZrY65Y6T9lJgvhtumqxHiSVMBjUv3u0xIUflW43HMec5K18TmaKlnglL5m0MHJPRIUo2Jhl+3t1PypPSf0GhXisemxlNCsyTwp7JpE8v8mp3G+XBzMtXMSRG/uFZr947hCYk20qqokQAdrA/JxD6lARnipGJ2Wkm9j9x+a/eYTsGGzuIUUcBock53q/ccOkgNj5lCqg9wPBLR+y6QIQNpeNFm5uOhWTcFnSMBkkwjRdO9AHc8JBehFczkAAON2R+bxxX90bCV4vLo9mAmr4zd0QvbHMK80Q36su1BXk5YTlefYiZ8HzLM8FCCd6Z+0d 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: Previously the seq_buf used for accumulating the memory.stat output was sized at PAGE_SIZE. But the amount of output is invariant to PAGE_SIZE; If 4K is enough on a 4K page system, then it should also be enough on a 64K page system, so we can save 60K on the static buffer used in mem_cgroup_print_oom_meminfo(). Let's make it so. This also has the beneficial side effect of removing a place in the code that assumed PAGE_SIZE is a compile-time constant. So this helps our quest towards supporting boot-time page size selection. Signed-off-by: Ryan Roberts Acked-by: Johannes Weiner Acked-by: Shakeel Butt Acked-by: Michal Hocko Acked-by: Roman Gushchin Acked-by: Muchun Song --- mm/memcontrol.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) -- 2.43.0 diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 17af08367c68..5c3a8629ef3e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -118,6 +118,7 @@ struct mem_cgroup *vmpressure_to_memcg(struct vmpressure *vmpr) return container_of(vmpr, struct mem_cgroup, vmpressure); } +#define SEQ_BUF_SIZE SZ_4K #define CURRENT_OBJCG_UPDATE_BIT 0 #define CURRENT_OBJCG_UPDATE_FLAG (1UL << CURRENT_OBJCG_UPDATE_BIT) @@ -1527,7 +1528,7 @@ void mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct * void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) { /* Use static buffer, for the caller is holding oom_lock. */ - static char buf[PAGE_SIZE]; + static char buf[SEQ_BUF_SIZE]; struct seq_buf s; lockdep_assert_held(&oom_lock); @@ -1553,7 +1554,7 @@ void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) pr_info("Memory cgroup stats for "); pr_cont_cgroup_path(memcg->css.cgroup); pr_cont(":"); - seq_buf_init(&s, buf, sizeof(buf)); + seq_buf_init(&s, buf, SEQ_BUF_SIZE); memory_stat_format(memcg, &s); seq_buf_do_printk(&s, KERN_INFO); } @@ -4194,12 +4195,12 @@ static int memory_events_local_show(struct seq_file *m, void *v) int memory_stat_show(struct seq_file *m, void *v) { struct mem_cgroup *memcg = mem_cgroup_from_seq(m); - char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); + char *buf = kmalloc(SEQ_BUF_SIZE, GFP_KERNEL); struct seq_buf s; if (!buf) return -ENOMEM; - seq_buf_init(&s, buf, PAGE_SIZE); + seq_buf_init(&s, buf, SEQ_BUF_SIZE); memory_stat_format(memcg, &s); seq_puts(m, buf); kfree(buf);