Skip to content

Commit b61fb56

Browse files
adam900710kdave
authored andcommitted
btrfs: remove btrfs_bio::fs_info by extracting it from btrfs_bio::inode
Currently there is only one caller which doesn't populate btrfs_bio::inode, and that's scrub. The idea is scrub doesn't want any automatic csum verification nor read-repair, as everything will be handled by scrub itself. However that behavior is really no different than metadata inode, thus we can reuse btree_inode as btrfs_bio::inode for scrub. The only exception is in btrfs_submit_chunk() where if a bbio is from scrub or data reloc inode, we set rst_search_commit_root to true. This means we still need a way to distinguish scrub from metadata, but that can be done by a new flag inside btrfs_bio. Now btrfs_bio::inode is a mandatory parameter, we can extract fs_info from that inode thus can remove btrfs_bio::fs_info to save 8 bytes from btrfs_bio structure. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 6b6f6f2 commit b61fb56

File tree

9 files changed

+84
-80
lines changed

9 files changed

+84
-80
lines changed

fs/btrfs/bio.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ static bool bbio_has_ordered_extent(const struct btrfs_bio *bbio)
4141
* Initialize a btrfs_bio structure. This skips the embedded bio itself as it
4242
* is already initialized by the block layer.
4343
*/
44-
void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info,
44+
void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_inode *inode, u64 file_offset,
4545
btrfs_bio_end_io_t end_io, void *private)
4646
{
47+
/* @inode parameter is mandatory. */
48+
ASSERT(inode);
49+
4750
memset(bbio, 0, offsetof(struct btrfs_bio, bio));
48-
bbio->fs_info = fs_info;
51+
bbio->inode = inode;
4952
bbio->end_io = end_io;
5053
bbio->private = private;
54+
bbio->file_offset = file_offset;
5155
atomic_set(&bbio->pending_ios, 1);
5256
WRITE_ONCE(bbio->status, BLK_STS_OK);
5357
}
@@ -60,15 +64,15 @@ void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info,
6064
* a mempool.
6165
*/
6266
struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf,
63-
struct btrfs_fs_info *fs_info,
67+
struct btrfs_inode *inode, u64 file_offset,
6468
btrfs_bio_end_io_t end_io, void *private)
6569
{
6670
struct btrfs_bio *bbio;
6771
struct bio *bio;
6872

6973
bio = bio_alloc_bioset(NULL, nr_vecs, opf, GFP_NOFS, &btrfs_bioset);
7074
bbio = btrfs_bio(bio);
71-
btrfs_bio_init(bbio, fs_info, end_io, private);
75+
btrfs_bio_init(bbio, inode, file_offset, end_io, private);
7276
return bbio;
7377
}
7478

@@ -85,9 +89,7 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info,
8589
return ERR_CAST(bio);
8690

