From: "David Wang" <00107082@163.com>
To: "Kent Overstreet" <kent.overstreet@linux.dev>
Cc: "Suren Baghdasaryan" <surenb@google.com>,
akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] alloc_tag: avoid mem alloc and iter reset when reading allocinfo
Date: Fri, 9 May 2025 00:58:25 +0800 (CST) [thread overview]
Message-ID: <5294252d.b74a.196b0d583c6.Coremail.00107082@163.com> (raw)
In-Reply-To: <is4valhxssgmj7cjdlp2gfvyivhdflu75vzzbkjeiyb47wom55@yx5lfwsptamg>
At 2025-05-09 00:34:27, "Kent Overstreet" <kent.overstreet@linux.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@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().
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
next prev parent reply other threads:[~2025-05-08 16:58 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 17:55 David Wang
2025-05-07 18:19 ` David Wang
2025-05-07 23:42 ` [PATCH] " Suren Baghdasaryan
2025-05-08 0:01 ` Kent Overstreet
2025-05-08 3:06 ` David Wang
2025-05-08 3:31 ` Kent Overstreet
2025-05-08 3:35 ` David Wang
2025-05-08 4:07 ` Kent Overstreet
2025-05-08 5:51 ` David Wang
2025-05-08 13:33 ` Kent Overstreet
2025-05-08 16:24 ` David Wang
2025-05-08 16:34 ` Kent Overstreet
2025-05-08 16:58 ` David Wang [this message]
2025-05-08 17:17 ` David Wang
2025-05-08 17:26 ` Kent Overstreet
2025-05-08 2:24 ` David Wang
2025-05-07 23:36 ` Suren Baghdasaryan
2025-05-08 3:10 ` David Wang
2025-05-08 15:32 ` David Wang
2025-05-08 21:41 ` Suren Baghdasaryan
2025-05-09 5:53 ` [PATCH 2/2] alloc_tag: keep codetag iterator cross read() calls David Wang
2025-05-09 17:34 ` Suren Baghdasaryan
2025-05-09 17:45 ` David Wang
2025-05-09 17:39 ` [PATCH v2 2/2] alloc_tag: keep codetag iterator active between " David Wang
2025-05-09 18:33 ` Tim Chen
2025-05-09 19:36 ` Suren Baghdasaryan
2025-05-09 19:46 ` Tim Chen
2025-05-09 20:46 ` Suren Baghdasaryan
2025-05-09 21:15 ` Suren Baghdasaryan
2025-05-10 3:10 ` David Wang
2025-05-10 3:30 ` Suren Baghdasaryan
2025-05-10 3:58 ` David Wang
2025-05-10 4:03 ` Suren Baghdasaryan
2025-05-10 3:35 ` David Wang
2025-05-10 3:25 ` David Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5294252d.b74a.196b0d583c6.Coremail.00107082@163.com \
--to=00107082@163.com \
--cc=akpm@linux-foundation.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=surenb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox