From: David Sterba <dsterba@suse.cz>
To: Daniel Vacek <neelx@suse.com>
Cc: dsterba@suse.cz, 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: Mon, 5 May 2025 16:10:19 +0200 [thread overview]
Message-ID: <20250505141019.GW9140@twin.jikos.cz> (raw)
In-Reply-To: <CAPjX3Ffy2=CQP2mx9Wa3BBR54fEAcuo8ADqeTVdcAmCO7g+gmg@mail.gmail.com>
On Fri, May 02, 2025 at 02:03:55PM +0200, Daniel Vacek wrote:
> > Yeah, 256 is a nice number because it aligns with cachelines on multiple
> > architectures, this is useful for splitting the structure to the "data
> > accessed together" and locking/refcounting. It's a tentative goal, we
> > used to have larger eb size due to own locking implementation but with
> > rwsems it got close/under 256.
> >
> > The current size 240 is 1/4 of cacheline shifted so it's not all clean
> > but whe have some wiggle room for adding new members or cached values,
> > like folio_size/folio_shift/addr.
>
> Sounds like we could force align to cacheline or explicitly pad to
> 256B? The later could be a bit tricky though.
We could and we also have conflicting goals:
- alignment (with some waste)
- more objects packed into the slab which is 8K
More objects mean better chance to satisfy allocations, that are right
now NOFAIL, so blocking metadata operations with worse consequences.
> > > struct btrfs_fs_info *fs_info;
> > >
> > > /*
> > > @@ -94,9 +97,6 @@ struct extent_buffer {
> > > spinlock_t refs_lock;
> > > atomic_t refs;
> > > int read_mirror;
> > > - /* >= 0 if eb belongs to a log tree, -1 otherwise */
> > > - s8 log_index;
> > > - u8 folio_shift;
> > > struct rcu_head rcu_head;
> > >
> > > struct rw_semaphore lock;
> > >
> > > you're down to 256 even on -rt. And the great part is I don't see any
> > > sacrifices (other than accessing a cacheline in fs_info). We're only
> > > using 8 flags now, so there is still some room left for another 8 if
> > > needed in the future.
> >
> > Which means that the size on non-rt would be something like 228, roughly
> > calculating the savings and the increase due to spinloct_t going from
> > 4 -> 32 bytes. Also I'd like to see the generated assembly after the
> > suggested reordering.
>
> If I see correctly the non-rt will not change when I keep ulong
> bflags. The -rt build goes down to 264 bytes. That's a bit better for
> free but still not ideal from alignment POV.
>
> > The eb may not be perfect, I think there could be false sharing of
> > refs_lock and refs but this is a wild guess and based only on code
>
> refs_lock and refs look like they share the same cacheline in every
> case. At least on x86.
> But still, the slab object is not aligned in the first place. Luckily
> the two fields roam together.
>
> Out of curiosity, is there any past experience where this kind of
> optimizations make a difference within a filesystem code?
> I can imagine perhaps for fast devices like NVDIMM or DAX the CPU may
> become the bottleneck? Or are nowadays NVMe devices already fast
> enough to saturate the CPU?
I don't have a specific example. This is tricky to measure and
historically the devices were slow so any IO and waiting made the cache
effects irrelevant. With NVMe, modern CPUs we might start seeing that.
Instrumentation or profiling of the structures can do that, there are
tools for that but the variability of the hardware combinations and
runtime conditions makes it hard so I'm resorting to more "static"
approach and go after known good patterns like alignment or placement
related to cachelines (manually or with ____cacheline_aligned_in_smp).
> I faintly recall one issue where I debugged a CPU which could not keep
> up with handling the interrupts of finished IO on NVMe submitted by
> other CPUs. Though that was on xfs (or maybe ext4) not on btrfs. But
> that was a power-play of one against the rest as the interrupt was not
> balanced or spread to more CPUs.
next prev parent reply other threads:[~2025-05-05 14:10 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
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 [this message]
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=20250505141019.GW9140@twin.jikos.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox