Skip to content

Commit 7a40974

Browse files
committed
Merge tag 'for-6.12-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs updates from David Sterba: "This brings mostly refactoring, cleanups, minor performance optimizations and usual fixes. The folio API conversions are most noticeable. There's one less visible change that could have a high impact. The extent lock scope for read is reduced, not held for the entire operation. In the buffered read case it's left to page or inode lock, some direct io read synchronization is still needed. This used to prevent deadlocks induced by page faults during direct io, so there was a 4K limitation on the requests, e.g. for io_uring. In the future this will allow smoother integration with iomap where the extent read lock was a major obstacle. User visible changes: - the FSTRIM ioctl updates the processed range even after an error or interruption - cleaner thread is woken up in SYNC ioctl instead of waking the transaction thread that can take some delay before waking up the cleaner, this can speed up cleaning of deleted subvolumes - print an error message when opening a device fail, e.g. when it's unexpectedly read-only Core changes: - improved extent map handling in various ways (locking, iteration, ...) - new assertions and locking annotations - raid-stripe-tree locking fixes - use xarray for tracking dirty qgroup extents, switched from rb-tree - turn the subpage test to compile-time condition if possible (e.g. on x86_64 with 4K pages), this allows to skip a lot of ifs and remove dead code - more preparatory work for compression in subpage mode Cleanups and refactoring - folio API conversions, many simple cases where page is passed so switch it to folios - more subpage code refactoring, update page state bitmap processing - introduce auto free for btrfs_path structure, use for the simple cases" * tag 'for-6.12-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: (110 commits) btrfs: only unlock the to-be-submitted ranges inside a folio btrfs: merge btrfs_folio_unlock_writer() into btrfs_folio_end_writer_lock() btrfs: BTRFS_PATH_AUTO_FREE in orphan.c btrfs: use btrfs_path auto free in zoned.c btrfs: DEFINE_FREE for struct btrfs_path btrfs: remove btrfs_folio_end_all_writers() btrfs: constify more pointer parameters btrfs: rework BTRFS_I as macro to preserve parameter const btrfs: add and use helper to verify the calling task has locked the inode btrfs: always update fstrim_range on failure in FITRIM ioctl btrfs: convert copy_inline_to_page() to use folio btrfs: convert btrfs_decompress() to take a folio btrfs: convert zstd_decompress() to take a folio btrfs: convert lzo_decompress() to take a folio btrfs: convert zlib_decompress() to take a folio btrfs: convert try_release_extent_mapping() to take a folio btrfs: convert try_release_extent_state() to take a folio btrfs: convert submit_eb_page() to take a folio btrfs: convert submit_eb_subpage() to take a folio btrfs: convert read_key_bytes() to take a folio ...
2 parents effdcd5 + bd610c0 commit 7a40974

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1583
-1597
lines changed

