[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=whD=9qTfhYVhH+d44KbwefC_vnRAjqz-pthcSn1p5zZLA@mail.gmail.com>
Date: Tue, 30 Jan 2024 13:52:05 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: Masami Hiramatsu <mhiramat@...nel.org>, linux-kernel@...r.kernel.org,
linux-trace-kernel@...r.kernel.org
Subject: Re: [PATCH 5/6] eventfs: get rid of dentry pointers without refcounts
On Tue, 30 Jan 2024 at 12:55, Steven Rostedt <rostedt@...dmis.org> wrote:
>
> I'm going to be putting back the ei->name pointer as the above actually
> adds more memory usage.
I did it mainly because I hate having multiple different allocation
sites that then have to do that kref_init() etc individually, and once
there was a single site the "name" thing really looked lik ean obvious
simplification.
That said, I think you're confused about the memory usage.
Sure, 'kstrdup_const()' optimizes away the allocation for static
constant strings, but what it does *not* do is to optimize away the
pointer.
In contrast, allocating them together gets rid of the pointer itself,
because now the name is just an offset in the structure.
And the pointer is 8 bytes right there.
So allocating the string _with_ the ei will always save at least 8 bytes.
So whenever the string is less than that in length it's *always* a win.
And even when it's not an absolute win, it will take advantage of the
kmalloc() quantized sizes too, and generally not be a loss even with
longer names.
So I'm pretty sure you are simply entirely wrong on the memory usage.
Not counting the size of the pointer is overlooking a big piece of the
puzzle.
Btw, you can look at name lengths in tracefs with something stupid like this:
find . | sed 's:^.*/::' | tr -c '\n' . | sort | uniq -c
and you will see that (at least in my case) names of lengths 1..7 are
dominating it all:
1 .
2189 ..
34 ...
2229 ....
207 .....
6833 ......
2211 .......
with the rest being insignificant in comparison.
The reason? There's a *lot* of those 'filter' and 'enable' and 'id'
files. All of which are better off without a 'const char *name' taking
8 bytes.
Linus
Powered by blists - more mailing lists