8791
bbio = btrfs_bio(bio);
88-
btrfs_bio_init(bbio, fs_info, NULL, orig_bbio);
89-
bbio->inode = orig_bbio->inode;
90-
bbio->file_offset = orig_bbio->file_offset;
92+
btrfs_bio_init(bbio, orig_bbio->inode, orig_bbio->file_offset, NULL, orig_bbio);
9193
orig_bbio->file_offset += map_length;
9294
if (bbio_has_ordered_extent(bbio)) {
9395
refcount_inc(&orig_bbio->ordered->refs);
@@ -244,9 +246,8 @@ static struct btrfs_failed_bio *repair_one_sector(struct btrfs_bio *failed_bbio,
244246
bio_add_folio_nofail(repair_bio, folio, sectorsize, foff);
245247

246248
repair_bbio = btrfs_bio(repair_bio);
247-
btrfs_bio_init(repair_bbio, fs_info, NULL, fbio);
248-
repair_bbio->inode = failed_bbio->inode;
249-
repair_bbio->file_offset = failed_bbio->file_offset + bio_offset;
249+
btrfs_bio_init(repair_bbio, failed_bbio->inode, failed_bbio->file_offset + bio_offset,
250+
NULL, fbio);
250251

251252
mirror = next_repair_mirror(fbio, failed_bbio->mirror_num);
252253
btrfs_debug(fs_info, "submitting repair read to mirror %d", mirror);
@@ -332,7 +333,7 @@ static void btrfs_simple_end_io(struct bio *bio)
332333
{
333334
struct btrfs_bio *bbio = btrfs_bio(bio);
334335
struct btrfs_device *dev = bio->bi_private;
335-
struct btrfs_fs_info *fs_info = bbio->fs_info;
336+
struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
336337

337338
btrfs_bio_counter_dec(fs_info);
338339

@@ -581,10 +582,11 @@ static void run_one_async_done(struct btrfs_work *work, bool do_free)
581582

582583
static bool should_async_write(struct btrfs_bio *bbio)
583584
{
585+
struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
584586
bool auto_csum_mode = true;
585587

586588
#ifdef CONFIG_BTRFS_EXPERIMENTAL
587-
struct btrfs_fs_devices *fs_devices = bbio->fs_info->fs_devices;
589+
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
588590
enum btrfs_offload_csum_mode csum_mode = READ_ONCE(fs_devices->offload_csum_mode);
589591

590592
if (csum_mode == BTRFS_OFFLOAD_CSUM_FORCE_OFF)
@@ -594,7 +596,7 @@ static bool should_async_write(struct btrfs_bio *bbio)
594596
#endif
595597

596598
/* Submit synchronously if the checksum implementation is fast. */
597-
if (auto_csum_mode && test_bit(BTRFS_FS_CSUM_IMPL_FAST, &bbio->fs_info->flags))
599+
if (auto_csum_mode && test_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags))
598600
return false;
599601

600602
/*
@@ -605,7 +607,7 @@ static bool should_async_write(struct btrfs_bio *bbio)
605607
return false;
606608

607609
/* Zoned devices require I/O to be submitted in order. */
608-
if ((bbio->bio.bi_opf & REQ_META) && btrfs_is_zoned(bbio->fs_info))
610+
if ((bbio->bio.bi_opf & REQ_META) && btrfs_is_zoned(fs_info))
609611
return false;
610612

611613
return true;
@@ -620,7 +622,7 @@ static bool btrfs_wq_submit_bio(struct btrfs_bio *bbio,
620622
struct btrfs_io_context *bioc,
621623
struct btrfs_io_stripe *smap, int mirror_num)
622624
{
623-
struct btrfs_fs_info *fs_info = bbio->fs_info;
625+
struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
624626
struct async_submit_bio *async;
625627

626628
async = kmalloc(sizeof(*async), GFP_NOFS);
@@ -639,27 +641,28 @@ static bool btrfs_wq_submit_bio(struct btrfs_bio *bbio,
639641

640642
static u64 btrfs_append_map_length(struct btrfs_bio *bbio, u64 map_length)
641643
{
644+
struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
642645
unsigned int nr_segs;
643646
int sector_offset;
644647

645-
map_length = min(map_length, bbio->fs_info->max_zone_append_size);
646-
sector_offset = bio_split_rw_at(&bbio->bio, &bbio->fs_info->limits,
648+
map_length = min(map_length, fs_info->max_zone_append_size);
649+
sector_offset = bio_split_rw_at(&bbio->bio, &fs_info->limits,
647650
&nr_segs, map_length);
648651
if (sector_offset) {
649652
/*
650653
* bio_split_rw_at() could split at a size smaller than our
651654
* sectorsize and thus cause unaligned I/Os. Fix that by
652655
* always rounding down to the nearest boundary.
653656
*/
654-
return ALIGN_DOWN(sector_offset << SECTOR_SHIFT, bbio->fs_info->sectorsize);
657+
return ALIGN_DOWN(sector_offset << SECTOR_SHIFT, fs_info->sectorsize);
655658
}
656659
return map_length;
657660
}
658661

659662
static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
660663
{
661664
struct btrfs_inode *inode = bbio->inode;
662-
struct btrfs_fs_info *fs_info = bbio->fs_info;
665+
struct btrfs_fs_info *fs_info = inode->root->fs_info;
663666
struct bio *bio = &bbio->bio;
664667
u64 logical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
665668
u64 length = bio->bi_iter.bi_size;
@@ -670,7 +673,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
670673
blk_status_t status;
671674
int ret;
672675

673-
if (!bbio->inode || btrfs_is_data_reloc_root(inode->root))
676+
if (bbio->is_scrub || btrfs_is_data_reloc_root(inode->root))
674677
smap.rst_search_commit_root = true;
675678
else
676679
smap.rst_search_commit_root = false;
@@ -782,7 +785,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
782785
static void assert_bbio_alignment(struct btrfs_bio *bbio)
783786
{
784787
#ifdef CONFIG_BTRFS_ASSERT
785-
struct btrfs_fs_info *fs_info = bbio->fs_info;
788+
struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
786789
struct bio_vec bvec;
787790
struct bvec_iter iter;
788791
const u32 blocksize = fs_info->sectorsize;
@@ -885,16 +888,16 @@ int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
885888
*/
886889
void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_replace)
887890
{
888-
struct btrfs_fs_info *fs_info = bbio->fs_info;
891+
struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
889892
u64 logical = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
890893
u64 length = bbio->bio.bi_iter.bi_size;
891894
struct btrfs_io_stripe smap = { 0 };
892895
int ret;
893896

894-
ASSERT(fs_info);
895897
ASSERT(mirror_num > 0);
896898
ASSERT(btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE);
897-
ASSERT(!bbio->inode);
899+
ASSERT(!is_data_inode(bbio->inode));
900+
ASSERT(bbio->is_scrub);
898901

899902
btrfs_bio_counter_inc_blocked(fs_info);
900903
ret = btrfs_map_repair_block(fs_info, &smap, logical, length, mirror_num);

fs/btrfs/bio.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ typedef void (*btrfs_bio_end_io_t)(struct btrfs_bio *bbio);
2727
struct btrfs_bio {
2828
/*
2929
* Inode and offset into it that this I/O operates on.
30-
* Only set for data I/O.
30+
*
31+
* If the inode is a data one, csum verification and read-repair
32+
* will be done automatically.
33+
* If the inode is a metadata one, everything is handled by the caller.
3134
*/
3235
struct btrfs_inode *inode;
3336
u64 file_offset;
@@ -69,14 +72,17 @@ struct btrfs_bio {
6972
atomic_t pending_ios;
7073
struct work_struct end_io_work;
7174

72-
/* File system that this I/O operates on. */
73-
struct btrfs_fs_info *fs_info;
74-
7575
/* Save the first error status of split bio. */
7676
blk_status_t status;
7777

7878
/* Use the commit root to look up csums (data read bio only). */
7979
bool csum_search_commit_root;
80+
81+
/*
82+
* Since scrub will reuse btree inode, we need this flag to distinguish
83+
* scrub bios.
84+
*/
85+
bool is_scrub;
8086
/*
8187
* This member must come last, bio_alloc_bioset will allocate enough
8288
* bytes for entire btrfs_bio but relies on bio being last.
@@ -92,10 +98,10 @@ static inline struct btrfs_bio *btrfs_bio(struct bio *bio)
9298
int __init btrfs_bioset_init(void);
9399
void __cold btrfs_bioset_exit(void);
94100

95-
void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info,
101+
void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_inode *inode, u64 file_offset,
96102
btrfs_bio_end_io_t end_io, void *private);
97103
struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf,
98-
struct btrfs_fs_info *fs_info,
104+
struct btrfs_inode *inode, u64 file_offset,
99105
btrfs_bio_end_io_t end_io, void *private);
100106
void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status);
101107

fs/btrfs/compression.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ static struct compressed_bio *alloc_compressed_bio(struct btrfs_inode *inode,
6767

6868
bbio = btrfs_bio(bio_alloc_bioset(NULL, BTRFS_MAX_COMPRESSED_PAGES, op,
6969
GFP_NOFS, &btrfs_compressed_bioset));
70-
btrfs_bio_init(bbio, inode->root->fs_info, end_io, NULL);
71-
bbio->inode = inode;
72-
bbio->file_offset = start;
70+
btrfs_bio_init(bbio, inode, start, end_io, NULL);
7371
return to_compressed_bio(bbio);
7472
}
7573

@@ -354,7 +352,7 @@ static void end_bbio_compressed_write(struct btrfs_bio *bbio)
354352

355353
static void btrfs_add_compressed_bio_folios(struct compressed_bio *cb)
356354
{
357-
struct btrfs_fs_info *fs_info = cb->bbio.fs_info;
355+
struct btrfs_fs_info *fs_info = cb->bbio.inode->root->fs_info;
358356
struct bio *bio = &cb->bbio.bio;
359357
u32 offset = 0;
360358

fs/btrfs/compression.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/pagemap.h>
1515
#include "bio.h"
1616
#include "fs.h"
17+
#include "btrfs_inode.h"
1718

1819
struct address_space;
1920
struct inode;
@@ -74,7 +75,7 @@ struct compressed_bio {
7475

7576
static inline struct btrfs_fs_info *cb_to_fs_info(const struct compressed_bio *cb)
7677
{
77-
return cb->bbio.fs_info;
78+
return cb->bbio.inode->root->fs_info;
7879
}
7980

8081
/* @range_end must be exclusive. */

fs/btrfs/direct-io.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,8 @@ static void btrfs_dio_submit_io(const struct iomap_iter *iter, struct bio *bio,
715715
container_of(bbio, struct btrfs_dio_private, bbio);
716716
struct btrfs_dio_data *dio_data = iter->private;
717717

718-
btrfs_bio_init(bbio, BTRFS_I(iter->inode)->root->fs_info,
718+
btrfs_bio_init(bbio, BTRFS_I(iter->inode), file_offset,
719719
btrfs_dio_end_io, bio->bi_private);
720-
bbio->inode = BTRFS_I(iter->inode);
721-
bbio->file_offset = file_offset;
722720

723721
dip->file_offset = file_offset;
724722
dip->bytes = bio->bi_iter.bi_size;

fs/btrfs/extent_io.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ static void end_folio_read(struct folio *folio, bool uptodate, u64 start, u32 le
517517
*/
518518
static void end_bbio_data_write(struct btrfs_bio *bbio)
519519
{
520-
struct btrfs_fs_info *fs_info = bbio->fs_info;
520+
struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
521521
struct bio *bio = &bbio->bio;
522522
int error = blk_status_to_errno(bio->bi_status);
523523
struct folio_iter fi;
@@ -573,7 +573,7 @@ static void begin_folio_read(struct btrfs_fs_info *fs_info, struct folio *folio)
573573
*/
574574
static void end_bbio_data_read(struct btrfs_bio *bbio)
575575
{
576-
struct btrfs_fs_info *fs_info = bbio->fs_info;
576+
struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
577577
struct bio *bio = &bbio->bio;
578578
struct folio_iter fi;
579579

@@ -738,12 +738,10 @@ static void alloc_new_bio(struct btrfs_inode *inode,
738738
struct btrfs_fs_info *fs_info = inode->root->fs_info;
739739
struct btrfs_bio *bbio;
740740

741-
bbio = btrfs_bio_alloc(BIO_MAX_VECS, bio_ctrl->opf, fs_info,
742-
bio_ctrl->end_io_func, NULL);
741+
bbio = btrfs_bio_alloc(BIO_MAX_VECS, bio_ctrl->opf, inode,
742+
file_offset, bio_ctrl->end_io_func, NULL);
743743
bbio->bio.bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT;
744744
bbio->bio.bi_write_hint = inode->vfs_inode.i_write_hint;
745-
bbio->inode = inode;
746-
bbio->file_offset = file_offset;
747745
bio_ctrl->bbio = bbio;
748746
bio_ctrl->len_to_oe_boundary = U32_MAX;
749747
bio_ctrl->next_file_offset = file_offset;
@@ -2224,12 +2222,11 @@ static noinline_for_stack void write_one_eb(struct extent_buffer *eb,
22242222

22252223
bbio = btrfs_bio_alloc(INLINE_EXTENT_BUFFER_PAGES,
22262224
REQ_OP_WRITE | REQ_META | wbc_to_write_flags(wbc),
2227-
eb->fs_info, end_bbio_meta_write, eb);
2225+
BTRFS_I(fs_info->btree_inode), eb->start,
2226+
end_bbio_meta_write, eb);
22282227
bbio->bio.bi_iter.bi_sector = eb->start >> SECTOR_SHIFT;
22292228
bio_set_dev(&bbio->bio, fs_info->fs_devices->latest_dev->bdev);
22302229
wbc_init_bio(wbc, &bbio->bio);
2231-
bbio->inode = BTRFS_I(eb->fs_info->btree_inode);
2232-
bbio->file_offset = eb->start;
22332230
for (int i = 0; i < num_extent_folios(eb); i++) {
22342231
struct folio *folio = eb->folios[i];
22352232
u64 range_start = max_t(u64, eb->start, folio_pos(folio));
@@ -3844,6 +3841,7 @@ static void end_bbio_meta_read(struct btrfs_bio *bbio)
38443841
int read_extent_buffer_pages_nowait(struct extent_buffer *eb, int mirror_num,
38453842
const struct btrfs_tree_parent_check *check)
38463843
{
3844+
struct btrfs_fs_info *fs_info = eb->fs_info;
38473845
struct btrfs_bio *bbio;
38483846

38493847
if (test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags))
@@ -3877,11 +3875,9 @@ int read_extent_buffer_pages_nowait(struct extent_buffer *eb, int mirror_num,
38773875
refcount_inc(&eb->refs);
38783876

38793877
bbio = btrfs_bio_alloc(INLINE_EXTENT_BUFFER_PAGES,
3880-
REQ_OP_READ | REQ_META, eb->fs_info,
3881-
end_bbio_meta_read, eb);
3878+
REQ_OP_READ | REQ_META, BTRFS_I(fs_info->btree_inode),
3879+
eb->start, end_bbio_meta_read, eb);
38823880
bbio->bio.bi_iter.bi_sector = eb->start >> SECTOR_SHIFT;
3883-
bbio->inode = BTRFS_I(eb->fs_info->btree_inode);
3884-
bbio->file_offset = eb->start;
38853881
memcpy(&bbio->parent_check, check, sizeof(*check));
38863882
for (int i = 0; i < num_extent_folios(eb); i++) {
38873883
struct folio *folio = eb->folios[i];

fs/btrfs/inode.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9402,7 +9402,6 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode,
94029402
u64 disk_bytenr, u64 disk_io_size,
94039403
struct page **pages, void *uring_ctx)
94049404
{
9405-
struct btrfs_fs_info *fs_info = inode->root->fs_info;
94069405
struct btrfs_encoded_read_private *priv, sync_priv;
94079406
struct completion sync_reads;
94089407
unsigned long i = 0;
@@ -9427,10 +9426,9 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode,
94279426
priv->status = 0;
94289427
priv->uring_ctx = uring_ctx;
94299428

9430-
bbio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, fs_info,
9429+
bbio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, inode, 0,
94319430
btrfs_encoded_read_endio, priv);
94329431
bbio->bio.bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT;
9433-
bbio->inode = inode;
94349432

94359433
do {
94369434
size_t bytes = min_t(u64, disk_io_size, PAGE_SIZE);
@@ -9439,10 +9437,9 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode,
94399437
refcount_inc(&priv->pending_refs);
94409438
btrfs_submit_bbio(bbio, 0);
94419439

9442-
bbio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, fs_info,
9440+
bbio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, inode, 0,
94439441
btrfs_encoded_read_endio, priv);
94449442
bbio->bio.bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT;
9445-
bbio->inode = inode;
94469443
continue;
94479444
}
94489445

0 commit comments

Comments
 (0)