fs/btrfs/backref.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ static void free_pref(struct prelim_ref *ref)
219219
* A -1 return indicates ref1 is a 'lower' block than ref2, while 1
220220
* indicates a 'higher' block.
221221
*/
222-
static int prelim_ref_compare(struct prelim_ref *ref1,
223-
struct prelim_ref *ref2)
222+
static int prelim_ref_compare(const struct prelim_ref *ref1,
223+
const struct prelim_ref *ref2)
224224
{
225225
if (ref1->level < ref2->level)
226226
return -1;
@@ -251,7 +251,7 @@ static int prelim_ref_compare(struct prelim_ref *ref1,
251251
}
252252

253253
static void update_share_count(struct share_check *sc, int oldcount,
254-
int newcount, struct prelim_ref *newref)
254+
int newcount, const struct prelim_ref *newref)
255255
{
256256
if ((!sc) || (oldcount == 0 && newcount < 1))
257257
return;

fs/btrfs/bio.c

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info,
5353

5454
/*
5555
* Allocate a btrfs_bio structure. The btrfs_bio is the main I/O container for
56-
* btrfs, and is used for all I/O submitted through btrfs_submit_bio.
56+
* btrfs, and is used for all I/O submitted through btrfs_submit_bbio().
5757
*
5858
* Just like the underlying bio_alloc_bioset it will not fail as it is backed by
5959
* a mempool.
@@ -120,12 +120,6 @@ static void __btrfs_bio_end_io(struct btrfs_bio *bbio)
120120
}
121121
}
122122

123-
void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
124-
{
125-
bbio->bio.bi_status = status;
126-
__btrfs_bio_end_io(bbio);
127-
}
128-
129123
static void btrfs_orig_write_end_io(struct bio *bio);
130124

131125
static void btrfs_bbio_propagate_error(struct btrfs_bio *bbio,
@@ -147,8 +141,9 @@ static void btrfs_bbio_propagate_error(struct btrfs_bio *bbio,
147141
}
148142
}
149143

150-
static void btrfs_orig_bbio_end_io(struct btrfs_bio *bbio)
144+
void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
151145
{
146+
bbio->bio.bi_status = status;
152147
if (bbio->bio.bi_pool == &btrfs_clone_bioset) {
153148
struct btrfs_bio *orig_bbio = bbio->private;
154149

@@ -179,7 +174,7 @@ static int prev_repair_mirror(struct btrfs_failed_bio *fbio, int cur_mirror)
179174
static void btrfs_repair_done(struct btrfs_failed_bio *fbio)
180175
{
181176
if (atomic_dec_and_test(&fbio->repair_count)) {
182-
btrfs_orig_bbio_end_io(fbio->bbio);
177+
btrfs_bio_end_io(fbio->bbio, fbio->bbio->bio.bi_status);
183178
mempool_free(fbio, &btrfs_failed_bio_pool);
184179
}
185180
}
@@ -211,7 +206,7 @@ static void btrfs_end_repair_bio(struct btrfs_bio *repair_bbio,
211206
goto done;
212207
}
213208

214-
btrfs_submit_bio(repair_bbio, mirror);
209+
btrfs_submit_bbio(repair_bbio, mirror);
215210
return;
216211
}
217212

@@ -280,7 +275,7 @@ static struct btrfs_failed_bio *repair_one_sector(struct btrfs_bio *failed_bbio,
280275

281276
mirror = next_repair_mirror(fbio, failed_bbio->mirror_num);
282277
btrfs_debug(fs_info, "submitting repair read to mirror %d", mirror);
283-
btrfs_submit_bio(repair_bbio, mirror);
278+
btrfs_submit_bbio(repair_bbio, mirror);
284279
return fbio;
285280
}
286281

@@ -326,7 +321,7 @@ static void btrfs_check_read_bio(struct btrfs_bio *bbio, struct btrfs_device *de
326321
if (fbio)
327322
btrfs_repair_done(fbio);
328323
else
329-
btrfs_orig_bbio_end_io(bbio);
324+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
330325
}
331326

332327
static void btrfs_log_dev_io_error(struct bio *bio, struct btrfs_device *dev)
@@ -360,7 +355,7 @@ static void btrfs_end_bio_work(struct work_struct *work)
360355
if (is_data_bbio(bbio))
361356
btrfs_check_read_bio(bbio, bbio->bio.bi_private);
362357
else
363-
btrfs_orig_bbio_end_io(bbio);
358+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
364359
}
365360

366361
static void btrfs_simple_end_io(struct bio *bio)
@@ -380,7 +375,7 @@ static void btrfs_simple_end_io(struct bio *bio)
380375
} else {
381376
if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status)
382377
btrfs_record_physical_zoned(bbio);
383-
btrfs_orig_bbio_end_io(bbio);
378+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
384379
}
385380
}
386381

@@ -394,7 +389,7 @@ static void btrfs_raid56_end_io(struct bio *bio)
394389
if (bio_op(bio) == REQ_OP_READ && is_data_bbio(bbio))
395390
btrfs_check_read_bio(bbio, NULL);
396391
else
397-
btrfs_orig_bbio_end_io(bbio);
392+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
398393

399394
btrfs_put_bioc(bioc);
400395
}
@@ -424,7 +419,7 @@ static void btrfs_orig_write_end_io(struct bio *bio)
424419
if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status)
425420
stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
426421

427-
btrfs_orig_bbio_end_io(bbio);
422+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
428423
btrfs_put_bioc(bioc);
429424
}
430425

@@ -502,8 +497,8 @@ static void btrfs_submit_mirrored_bio(struct btrfs_io_context *bioc, int dev_nr)
502497
btrfs_submit_dev_bio(bioc->stripes[dev_nr].dev, bio);
503498
}
504499

505-
static void __btrfs_submit_bio(struct bio *bio, struct btrfs_io_context *bioc,
506-
struct btrfs_io_stripe *smap, int mirror_num)
500+
static void btrfs_submit_bio(struct bio *bio, struct btrfs_io_context *bioc,
501+
struct btrfs_io_stripe *smap, int mirror_num)
507502
{
508503
if (!bioc) {
509504
/* Single mirror read/write fast path. */
@@ -593,7 +588,7 @@ static void run_one_async_done(struct btrfs_work *work, bool do_free)
593588

594589
/* If an error occurred we just want to clean up the bio and move on. */
595590
if (bio->bi_status) {
596-
btrfs_orig_bbio_end_io(async->bbio);
591+
btrfs_bio_end_io(async->bbio, async->bbio->bio.bi_status);
597592
return;
598593
}
599594

@@ -603,7 +598,7 @@ static void run_one_async_done(struct btrfs_work *work, bool do_free)
603598
* context. This changes nothing when cgroups aren't in use.
604599
*/
605600
bio->bi_opf |= REQ_BTRFS_CGROUP_PUNT;
606-
__btrfs_submit_bio(bio, async->bioc, &async->smap, async->mirror_num);
601+
btrfs_submit_bio(bio, async->bioc, &async->smap, async->mirror_num);
607602
}
608603

