Skip to content

Commit 2850630

Browse files
committed
Merge tag 'for-6.3-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "A few more fixes, the zoned accounting fix is spread across a few patches, preparatory and the actual fixes: - zoned mode: - fix accounting of unusable zone space - fix zone activation condition for DUP profile - preparatory patches - improved error handling of missing chunks - fix compiler warning" * tag 'for-6.3-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: zoned: drop space_info->active_total_bytes btrfs: zoned: count fresh BG region as zone unusable btrfs: use temporary variable for space_info in btrfs_update_block_group btrfs: rename BTRFS_FS_NO_OVERCOMMIT to BTRFS_FS_ACTIVE_ZONE_TRACKING btrfs: zoned: fix btrfs_can_activate_zone() to support DUP profile btrfs: fix compiler warning on SPARC/PA-RISC handling fscrypt_setup_filename btrfs: handle missing chunk mapping more gracefully
2 parents 6dd74c5 + e15acc2 commit 2850630

File tree

8 files changed

+71
-71
lines changed

8 files changed

+71
-71
lines changed

fs/btrfs/block-group.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,14 +1175,8 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
11751175
< block_group->zone_unusable);
11761176
WARN_ON(block_group->space_info->disk_total
11771177
< block_group->length * factor);
1178-
WARN_ON(test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE,
1179-
&block_group->runtime_flags) &&
1180-
block_group->space_info->active_total_bytes
1181-
< block_group->length);
11821178
}
11831179
block_group->space_info->total_bytes -= block_group->length;
1184-
if (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags))
1185-
block_group->space_info->active_total_bytes -= block_group->length;
11861180
block_group->space_info->bytes_readonly -=
11871181
(block_group->length - block_group->zone_unusable);
11881182
block_group->space_info->bytes_zone_unusable -=
@@ -3476,13 +3470,15 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans,
34763470
spin_unlock(&info->delalloc_root_lock);
34773471

