Skip to content

Commit 4cd4d6c

Browse files
adam900710kdave
authored andcommitted
btrfs: shrink the size of btrfs_bio
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> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent e004221 commit 4cd4d6c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fs/btrfs/bio.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,33 @@ struct btrfs_bio {
6868
struct btrfs_tree_parent_check parent_check;
6969
};
7070

71+
/* For internal use in read end I/O handling */
72+
struct work_struct end_io_work;
73+
7174
/* End I/O information supplied to btrfs_bio_alloc */
7275
btrfs_bio_end_io_t end_io;
7376
void *private;
7477

75-
/* For internal use in read end I/O handling */
76-
unsigned int mirror_num;
7778
atomic_t pending_ios;
78-
struct work_struct end_io_work;
79+
u16 mirror_num;
7980

8081
/* Save the first error status of split bio. */
8182
blk_status_t status;
8283

8384
/* Use the commit root to look up csums (data read bio only). */
84-
bool csum_search_commit_root;
85+
bool csum_search_commit_root:1;
8586

8687
/*
8788
* Since scrub will reuse btree inode, we need this flag to distinguish
8889
* scrub bios.
8990
*/
90-
bool is_scrub;
91+
bool is_scrub:1;
9192

9293
/* Whether the csum generation for data write is async. */
93-
bool async_csum;
94+
bool async_csum:1;
9495

9596
/* Whether the bio is written using zone append. */
96-
bool can_use_append;
97+
bool can_use_append:1;
9798

9899
/*
99100
* This member must come last, bio_alloc_bioset will allocate enough

0 commit comments

Comments
 (0)