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] [thread-next>] [day] [month] [year] [list]
Message-ID: <64e0d38f.b791.196b0e73c9d.Coremail.00107082@163.com>
Date: Fri, 9 May 2025 01:17:46 +0800 (CST)
From: "David Wang" <00107082@....com>
To: "Kent Overstreet" <kent.overstreet@...ux.dev>
Cc: "Suren Baghdasaryan" <surenb@...gle.com>, akpm@...ux-foundation.org,
	linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] alloc_tag: avoid mem alloc and iter reset when reading
 allocinfo


The impact of accumulated iterator rewinding could be observed via:

sudo strace -T -e read cat /proc/allocinfo  > /dev/null

Tens of read should be observed and each read should become slower and slower.


 

At 2025-05-09 00:58:25, "David Wang" <00107082@....com> wrote:
>
>At 2025-05-09 00:34:27, "Kent Overstreet" <kent.overstreet@...ux.dev> wrote:
>>On Fri, May 09, 2025 at 12:24:56AM +0800, David Wang wrote:
>>> At 2025-05-08 21:33:50, "Kent Overstreet" <kent.overstreet@...ux.dev> wrote:
>>> >The first question is - does it matter? If the optimization is just for
>>> >/proc/allocinfo, who's reading it at a high enough rate that we care?
>>> >
>>> >If it's only being used interactively, it doesn't matter. If it's being
>>> >read at a high rate by some sort of profiling program, we'd want to skip
>>> >the text interface entirely and add an ioctl to read the data out in a
>>> >binary format.
>>> ...^_^, Actually, I have been running tools parsing /proc/allocinfo every 5 seconds
>>> ,and feeding data to a prometheus server for a quite long while...
>>> 5 seconds seems not that frequent, but I also have all other proc files to read, 
>>> I would like optimization for all the proc files......
>>> 
>>> Ioctl or other binary interfaces are indeed more efficient, but most are
>>> not well documented, while most proc files are self-documented. If proc files
>>> are efficient enough, I think I would stay with proc files even with a binary
>>> interface alternate tens of fold faster.
>>
>>This would be a perfect place for a binary interface, you just want to
>>return an array of
>>
>>struct allocated_by_ip {
>>	u64	ip;
>>	u64	bytes;
>>};
>
>
>
>>
>>Printing it in text form requires symbol table lookup, what you're
>>optimizing is noise compared to that and vsnprintf().
>
>Oh, no, this optimization is mostly achieved by avoiding iter rewinding, I think
>I talk about the extra memory allocation "too much"....
>These lines of code:
>-	while ((ct = codetag_next_ct(&priv->iter)) != NULL && node)
>-		node--;
>have accumulated way too much.
>Think it this way, advancing iterator n times takes 1%, reasonable noise
>compared to  symbol lookup and printf(). The problem is seq_file() would
>restart about 80 times to read out all content of /proc/allocinfo, accumulated
>to a total 40*n iterator advancement, hence 1% become 40*1%, noise become significant.
>
>My test result shows an improvement from 7ms to 4ms:
>
>Timings before:
>	$ time cat /proc/allocinfo  > /dev/null
>
>	real	0m0.007s
>	user	0m0.000s
>	sys	0m0.007s
>read-syscalls get slower and slower:
>	read(3, "allocinfo - version: 1.0\n#     <"..., 131072) = 4085 <0.000062>
>	...
>	read(3, "           0        0 drivers/gp"..., 131072) = 4046 <0.000135>
>	read(3, "           0        0 sound/core"..., 131072) = 4021 <0.000150>
>	...
>
>and with the change:
>	$ time cat /proc/allocinfo  > /dev/null
>
>	real	0m0.004s
>	user	0m0.000s
>	sys	0m0.003s
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