34783472
while (total) {
3473+
struct btrfs_space_info *space_info;
34793474
bool reclaim = false;
34803475

34813476
cache = btrfs_lookup_block_group(info, bytenr);
34823477
if (!cache) {
34833478
ret = -ENOENT;
34843479
break;
34853480
}
3481+
space_info = cache->space_info;
34863482
factor = btrfs_bg_type_to_factor(cache->flags);
34873483

34883484
/*
@@ -3497,7 +3493,7 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans,
34973493
byte_in_group = bytenr - cache->start;
34983494
WARN_ON(byte_in_group > cache->length);
34993495

3500-
spin_lock(&cache->space_info->lock);
3496+
spin_lock(&space_info->lock);
35013497
spin_lock(&cache->lock);
35023498

35033499
if (btrfs_test_opt(info, SPACE_CACHE) &&
@@ -3510,24 +3506,24 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans,
35103506
old_val += num_bytes;
35113507
cache->used = old_val;
35123508
cache->reserved -= num_bytes;
3513-
cache->space_info->bytes_reserved -= num_bytes;
3514-
cache->space_info->bytes_used += num_bytes;
3515-
cache->space_info->disk_used += num_bytes * factor;
3509+
space_info->bytes_reserved -= num_bytes;
3510+
space_info->bytes_used += num_bytes;
3511+
space_info->disk_used += num_bytes * factor;
35163512
spin_unlock(&cache->lock);
3517-
spin_unlock(&cache->space_info->lock);
3513+
spin_unlock(&space_info->lock);
35183514
} else {
35193515
old_val -= num_bytes;
35203516
cache->used = old_val;
35213517
cache->pinned += num_bytes;
3522-
btrfs_space_info_update_bytes_pinned(info,
3523-
cache->space_info, num_bytes);
3524-
cache->space_info->bytes_used -= num_bytes;
3525-
cache->space_info->disk_used -= num_bytes * factor;
3518+
btrfs_space_info_update_bytes_pinned(info, space_info,
3519+
num_bytes);
3520+
space_info->bytes_used -= num_bytes;
3521+
space_info->disk_used -= num_bytes * factor;
35263522

35273523
reclaim = should_reclaim_block_group(cache, num_bytes);
35283524

35293525
spin_unlock(&cache->lock);
3530-
spin_unlock(&cache->space_info->lock);
3526+
spin_unlock(&space_info->lock);
35313527

35323528
set_extent_dirty(&trans->transaction->pinned_extents,
35333529
bytenr, bytenr + num_bytes - 1,

fs/btrfs/free-space-cache.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2693,8 +2693,13 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
26932693
bg_reclaim_threshold = READ_ONCE(sinfo->bg_reclaim_threshold);
26942694

26952695
spin_lock(&ctl->tree_lock);
2696+
/* Count initial region as zone_unusable until it gets activated. */
26962697
if (!used)
26972698
to_free = size;
2699+
else if (initial &&
2700+
test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &block_group->fs_info->flags) &&
2701+
(block_group->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM)))
2702+
to_free = 0;
26982703
else if (initial)
26992704
to_free = block_group->zone_capacity;
27002705
else if (offset >= block_group->alloc_offset)
@@ -2722,7 +2727,8 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
27222727
reclaimable_unusable = block_group->zone_unusable -
27232728
(block_group->length - block_group->zone_capacity);
27242729
/* All the region is now unusable. Mark it as unused and reclaim */
2725-
if (block_group->zone_unusable == block_group->length) {
2730+
if (block_group->zone_unusable == block_group->length &&
2731+
block_group->alloc_offset) {
27262732
btrfs_mark_bg_unused(block_group);
27272733
} else if (bg_reclaim_threshold &&
27282734
reclaimable_unusable >=

fs/btrfs/fs.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ enum {
120120
/* Indicate that we want to commit the transaction. */
121121
BTRFS_FS_NEED_TRANS_COMMIT,
122122

123-
/*
124-
* Indicate metadata over-commit is disabled. This is set when active
125-
* zone tracking is needed.
126-
*/
127-
BTRFS_FS_NO_OVERCOMMIT,
123+
/* This is set when active zone tracking is needed. */
124+
BTRFS_FS_ACTIVE_ZONE_TRACKING,
128125

129126
/*
130127
* Indicate if we have some features changed, this is mostly for

fs/btrfs/inode.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5421,8 +5421,13 @@ static int btrfs_inode_by_name(struct btrfs_inode *dir, struct dentry *dentry,
54215421
return -ENOMEM;
54225422

54235423
ret = fscrypt_setup_filename(&dir->vfs_inode, &dentry->d_name, 1, &fname);
5424-
if (ret)
5424+
if (ret < 0)
54255425
goto out;
5426+
/*
5427+
* fscrypt_setup_filename() should never return a positive value, but
5428+
* gcc on sparc/parisc thinks it can, so assert that doesn't happen.
5429+
*/
5430+
ASSERT(ret == 0);
54265431

54275432
/* This needs to handle no-key deletions later on */
54285433

fs/btrfs/space-info.c

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
308308
ASSERT(found);
309309
spin_lock(&found->lock);
310310
found->total_bytes += block_group->length;
311-
if (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags))
312-
found->active_total_bytes += block_group->length;
313311
found->disk_total += block_group->length * factor;
314312
found->bytes_used += block_group->used;
315313
found->disk_used += block_group->used * factor;
@@ -379,22 +377,6 @@ static u64 calc_available_free_space(struct btrfs_fs_info *fs_info,
379377
return avail;
380378
}
381379

382-
static inline u64 writable_total_bytes(struct btrfs_fs_info *fs_info,
383-
struct btrfs_space_info *space_info)
384-
{
385-
/*
386-
* On regular filesystem, all total_bytes are always writable. On zoned
387-
* filesystem, there may be a limitation imposed by max_active_zones.
388-
* For metadata allocation, we cannot finish an existing active block
389-
* group to avoid a deadlock. Thus, we need to consider only the active
390-
* groups to be writable for metadata space.
391-
*/
392-
if (!btrfs_is_zoned(fs_info) || (space_info->flags & BTRFS_BLOCK_GROUP_DATA))
393-
return space_info->total_bytes;
394-
395-
return space_info->active_total_bytes;
396-
}
397-
398380
int btrfs_can_overcommit(struct btrfs_fs_info *fs_info,
399381
struct btrfs_space_info *space_info, u64 bytes,
400382
enum btrfs_reserve_flush_enum flush)
@@ -407,13 +389,13 @@ int btrfs_can_overcommit(struct btrfs_fs_info *fs_info,
407389
return 0;
408390

409391
used = btrfs_space_info_used(space_info, true);
410-
if (test_bit(BTRFS_FS_NO_OVERCOMMIT, &fs_info->flags) &&
392+
if (test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &fs_info->flags) &&
411393
(space_info->flags & BTRFS_BLOCK_GROUP_METADATA))
412394
avail = 0;
413395
else
414396
avail = calc_available_free_space(fs_info, space_info, flush);
415397

416-
if (used + bytes < writable_total_bytes(fs_info, space_info) + avail)
398+
if (used + bytes < space_info->total_bytes + avail)
417399
return 1;
418400
return 0;
419401
}
@@ -449,7 +431,7 @@ void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info,
449431
ticket = list_first_entry(head, struct reserve_ticket, list);
450432

451433
/* Check and see if our ticket can be satisfied now. */
452-
if ((used + ticket->bytes <= writable_total_bytes(fs_info, space_info)) ||
434+
if ((used + ticket->bytes <= space_info->total_bytes) ||
453435
btrfs_can_overcommit(fs_info, space_info, ticket->bytes,
454436
flush)) {
455437
btrfs_space_info_update_bytes_may_use(fs_info,
@@ -829,7 +811,6 @@ btrfs_calc_reclaim_metadata_size(struct btrfs_fs_info *fs_info,
829811
{
830812
u64 used;
831813
u64 avail;
832-
u64 total;
833814
u64 to_reclaim = space_info->reclaim_size;
834815

835816
lockdep_assert_held(&space_info->lock);
@@ -844,9 +825,8 @@ btrfs_calc_reclaim_metadata_size(struct btrfs_fs_info *fs_info,
844825
* space. If that's the case add in our overage so we make sure to put
845826
* appropriate pressure on the flushing state machine.
846827
*/
847-
total = writable_total_bytes(fs_info, space_info);
848-
if (total + avail < used)
849-
to_reclaim += used - (total + avail);
828+
if (space_info->total_bytes + avail < used)
829+
to_reclaim += used - (space_info->total_bytes + avail);
850830

851831
return to_reclaim;
852832
}
@@ -856,11 +836,10 @@ static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info,
856836
{
857837
u64 global_rsv_size = fs_info->global_block_rsv.reserved;
858838
u64 ordered, delalloc;
859-
u64 total = writable_total_bytes(fs_info, space_info);
860839
u64 thresh;
861840
u64 used;
862841

863-
thresh = mult_perc(total, 90);
842+
thresh = mult_perc(space_info->total_bytes, 90);
864843

865844
lockdep_assert_held(&space_info->lock);
866845

@@ -923,8 +902,8 @@ static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info,
923902
BTRFS_RESERVE_FLUSH_ALL);
924903
used = space_info->bytes_used + space_info->bytes_reserved +
925904
space_info->bytes_readonly + global_rsv_size;
926-
if (used < total)
927-
thresh += total - used;
905+
if (used < space_info->total_bytes)
906+
thresh += space_info->total_bytes - used;
928907
thresh >>= space_info->clamp;
929908

930909
used = space_info->bytes_pinned;
@@ -1651,7 +1630,7 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info,
16511630
* can_overcommit() to ensure we can overcommit to continue.
16521631
*/
16531632
if (!pending_tickets &&
1654-
((used + orig_bytes <= writable_total_bytes(fs_info, space_info)) ||
1633+
((used + orig_bytes <= space_info->total_bytes) ||
16551634
btrfs_can_overcommit(fs_info, space_info, orig_bytes, flush))) {
16561635
btrfs_space_info_update_bytes_may_use(fs_info, space_info,
16571636
orig_bytes);
@@ -1665,8 +1644,7 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info,
16651644
*/
16661645
if (ret && unlikely(flush == BTRFS_RESERVE_FLUSH_EMERGENCY)) {
16671646
used = btrfs_space_info_used(space_info, false);
1668-
if (used + orig_bytes <=
1669-
writable_total_bytes(fs_info, space_info)) {
1647+
if (used + orig_bytes <= space_info->total_bytes) {
16701648
btrfs_space_info_update_bytes_may_use(fs_info, space_info,
16711649
orig_bytes);
16721650
ret = 0;

fs/btrfs/space-info.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ struct btrfs_space_info {
9696
u64 bytes_may_use; /* number of bytes that may be used for
9797
delalloc/allocations */
9898
u64 bytes_readonly; /* total bytes that are read only */
99-
/* Total bytes in the space, but only accounts active block groups. */
100-
u64 active_total_bytes;
10199
u64 bytes_zone_unusable; /* total bytes that are unusable until
102100
resetting the device zone */
103101

fs/btrfs/volumes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6363,7 +6363,8 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
63636363
ASSERT(op != BTRFS_MAP_DISCARD);
63646364

63656365
em = btrfs_get_chunk_map(fs_info, logical, *length);
6366-
ASSERT(!IS_ERR(em));
6366+
if (IS_ERR(em))
6367+
return PTR_ERR(em);
63676368

63686369
map = em->map_lookup;
63696370
data_stripes = nr_data_stripes(map);

fs/btrfs/zoned.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
524524
}
525525
atomic_set(&zone_info->active_zones_left,
526526
max_active_zones - nactive);
527-
/* Overcommit does not work well with active zone tacking. */
528-
set_bit(BTRFS_FS_NO_OVERCOMMIT, &fs_info->flags);
527+
set_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &fs_info->flags);
529528
}
530529

531530
/* Validate superblock log */
@@ -1581,9 +1580,19 @@ void btrfs_calc_zone_unusable(struct btrfs_block_group *cache)
15811580
return;
15821581

15831582
WARN_ON(cache->bytes_super != 0);
1584-
unusable = (cache->alloc_offset - cache->used) +
1585-
(cache->length - cache->zone_capacity);
1586-
free = cache->zone_capacity - cache->alloc_offset;
1583+
1584+
/* Check for block groups never get activated */
1585+
if (test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &cache->fs_info->flags) &&
1586+
cache->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM) &&
1587+
!test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &cache->runtime_flags) &&
1588+
cache->alloc_offset == 0) {
1589+
unusable = cache->length;
1590+
free = 0;
1591+
} else {
1592+
unusable = (cache->alloc_offset - cache->used) +
1593+
(cache->length - cache->zone_capacity);
1594+
free = cache->zone_capacity - cache->alloc_offset;
1595+
}
15871596

15881597
/* We only need ->free_space in ALLOC_SEQ block groups */
15891598
cache->cached = BTRFS_CACHE_FINISHED;
@@ -1902,7 +1911,11 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)
19021911

19031912
/* Successfully activated all the zones */
19041913
set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags);
1905-
space_info->active_total_bytes += block_group->length;
1914+
WARN_ON(block_group->alloc_offset != 0);
1915+
if (block_group->zone_unusable == block_group->length) {
1916+
block_group->zone_unusable = block_group->length - block_group->zone_capacity;
1917+
space_info->bytes_zone_unusable -= block_group->zone_capacity;
1918+
}
19061919
spin_unlock(&block_group->lock);
19071920
btrfs_try_granting_tickets(fs_info, space_info);
19081921
spin_unlock(&space_info->lock);
@@ -2086,11 +2099,21 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
20862099
if (!device->bdev)
20872100
continue;
20882101

2089-
if (!zinfo->max_active_zones ||
2090-
atomic_read(&zinfo->active_zones_left)) {
2102+
if (!zinfo->max_active_zones) {
20912103
ret = true;
20922104
break;
20932105
}
2106+
2107+
switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
2108+
case 0: /* single */
2109+
ret = (atomic_read(&zinfo->active_zones_left) >= 1);
2110+
break;
2111+
case BTRFS_BLOCK_GROUP_DUP:
2112+
ret = (atomic_read(&zinfo->active_zones_left) >= 2);
2113+
break;
2114+
}
2115+
if (ret)
2116+
break;
20942117
}
20952118
mutex_unlock(&fs_info->chunk_mutex);
20962119

@@ -2256,7 +2279,7 @@ int btrfs_zone_finish_one_bg(struct btrfs_fs_info *fs_info)
22562279
u64 avail;
22572280

22582281
spin_lock(&block_group->lock);
2259-
if (block_group->reserved ||
2282+
if (block_group->reserved || block_group->alloc_offset == 0 ||
22602283
(block_group->flags & BTRFS_BLOCK_GROUP_SYSTEM)) {
22612284
spin_unlock(&block_group->lock);
22622285
continue;
@@ -2293,10 +2316,6 @@ int btrfs_zoned_activate_one_bg(struct btrfs_fs_info *fs_info,
22932316
if (!btrfs_is_zoned(fs_info) || (space_info->flags & BTRFS_BLOCK_GROUP_DATA))
22942317
return 0;
22952318

2296-
/* No more block groups to activate */
2297-
if (space_info->active_total_bytes == space_info->total_bytes)
2298-
return 0;
2299-
23002319
for (;;) {
23012320
int ret;
23022321
bool need_finish = false;

0 commit comments

Comments
 (0)