609604
static bool should_async_write(struct btrfs_bio *bbio)
@@ -678,7 +673,10 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
678673
blk_status_t ret;
679674
int error;
680675

681-
smap.is_scrub = !bbio->inode;
676+
if (!bbio->inode || btrfs_is_data_reloc_root(inode->root))
677+
smap.rst_search_commit_root = true;
678+
else
679+
smap.rst_search_commit_root = false;
682680

683681
btrfs_bio_counter_inc_blocked(fs_info);
684682
error = btrfs_map_block(fs_info, btrfs_op(bio), logical, &map_length,
@@ -749,7 +747,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
749747
}
750748
}
751749

752-
__btrfs_submit_bio(bio, bioc, &smap, mirror_num);
750+
btrfs_submit_bio(bio, bioc, &smap, mirror_num);
753751
done:
754752
return map_length == length;
755753

@@ -765,16 +763,14 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
765763
ASSERT(bbio->bio.bi_pool == &btrfs_clone_bioset);
766764
ASSERT(remaining);
767765

768-
remaining->bio.bi_status = ret;
769-
btrfs_orig_bbio_end_io(remaining);
766+
btrfs_bio_end_io(remaining, ret);
770767
}
771-
bbio->bio.bi_status = ret;
772-
btrfs_orig_bbio_end_io(bbio);
768+
btrfs_bio_end_io(bbio, ret);
773769
/* Do not submit another chunk */
774770
return true;
775771
}
776772

