From: David Sterba <dsterba@suse.cz>
To: Daniel Vacek <neelx@suse.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: remove extent buffer's redundant `len` member field
Date: Fri, 2 May 2025 12:30:14 +0200 [thread overview]
Message-ID: <20250502103014.GN9140@suse.cz> (raw)
In-Reply-To: <CAPjX3FdpjOfu61KTnQFKdGgh4u5eVz_AwenoPVNgP_eiuka3hw@mail.gmail.com>
On Wed, Apr 30, 2025 at 02:31:33PM +0200, Daniel Vacek wrote:
> On Wed, 30 Apr 2025 at 10:21, Daniel Vacek <neelx@suse.com> wrote:
> >
> > On Wed, 30 Apr 2025 at 10:03, David Sterba <dsterba@suse.cz> wrote:
> > >
> > > On Tue, Apr 29, 2025 at 05:17:57PM +0200, Daniel Vacek wrote:
> > > > Even super block nowadays uses nodesize for eb->len. This is since commits
> > > >
> > > > 551561c34663 ("btrfs: don't pass nodesize to __alloc_extent_buffer()")
> > > > da17066c4047 ("btrfs: pull node/sector/stripe sizes out of root and into fs_info")
> > > > ce3e69847e3e ("btrfs: sink parameter len to alloc_extent_buffer")
> > > > a83fffb75d09 ("btrfs: sink blocksize parameter to btrfs_find_create_tree_block")
> > > >
> > > > With these the eb->len is not really useful anymore. Let's use the nodesize
> > > > directly where applicable.
> > >
> > > I've had this patch in my local branch for some years from the times we
> > > were optimizing extent buffer size. The size on release config is 240
> > > bytes. The goal was to get it under 256 and keep it aligned.
> > >
> > > Removing eb->len does not change the structure size and leaves a hole
> > >
> > > struct extent_buffer {
> > > u64 start; /* 0 8 */
> > > - u32 len; /* 8 4 */
> > > - u32 folio_size; /* 12 4 */
> > > + u32 folio_size; /* 8 4 */
> > > +
> > > + /* XXX 4 bytes hole, try to pack */
> > > +
> > > long unsigned int bflags; /* 16 8 */
> > > struct btrfs_fs_info * fs_info; /* 24 8 */
> > > void * addr; /* 32 8 */
> > > @@ -5554,8 +5556,8 @@ struct extent_buffer {
> > > struct rw_semaphore lock; /* 72 40 */
> > > struct folio * folios[16]; /* 112 128 */
> > >
> > > - /* size: 240, cachelines: 4, members: 14 */
> > > - /* sum members: 238, holes: 1, sum holes: 2 */
> > > + /* size: 240, cachelines: 4, members: 13 */
> > > + /* sum members: 234, holes: 2, sum holes: 6 */
> > > /* forced alignments: 1, forced holes: 1, sum forced holes: 2 */
> > > /* last cacheline: 48 bytes */
> > > } __attribute__((__aligned__(8)));
> > >
> > > The benefit of duplicating the length in each eb is that it's in the
> > > same cacheline as the other members that are used for offset
> > > calculations or bit manipulations.
> > >
> > > Going to the fs_info->nodesize may or may not hit a cache, also because
> > > it needs to do 2 pointer dereferences, so from that perspective I think
> > > it's making it worse.
> >
> > I was considering that. Since fs_info is shared for all ebs and other
> > stuff like transactions, etc. I think the cache is hot most of the
> > time and there will be hardly any performance difference observable.
> > Though without benchmarks this is just a speculation (on both sides).
> >
> > > I don't think we need to do the optimization right now, but maybe in the
> > > future if there's a need to add something to eb. Still we can use the
> > > remaining 16 bytes up to 256 without making things worse.
> >
> > This really depends on configuration. On my laptop (Debian -rt kernel)
> > the eb struct is actually 272 bytes as the rt_mutex is significantly
> > heavier than raw spin lock. And -rt is a first class citizen nowadays,
> > often used in Kubernetes deployments like 5G RAN telco, dpdk and such.
> > I think it would be nice to slim the struct below 256 bytes even there
> > if that's your aim.
>
> Eventually we can get there by using ushort for bflags and moving
> log_index and folio_shift to fill the hole.
> Let me know what you think.
The bflags are atomic bits and this requires unsigned long. Also the
short int type is something we want to avoid because it's not a natural
type on many architectures and generates worse code. I don't think we
need to optimize for RT kernels, it's now part of mainline kernel but by
far not a common configuration.
next prev parent reply other threads:[~2025-05-02 10:30 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 15:17 [PATCH] btrfs: remove extent buffer's redundant `len` member field Daniel Vacek
2025-04-29 22:34 ` Qu Wenruo
2025-04-30 8:03 ` David Sterba
2025-04-30 8:21 ` Daniel Vacek
2025-04-30 12:31 ` Daniel Vacek
2025-05-02 10:30 ` David Sterba [this message]
2025-05-02 11:23 ` Daniel Vacek
2025-04-30 13:30 ` David Sterba
2025-04-30 14:13 ` Daniel Vacek
2025-05-02 10:56 ` David Sterba
2025-05-02 12:03 ` Daniel Vacek
2025-05-05 14:10 ` David Sterba
2025-05-05 16:19 ` Daniel Vacek
2025-04-30 8:05 ` Filipe Manana
2025-04-30 8:26 ` Daniel Vacek
2025-04-30 8:34 ` Filipe Manana
2025-04-30 8:50 ` Daniel Vacek
2025-04-30 10:26 ` Filipe Manana
2025-04-30 11:09 ` Johannes Thumshirn
2025-04-30 12:09 ` Daniel Vacek
2025-04-30 12:06 ` Daniel Vacek
2025-04-30 12:33 ` Filipe Manana
2025-04-30 12:53 ` Daniel Vacek
2025-05-02 13:37 ` [PATCH v2 0/2] btrfs: eb struct cleanups Daniel Vacek
2025-05-02 13:37 ` [PATCH v2 1/2] btrfs: remove extent buffer's redundant `len` member field Daniel Vacek
2025-05-02 17:35 ` Boris Burkov
2025-05-05 8:23 ` Daniel Vacek
2025-05-05 11:50 ` [PATCH v3 0/2] btrfs: eb struct cleanups Daniel Vacek
2025-05-05 11:50 ` [PATCH v3 1/2] btrfs: remove extent buffer's redundant `len` member field Daniel Vacek
2025-05-05 15:18 ` David Sterba
2025-05-05 17:53 ` Daniel Vacek
2025-05-13 0:32 ` David Sterba
2025-05-13 10:43 ` Daniel Vacek
2025-05-05 11:50 ` [PATCH v3 2/2] btrfs: rearrange the extent buffer structure members Daniel Vacek
2025-05-02 13:37 ` [PATCH v2 " Daniel Vacek
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=20250502103014.GN9140@suse.cz \
--to=dsterba@suse.cz \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neelx@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.