Skip to content

Commit 030f2c6

Browse files
committed
Merge branch 'misc-next' into for-next-next-v6.10-20240607
2 parents add9c20 + 866fb14 commit 030f2c6

File tree

16 files changed

+849
-333
lines changed

16 files changed

+849
-333
lines changed

fs/btrfs/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
# misc-next marker
23

34
config BTRFS_FS
45
tristate "Btrfs filesystem support"

fs/btrfs/block-group.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,24 +1764,21 @@ static inline bool btrfs_should_reclaim(struct btrfs_fs_info *fs_info)
17641764

17651765
static bool should_reclaim_block_group(struct btrfs_block_group *bg, u64 bytes_freed)
17661766
{
1767-
const struct btrfs_space_info *space_info = bg->space_info;
1768-
const int reclaim_thresh = READ_ONCE(space_info->bg_reclaim_threshold);
1767+
const int thresh_pct = btrfs_calc_reclaim_threshold(bg->space_info);
1768+
u64 thresh_bytes = mult_perc(bg->length, thresh_pct);
17691769
const u64 new_val = bg->used;
17701770
const u64 old_val = new_val + bytes_freed;
1771-
u64 thresh;
17721771

1773-
if (reclaim_thresh == 0)
1772+
if (thresh_bytes == 0)
17741773
return false;
17751774

1776-
thresh = mult_perc(bg->length, reclaim_thresh);
1777-
17781775
/*
17791776
* If we were below the threshold before don't reclaim, we are likely a
17801777
* brand new block group and we don't want to relocate new block groups.
17811778
*/
1782-
if (old_val < thresh)
1779+
if (old_val < thresh_bytes)
17831780
return false;
1784-
if (new_val >= thresh)
1781+
if (new_val >= thresh_bytes)
17851782
return false;
17861783
return true;
17871784
}
@@ -1828,6 +1825,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
18281825
list_sort(NULL, &fs_info->reclaim_bgs, reclaim_bgs_cmp);
18291826
while (!list_empty(&fs_info->reclaim_bgs)) {
18301827
u64 zone_unusable;
1828+
u64 reclaimed;
18311829
int ret = 0;
18321830

18331831
bg = list_first_entry(&fs_info->reclaim_bgs,
@@ -1841,6 +1839,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
18411839
/* Don't race with allocators so take the groups_sem */
18421840
down_write(&space_info->groups_sem);
18431841

1842+
spin_lock(&space_info->lock);
18441843
spin_lock(&bg->lock);
18451844
if (bg->reserved || bg->pinned || bg->ro) {
18461845
/*
@@ -1850,6 +1849,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
18501849
* this block group.
18511850
*/
18521851
spin_unlock(&bg->lock);
1852+
spin_unlock(&space_info->lock);
18531853
up_write(&space_info->groups_sem);
18541854
goto next;
18551855
}
@@ -1868,6 +1868,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
18681868
if (!btrfs_test_opt(fs_info, DISCARD_ASYNC))
18691869
btrfs_mark_bg_unused(bg);
18701870
spin_unlock(&bg->lock);
1871+
spin_unlock(&space_info->lock);
18711872
up_write(&space_info->groups_sem);
18721873
goto next;
18731874

@@ -1884,10 +1885,12 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
18841885
*/
18851886
if (!should_reclaim_block_group(bg, bg->length)) {
18861887
spin_unlock(&bg->lock);
1888+
spin_unlock(&space_info->lock);
18871889
up_write(&space_info->groups_sem);
18881890
goto next;
18891891
}
18901892
spin_unlock(&bg->lock);
1893+
spin_unlock(&space_info->lock);
18911894

18921895
/*
18931896
* Get out fast, in case we're read-only or unmounting the
@@ -1920,15 +1923,26 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
19201923
div64_u64(bg->used * 100, bg->length),
19211924
div64_u64(zone_unusable * 100, bg->length));
19221925
trace_btrfs_reclaim_block_group(bg);
1926+
reclaimed = bg->used;
19231927
ret = btrfs_relocate_chunk(fs_info, bg->start);
19241928
if (ret) {
19251929
btrfs_dec_block_group_ro(bg);
19261930
btrfs_err(fs_info, "error relocating chunk %llu",
19271931
bg->start);
1932+
spin_lock(&space_info->lock);
1933+
space_info->reclaim_count++;
1934+
if (READ_ONCE(space_info->periodic_reclaim))
1935+
space_info->periodic_reclaim_ready = false;
1936+
spin_unlock(&space_info->lock);
1937+
} else {
1938+
spin_lock(&space_info->lock);
1939+
space_info->reclaim_count++;
1940+
space_info->reclaim_bytes += reclaimed;
1941+
spin_unlock(&space_info->lock);
19281942
}
19291943

19301944
next:
1931-
if (ret)
1945+
if (ret && !READ_ONCE(space_info->periodic_reclaim))
19321946
btrfs_mark_bg_to_reclaim(bg);
19331947
btrfs_put_block_group(bg);
19341948

@@ -1955,6 +1969,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
19551969

19561970
void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info)
19571971
{
1972+
btrfs_reclaim_sweep(fs_info);
19581973
spin_lock(&fs_info->unused_bgs_lock);
19591974
if (!list_empty(&fs_info->reclaim_bgs))
19601975
queue_work(system_unbound_wq, &fs_info->reclaim_bgs_work);
@@ -3653,9 +3668,12 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans,
36533668
old_val += num_bytes;
36543669
cache->used = old_val;
36553670
cache->reserved -= num_bytes;
3671+
cache->reclaim_mark = 0;
36563672
space_info->bytes_reserved -= num_bytes;
36573673
space_info->bytes_used += num_bytes;
36583674
space_info->disk_used += num_bytes * factor;
3675+
if (READ_ONCE(space_info->periodic_reclaim))
3676+
btrfs_space_info_update_reclaimable(space_info, -num_bytes);
36593677
spin_unlock(&cache->lock);
36603678
spin_unlock(&space_info->lock);
36613679
} else {
@@ -3665,8 +3683,10 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans,
36653683
btrfs_space_info_update_bytes_pinned(info, space_info, num_bytes);
36663684
space_info->bytes_used -= num_bytes;
36673685
space_info->disk_used -= num_bytes * factor;
3668-
3669-
reclaim = should_reclaim_block_group(cache, num_bytes);
3686+
if (READ_ONCE(space_info->periodic_reclaim))
3687+
btrfs_space_info_update_reclaimable(space_info, num_bytes);
3688+
else
3689+
reclaim = should_reclaim_block_group(cache, num_bytes);
36703690

36713691
spin_unlock(&cache->lock);
36723692
spin_unlock(&space_info->lock);

fs/btrfs/block-group.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ struct btrfs_block_group {
263263
struct work_struct zone_finish_work;
264264
struct extent_buffer *last_eb;
265265
enum btrfs_block_group_size_class size_class;
266+
u64 reclaim_mark;
266267
};
267268

268269
static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group)

fs/btrfs/compression.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ static inline unsigned int btrfs_compress_level(unsigned int type_level)
8282
return ((type_level & 0xF0) >> 4);
8383
}
8484

85+
/* @range_end must be exclusive. */
86+
static inline u32 btrfs_calc_input_length(u64 range_end, u64 cur)
87+
{
88+
u64 page_end = round_down(cur, PAGE_SIZE) + PAGE_SIZE;
89+
90+
return min(range_end, page_end) - cur;
91+
}
92+
8593
int __init btrfs_init_compress(void);
8694
void __cold btrfs_exit_compress(void);
8795

fs/btrfs/ctree.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,12 +1551,7 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
15511551
if (ret) {
15521552
free_extent_buffer(tmp);
15531553
btrfs_release_path(p);
1554-
return -EIO;
1555-
}
1556-
if (btrfs_check_eb_owner(tmp, btrfs_root_id(root))) {
1557-
free_extent_buffer(tmp);
1558-
btrfs_release_path(p);
1559-
return -EUCLEAN;
1554+
return ret;
15601555
}
15611556

15621557
if (unlock_up)

fs/btrfs/disk-io.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,6 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
635635
free_extent_buffer_stale(buf);
636636
return ERR_PTR(ret);
637637
}
638-
if (btrfs_check_eb_owner(buf, check->owner_root)) {
639-
free_extent_buffer_stale(buf);
640-
return ERR_PTR(-EUCLEAN);
641-
}
642638
return buf;
643639

644640
}

0 commit comments

Comments
 (0)