777-
void btrfs_submit_bio(struct btrfs_bio *bbio, int mirror_num)
773+
void btrfs_submit_bbio(struct btrfs_bio *bbio, int mirror_num)
778774
{
779775
/* If bbio->inode is not populated, its file_offset must be 0. */
780776
ASSERT(bbio->inode || bbio->file_offset == 0);
@@ -786,7 +782,7 @@ void btrfs_submit_bio(struct btrfs_bio *bbio, int mirror_num)
786782
/*
787783
* Submit a repair write.
788784
*
789-
* This bypasses btrfs_submit_bio deliberately, as that writes all copies in a
785+
* This bypasses btrfs_submit_bbio() deliberately, as that writes all copies in a
790786
* RAID setup. Here we only want to write the one bad copy, so we do the
791787
* mapping ourselves and submit the bio directly.
792788
*
@@ -875,7 +871,7 @@ void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_
875871
ASSERT(smap.dev == fs_info->dev_replace.srcdev);
876872
smap.dev = fs_info->dev_replace.tgtdev;
877873
}
878-
__btrfs_submit_bio(&bbio->bio, NULL, &smap, mirror_num);
874+
btrfs_submit_bio(&bbio->bio, NULL, &smap, mirror_num);
879875
return;
880876

881877
fail:

fs/btrfs/bio.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef void (*btrfs_bio_end_io_t)(struct btrfs_bio *bbio);
2929

3030
/*
3131
* Highlevel btrfs I/O structure. It is allocated by btrfs_bio_alloc and
32-
* passed to btrfs_submit_bio for mapping to the physical devices.
32+
* passed to btrfs_submit_bbio() for mapping to the physical devices.
3333
*/
3434
struct btrfs_bio {
3535
/*
@@ -42,7 +42,7 @@ struct btrfs_bio {
4242
union {
4343
/*
4444
* For data reads: checksumming and original I/O information.
45-
* (for internal use in the btrfs_submit_bio machinery only)
45+
* (for internal use in the btrfs_submit_bbio() machinery only)
4646
*/
4747
struct {
4848
u8 *csum;
@@ -104,7 +104,7 @@ void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status);
104104
/* Submit using blkcg_punt_bio_submit. */
105105
#define REQ_BTRFS_CGROUP_PUNT REQ_FS_PRIVATE
106106

107-
void btrfs_submit_bio(struct btrfs_bio *bbio, int mirror_num);
107+
void btrfs_submit_bbio(struct btrfs_bio *bbio, int mirror_num);
108108
void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_replace);
109109
int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
110110
u64 length, u64 logical, struct folio *folio,

fs/btrfs/block-group.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "extent-tree.h"
2424

2525
#ifdef CONFIG_BTRFS_DEBUG
26-
int btrfs_should_fragment_free_space(struct btrfs_block_group *block_group)
26+
int btrfs_should_fragment_free_space(const struct btrfs_block_group *block_group)
2727
{
2828
struct btrfs_fs_info *fs_info = block_group->fs_info;
2929

@@ -40,9 +40,9 @@ int btrfs_should_fragment_free_space(struct btrfs_block_group *block_group)
4040
*
4141
* Should be called with balance_lock held
4242
*/
43-
static u64 get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags)
43+
static u64 get_restripe_target(const struct btrfs_fs_info *fs_info, u64 flags)
4444
{
45-
struct btrfs_balance_control *bctl = fs_info->balance_ctl;
45+
const struct btrfs_balance_control *bctl = fs_info->balance_ctl;
4646
u64 target = 0;
4747

4848
if (!bctl)
@@ -1415,9 +1415,9 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, int force)
14151415
}
14161416

14171417
static bool clean_pinned_extents(struct btrfs_trans_handle *trans,
1418-
struct btrfs_block_group *bg)
1418+
const struct btrfs_block_group *bg)
14191419
{
1420-
struct btrfs_fs_info *fs_info = bg->fs_info;
1420+
struct btrfs_fs_info *fs_info = trans->fs_info;
14211421
struct btrfs_transaction *prev_trans = NULL;
14221422
const u64 start = bg->start;
14231423
const u64 end = start + bg->length - 1;
@@ -1756,14 +1756,14 @@ static int reclaim_bgs_cmp(void *unused, const struct list_head *a,
17561756
return bg1->used > bg2->used;
17571757
}
17581758

1759-
static inline bool btrfs_should_reclaim(struct btrfs_fs_info *fs_info)
1759+
static inline bool btrfs_should_reclaim(const struct btrfs_fs_info *fs_info)
17601760
{
17611761
if (btrfs_is_zoned(fs_info))
17621762
return btrfs_zoned_should_reclaim(fs_info);
17631763
return true;
17641764
}
17651765

1766-
static bool should_reclaim_block_group(struct btrfs_block_group *bg, u64 bytes_freed)
1766+
static bool should_reclaim_block_group(const struct btrfs_block_group *bg, u64 bytes_freed)
17671767
{
17681768
const int thresh_pct = btrfs_calc_reclaim_threshold(bg->space_info);
17691769
u64 thresh_bytes = mult_perc(bg->length, thresh_pct);
@@ -2006,8 +2006,8 @@ void btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg)
20062006
spin_unlock(&fs_info->unused_bgs_lock);
20072007
}
20082008

