Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/memcontrol: fix seq_buf size to save memory when PAGE_SIZE is large

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.

Link: https://lkml.kernel.org/r/20241021130027.3615969-1-ryan.roberts@arm.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Muchun Song <muchun.song@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ryan Roberts and committed by
Andrew Morton
8717734f 628e1b8c

+5 -4
+5 -4
mm/memcontrol.c
··· 118 118 return container_of(vmpr, struct mem_cgroup, vmpressure); 119 119 } 120 120 121 + #define SEQ_BUF_SIZE SZ_4K 121 122 #define CURRENT_OBJCG_UPDATE_BIT 0 122 123 #define CURRENT_OBJCG_UPDATE_FLAG (1UL << CURRENT_OBJCG_UPDATE_BIT) 123 124 ··· 1528 1527 void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) 1529 1528 { 1530 1529 /* Use static buffer, for the caller is holding oom_lock. */ 1531 - static char buf[PAGE_SIZE]; 1530 + static char buf[SEQ_BUF_SIZE]; 1532 1531 struct seq_buf s; 1533 1532 1534 1533 lockdep_assert_held(&oom_lock); ··· 1554 1553 pr_info("Memory cgroup stats for "); 1555 1554 pr_cont_cgroup_path(memcg->css.cgroup); 1556 1555 pr_cont(":"); 1557 - seq_buf_init(&s, buf, sizeof(buf)); 1556 + seq_buf_init(&s, buf, SEQ_BUF_SIZE); 1558 1557 memory_stat_format(memcg, &s); 1559 1558 seq_buf_do_printk(&s, KERN_INFO); 1560 1559 } ··· 4197 4196 int memory_stat_show(struct seq_file *m, void *v) 4198 4197 { 4199 4198 struct mem_cgroup *memcg = mem_cgroup_from_seq(m); 4200 - char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 4199 + char *buf = kmalloc(SEQ_BUF_SIZE, GFP_KERNEL); 4201 4200 struct seq_buf s; 4202 4201 4203 4202 if (!buf) 4204 4203 return -ENOMEM; 4205 - seq_buf_init(&s, buf, PAGE_SIZE); 4204 + seq_buf_init(&s, buf, SEQ_BUF_SIZE); 4206 4205 memory_stat_format(memcg, &s); 4207 4206 seq_puts(m, buf); 4208 4207 kfree(buf);