lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <wzanjpb5fb3cff6jaissuzx3yxghgd5n4l4ekgpltytbdb6new@6v2uhp3oka5t>
Date: Mon, 12 Jan 2026 16:29:51 -0800
From: Shakeel Butt <shakeel.butt@...ux.dev>
To: Jianyue Wu <wujianyue000@...il.com>
Cc: linux-mm@...ck.org, cgroups@...r.kernel.org, hannes@...xchg.org, 
	mhocko@...nel.org, roman.gushchin@...ux.dev, muchun.song@...ux.dev, 
	akpm@...ux-foundation.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] mm: optimize stat output for 11% sys time reduce

On Sat, Jan 10, 2026 at 12:22:49PM +0800, Jianyue Wu wrote:
> From: Jianyue Wu <wujianyue000@...il.com>
> 
> Replace seq_printf/seq_buf_printf with lightweight helpers to avoid
> printf parsing in memcg stats output.
> 
> Key changes:
> - Add memcg_seq_put_name_val() for seq_file "name value\n" formatting
> - Add memcg_seq_buf_put_name_val() for seq_buf "name value\n" formatting
> - Update __memory_events_show(), swap_events_show(),
>   memory_stat_format(), memory_numa_stat_show(), and related helpers
> - Introduce local variables to improve readability and reduce line length
> 
> Performance:
> - 1M reads of memory.stat+memory.numa_stat
> - Before: real 0m9.663s, user 0m4.840s, sys 0m4.823s
> - After:  real 0m9.051s, user 0m4.775s, sys 0m4.275s (~11.4% sys drop)
> 
> Tests:
> - Script:
>   for ((i=1; i<=1000000; i++)); do
>       : > /dev/null < /sys/fs/cgroup/memory.stat
>       : > /dev/null < /sys/fs/cgroup/memory.numa_stat
>   done
> 
> Signed-off-by: Jianyue Wu <wujianyue000@...il.com>

With a nit below, you can add:

Acked-by: Shakeel Butt <shakeel.butt@...ux.dev>

>  
> +/* Max 2^64 - 1 = 18446744073709551615 (20 digits) */
> +#define MEMCG_DEC_U64_MAX_LEN 20
> +
> +static inline void memcg_seq_put_name_val(struct seq_file *m, const char *name,
> +					  u64 val)
> +{
> +	seq_puts(m, name);
> +	/* need a space between name and value */
> +	seq_put_decimal_ull(m, " ", val);
> +	seq_putc(m, '\n');
> +}
> +
> +static inline void memcg_seq_buf_put_name_val(struct seq_buf *s,
> +					      const char *name, u64 val)
> +{
> +	char num_buf[MEMCG_DEC_U64_MAX_LEN];
> +	int num_len;
> +
> +	num_len = num_to_str(num_buf, sizeof(num_buf), val, 0);
> +	if (num_len <= 0)
> +		return;
> +
> +	if (seq_buf_puts(s, name))
> +		return;
> +	if (seq_buf_putc(s, ' '))
> +		return;
> +	if (seq_buf_putmem(s, num_buf, num_len))
> +		return;
> +	seq_buf_putc(s, '\n');
> +}

Move the above functions to memcontrol.c and add documentation for them.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