From: Mateusz Guzik <mjguzik@gmail.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, torvalds@linux-foundation.org,
brauner@kernel.org, jack@suse.cz, paul@paul-moore.com,
axboe@kernel.dk, audit@vger.kernel.org,
io-uring@vger.kernel.org
Subject: Re: [RFC PATCH v2 15/18] struct filename: saner handling of long names
Date: Sun, 30 Nov 2025 05:38:18 +0100 [thread overview]
Message-ID: <CAGudoHEMjWCOLEp+TdKLjuguHEKn9+e+aZwfKyK_sYpTZY8HRg@mail.gmail.com> (raw)
In-Reply-To: <20251130040622.GO3538@ZenIV>
On Sun, Nov 30, 2025 at 5:06 AM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Sat, Nov 29, 2025 at 06:33:22PM +0100, Mateusz Guzik wrote:
>
> > This makes sizeof struct filename 152 bytes. At the same time because
> > of the SLAB_HWCACHE_ALIGN flag, the obj is going to take 192 bytes.
> >
> > I don't know what would be the nice way to handle this in Linux, but
> > as is this is just failing to take advantage of memory which is going
> > to get allocated anyway.
> >
> > Perhaps the macro could be bumped to 168 and the size checked with a
> > static assert on 64 bit platforms?
>
> Could be done, even though I wonder how much would that really save.
>
By any chance are you angling for that idea to keep struct filename on
the stack and that's why the size is 128?
With struct nameidata already on the stack and taking 240 bytes,
adding the 152 bytes would result in 392 bytes in total. I would argue
that's prohibitive, at the same time lowering the length to something
like 64 already makes gcc not fit with some of its lookups.
Anyway, I did look into something like this way back and some programs
really liked their *long* paths (way past 128).
Some stats I recently collected on FreeBSD while building packages:
dtrace -n 'vfs:namei:lookup:entry { @ =
lquantize(strlen(stringof(arg1)), 0, 384, 8); }'
value ------------- Distribution ------------- count
< 0 | 0
0 |@@@@@@@@ 18105105
8 |@@@@@@@ 16360012
16 |@@@@@@@@@ 21313430
24 |@@@@@@ 15000426
32 |@@@ 6450202
40 |@@ 4209166
48 |@ 2533298
56 |@ 1611506
64 |@ 1203825
72 | 1068207
80 | 877158
88 | 592192
96 | 489958
104 | 709757
112 | 925775
120 | 1041627
128 |@ 1315123
136 | 664687
144 | 276673
152 | 150870
160 | 82661
168 | 40630
176 | 26693
184 | 15112
192 | 7276
200 | 5773
208 | 2462
216 | 1679
224 | 1150
232 | 1301
240 | 1652
248 | 659
256 | 464
264 | 0
> > Or some magic based on reported
> > cache line size.
>
> No comments. At least, none suitable for polite company.
>
> BTW, one thing that might make sense is storing the name length in there...
(gdb) ptype /o struct filename
/* offset | size */ type = struct filename {
/* 0 | 8 */ const char *name;
/* 8 | 8 */ const char *uptr;
/* 16 | 4 */ atomic_t refcnt;
/* XXX 4-byte hole */
/* 24 | 8 */ struct audit_names *aname;
/* 32 | 0 */ const char iname[];
/* total size (bytes): 32 */
}
If the length start getting stored it can presumably go into the hole.
Otherwise is there a reason to not rearrange this? The array could be
only aligned to 4 bytes, on archs which are fine with misaligned
access anyway. That's 4 extra bytes recovered.
All that said, now that I look at it, assuming struct filename will
keep being allocated from slub, why not make it 256 bytes? This gives
232 bytes for the name buffer (covering almost all of the looups I ran
into anyway), archs with 128 byte cacheline are sorted out and one can
trivially unconditionally static assert on the total size being 256
bytes, all while not having space which is never going to be used.
next prev parent reply other threads:[~2025-11-30 4:38 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-29 17:01 [RFC PATCH v2 00/18] io_uring, struct filename and audit Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 01/18] do_faccessat(): import pathname only once Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 02/18] do_fchmodat(): " Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 03/18] do_fchownat(): " Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 04/18] do_utimes_path(): " Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 05/18] chdir(2): " Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 06/18] chroot(2): " Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 07/18] user_statfs(): " Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 08/18] do_sys_truncate(): " Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 09/18] do_readlinkat(): " Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 10/18] get rid of audit_reusename() Al Viro
2025-12-16 2:14 ` Paul Moore
2025-11-29 17:01 ` [RFC PATCH v2 11/18] ntfs: ->d_compare() must not block Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 12/18] getname_flags() massage, part 1 Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 13/18] getname_flags() massage, part 2 Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 14/18] struct filename: use names_cachep only for getname() and friends Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 15/18] struct filename: saner handling of long names Al Viro
2025-11-29 17:33 ` Mateusz Guzik
2025-11-30 4:06 ` Al Viro
2025-11-30 4:38 ` Mateusz Guzik [this message]
2025-11-29 17:01 ` [RFC PATCH v2 16/18] allow incomplete imports of filenames Al Viro
2025-11-29 17:01 ` [RFC PATCH v2 17/18] fs: touch up predicts in putname() Al Viro
2025-11-29 17:34 ` Mateusz Guzik
2025-11-29 17:01 ` [RFC PATCH v2 18/18] struct filename ->refcnt doesn't need to be atomic Al Viro
2025-12-16 2:18 ` Paul Moore
2025-12-10 1:31 ` [RFC PATCH v2 00/18] io_uring, struct filename and audit Jens Axboe
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=CAGudoHEMjWCOLEp+TdKLjuguHEKn9+e+aZwfKyK_sYpTZY8HRg@mail.gmail.com \
--to=mjguzik@gmail.com \
--cc=audit@vger.kernel.org \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=io-uring@vger.kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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