Re: [PATCH] alloc_tag: avoid mem alloc and iter reset when reading allocinfo

Kent Overstreet
2025-05-08T16:34:39Z

On Fri, May 09, 2025 at 12:24:56AM +0800, David Wang wrote:
> At 2025-05-08 21:33:50, "Kent Overstreet" <kent.overstreet@linux.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().