From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org,
Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: Re: [PATCH] btrfs: shrink the size of btrfs_bio
Date: Fri, 12 Dec 2025 04:18:54 +0100 [thread overview]
Message-ID: <20251212031854.GP4859@twin.jikos.cz> (raw)
In-Reply-To: <0f25d1779166876e3bd4c1509d8eaf67968a6f65.1765229068.git.wqu@suse.com>
On Tue, Dec 09, 2025 at 07:55:03AM +1030, Qu Wenruo wrote:
> This is done by:
>
> - Shrink the size of btrfs_bio::mirror_num
> From 32 bits unsigned int to u16.
>
> Normally btrfs mirror number is either 0 (all profiles), 1 (all
> profiles), 2 (DUP/RAID1/RAID10/RAID5), 3 (RAID1C3) or 4 (RAID1C4).
>
> But for RAID6 the mirror number can go as large as the number of
> devices of that chunk.
>
> Currently the limit for number of devices for a data chunk is
> BTRFS_MAX_DEVS(), which is around 500 for the default 16K nodesize.
> And if going the max 64K nodesize, we can have a little over 2000
> devices for a chunk.
>
> Although I'd argue it's way overkilled, we don't reject such cases yet
> thus u8 is not going to cut it, and have to use u16 (max out at 64K).
>
> - Use bit fields for boolean members
> Although it's not always safe for racy call sites, those members are
> safe.
>
> * csum_search_commit_root
> * is_scrub
> Those two are set immediately after bbio allocation and no more
> writes after allocation, thus they are very safe.
>
> * async_csum
> * can_use_append
> Those two are set for each split range, and after that there is no
> writes into those two members in different threads, thus they are
> also safe.
>
> And there are spaces for 4 more bits before increasing the size of
> btrfs_bio again, which should be future proof enough.
>
> - Reorder the structure members
> Now we always put the largest member first (after the huge 120 bytes
> union), making it easier to fill any holes.
>
> This reduce the size of btrfs_bio by 8 bytes, from 312 bytes to 304 bytes.
>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> Changelog:
> v2:
> - Change mirror number from u8 to u16
> As for RAID6 we can have cases (that's beyond 255 devices in a RAID6
> chunk) where u8 is not large enough.
> Thankfully u16 is large enough for the max number of devices possible
> for a RAID6 chunk.
>
> And we have exactly a one-byte hole the in structure, and expanding
> the widith of @mirror_num will not increase the size of btrfs_bio.
Reviewed-by: David Sterba <dsterba@suse.com>
next prev parent reply other threads:[~2025-12-12 3:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 21:25 [PATCH] btrfs: shrink the size of btrfs_bio Qu Wenruo
2025-12-12 3:18 ` David Sterba [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-12-05 8:04 Qu Wenruo
2025-12-05 10:09 ` Johannes Thumshirn
2025-12-08 19:19 ` David Sterba
2025-12-08 20:26 ` Qu Wenruo
2025-12-08 20:44 ` David Sterba
2025-12-08 20:53 ` Qu Wenruo
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=20251212031854.GP4859@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@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