2009-
static int read_bg_from_eb(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
2010-
struct btrfs_path *path)
2009+
static int read_bg_from_eb(struct btrfs_fs_info *fs_info, const struct btrfs_key *key,
2010+
const struct btrfs_path *path)
20112011
{
20122012
struct btrfs_chunk_map *map;
20132013
struct btrfs_block_group_item bg;
@@ -2055,7 +2055,7 @@ static int read_bg_from_eb(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
20552055

20562056
static int find_first_block_group(struct btrfs_fs_info *fs_info,
20572057
struct btrfs_path *path,
2058-
struct btrfs_key *key)
2058+
const struct btrfs_key *key)
20592059
{
20602060
struct btrfs_root *root = btrfs_block_group_root(fs_info);
20612061
int ret;
@@ -2640,8 +2640,8 @@ static int insert_block_group_item(struct btrfs_trans_handle *trans,
26402640
}
26412641

26422642
static int insert_dev_extent(struct btrfs_trans_handle *trans,
2643-
struct btrfs_device *device, u64 chunk_offset,
2644-
u64 start, u64 num_bytes)
2643+
const struct btrfs_device *device, u64 chunk_offset,
2644+
u64 start, u64 num_bytes)
26452645
{
26462646
struct btrfs_fs_info *fs_info = device->fs_info;
26472647
struct btrfs_root *root = fs_info->dev_root;
@@ -2817,7 +2817,7 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans)
28172817
* For extent tree v2 we use the block_group_item->chunk_offset to point at our
28182818
* global root id. For v1 it's always set to BTRFS_FIRST_CHUNK_TREE_OBJECTID.
28192819
*/
2820-
static u64 calculate_global_root_id(struct btrfs_fs_info *fs_info, u64 offset)
2820+
static u64 calculate_global_root_id(const struct btrfs_fs_info *fs_info, u64 offset)
28212821
{
28222822
u64 div = SZ_1G;
28232823
u64 index;
@@ -3842,8 +3842,8 @@ static void force_metadata_allocation(struct btrfs_fs_info *info)
38423842
}
38433843
}
38443844

3845-
static int should_alloc_chunk(struct btrfs_fs_info *fs_info,
3846-
struct btrfs_space_info *sinfo, int force)
3845+
static int should_alloc_chunk(const struct btrfs_fs_info *fs_info,
3846+
const struct btrfs_space_info *sinfo, int force)
38473847
{
38483848
u64 bytes_used = btrfs_space_info_used(sinfo, false);
38493849
u64 thresh;
@@ -4218,7 +4218,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
42184218
return ret;
42194219
}
42204220

4221-
static u64 get_profile_num_devs(struct btrfs_fs_info *fs_info, u64 type)
4221+
static u64 get_profile_num_devs(const struct btrfs_fs_info *fs_info, u64 type)
42224222
{
42234223
u64 num_dev;
42244224

@@ -4622,7 +4622,7 @@ int btrfs_use_block_group_size_class(struct btrfs_block_group *bg,
46224622
return 0;
46234623
}
46244624

4625-
bool btrfs_block_group_should_use_size_class(struct btrfs_block_group *bg)
4625+
bool btrfs_block_group_should_use_size_class(const struct btrfs_block_group *bg)
46264626
{
46274627
if (btrfs_is_zoned(bg->fs_info))
46284628
return false;

0 commit comments

Comments
 (0)