Skip to content

Commit 57b1482

Browse files
committed
Merge tag 'for-6.11-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull more btrfs fixes from David Sterba: "A more fixes. We got reports that shrinker added in 6.10 still causes latency spikes and the fixes don't handle all corner cases. Due to summer holidays we're taking a shortcut to disable it for release builds and will fix it in the near future. - only enable extent map shrinker for DEBUG builds, temporary quick fix to avoid latency spikes for regular builds - update target inode's ctime on unlink, mandated by POSIX - properly take lock to read/update block group's zoned variables - add counted_by() annotations" * tag 'for-6.11-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: only enable extent map shrinker for DEBUG builds btrfs: zoned: properly take lock to read/update block group's zoned variables btrfs: tree-checker: add dev extent item checks btrfs: update target inode's ctime on unlink btrfs: send: annotate struct name_cache_entry with __counted_by()
2 parents 3c0da3d + 534f7ef commit 57b1482

File tree

5 files changed

+86
-8
lines changed

5 files changed

+86
-8
lines changed

fs/btrfs/free-space-cache.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,15 +2697,16 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
26972697
u64 offset = bytenr - block_group->start;
26982698
u64 to_free, to_unusable;
26992699
int bg_reclaim_threshold = 0;
2700-
bool initial = ((size == block_group->length) && (block_group->alloc_offset == 0));
2700+
bool initial;
27012701
u64 reclaimable_unusable;
27022702

2703-
WARN_ON(!initial && offset + size > block_group->zone_capacity);
2703+
spin_lock(&block_group->lock);
27042704

2705+
initial = ((size == block_group->length) && (block_group->alloc_offset == 0));
2706+
WARN_ON(!initial && offset + size > block_group->zone_capacity);
27052707
if (!initial)
27062708
bg_reclaim_threshold = READ_ONCE(sinfo->bg_reclaim_threshold);
27072709

2708-
spin_lock(&ctl->tree_lock);
27092710
if (!used)
27102711
to_free = size;
27112712
else if (initial)
@@ -2718,7 +2719,9 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
27182719
to_free = offset + size - block_group->alloc_offset;
27192720
to_unusable = size - to_free;
27202721

2722+
spin_lock(&ctl->tree_lock);
27212723
ctl->free_space += to_free;
2724+
spin_unlock(&ctl->tree_lock);
27222725
/*
27232726
* If the block group is read-only, we should account freed space into
27242727
* bytes_readonly.
@@ -2727,11 +2730,8 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
27272730
block_group->zone_unusable += to_unusable;
27282731
WARN_ON(block_group->zone_unusable > block_group->length);
27292732
}
2730-
spin_unlock(&ctl->tree_lock);
27312733
if (!used) {
2732-
spin_lock(&block_group->lock);
27332734
block_group->alloc_offset -= size;
2734-
spin_unlock(&block_group->lock);
27352735
}
27362736

27372737
reclaimable_unusable = block_group->zone_unusable -
@@ -2745,6 +2745,8 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
27452745
btrfs_mark_bg_to_reclaim(block_group);
27462746
}
27472747

2748+
spin_unlock(&block_group->lock);
2749+
27482750
return 0;
27492751
}
27502752

fs/btrfs/inode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,6 +4195,7 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans,
41954195

41964196
btrfs_i_size_write(dir, dir->vfs_inode.i_size - name->len * 2);
41974197
inode_inc_iversion(&inode->vfs_inode);
4198+
inode_set_ctime_current(&inode->vfs_inode);
41984199
inode_inc_iversion(&dir->vfs_inode);
41994200
inode_set_mtime_to_ts(&dir->vfs_inode, inode_set_ctime_current(&dir->vfs_inode));
42004201
ret = btrfs_update_inode(trans, dir);

fs/btrfs/send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ struct name_cache_entry {
347347
int ret;
348348
int need_later_update;
349349
int name_len;
350-
char name[];
350+
char name[] __counted_by(name_len);
351351
};
352352

353353
/* See the comment at lru_cache.h about struct btrfs_lru_cache_entry. */

fs/btrfs/super.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,13 @@ static long btrfs_nr_cached_objects(struct super_block *sb, struct shrink_contro
24022402

24032403
trace_btrfs_extent_map_shrinker_count(fs_info, nr);
24042404

2405-
return nr;
2405+
/*
2406+
* Only report the real number for DEBUG builds, as there are reports of
2407+
* serious performance degradation caused by too frequent shrinks.
2408+
*/
2409+
if (IS_ENABLED(CONFIG_BTRFS_DEBUG))
2410+
return nr;
2411+
return 0;
24062412
}
24072413

24082414
static long btrfs_free_cached_objects(struct super_block *sb, struct shrink_control *sc)

fs/btrfs/tree-checker.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,72 @@ static int check_raid_stripe_extent(const struct extent_buffer *leaf,
17641764
return 0;
17651765
}
17661766

1767+
static int check_dev_extent_item(const struct extent_buffer *leaf,
1768+
const struct btrfs_key *key,
1769+
int slot,
1770+
struct btrfs_key *prev_key)
1771+
{
1772+
struct btrfs_dev_extent *de;
1773+
const u32 sectorsize = leaf->fs_info->sectorsize;
1774+
1775+
de = btrfs_item_ptr(leaf, slot, struct btrfs_dev_extent);
1776+
/* Basic fixed member checks. */
1777+
if (unlikely(btrfs_dev_extent_chunk_tree(leaf, de) !=
1778+
BTRFS_CHUNK_TREE_OBJECTID)) {
1779+
generic_err(leaf, slot,
1780+
"invalid dev extent chunk tree id, has %llu expect %llu",
1781+
btrfs_dev_extent_chunk_tree(leaf, de),
1782+
BTRFS_CHUNK_TREE_OBJECTID);
1783+
return -EUCLEAN;
1784+
}
1785+
if (unlikely(btrfs_dev_extent_chunk_objectid(leaf, de) !=
1786+
BTRFS_FIRST_CHUNK_TREE_OBJECTID)) {
1787+
generic_err(leaf, slot,
1788+
"invalid dev extent chunk objectid, has %llu expect %llu",
1789+
btrfs_dev_extent_chunk_objectid(leaf, de),
1790+
BTRFS_FIRST_CHUNK_TREE_OBJECTID);
1791+
return -EUCLEAN;
1792+
}
1793+
/* Alignment check. */
1794+
if (unlikely(!IS_ALIGNED(key->offset, sectorsize))) {
1795+
generic_err(leaf, slot,
1796+
"invalid dev extent key.offset, has %llu not aligned to %u",
1797+
key->offset, sectorsize);
1798+
return -EUCLEAN;
1799+
}
1800+
if (unlikely(!IS_ALIGNED(btrfs_dev_extent_chunk_offset(leaf, de),
1801+
sectorsize))) {
1802+
generic_err(leaf, slot,
1803+
"invalid dev extent chunk offset, has %llu not aligned to %u",
1804+
btrfs_dev_extent_chunk_objectid(leaf, de),
1805+
sectorsize);
1806+
return -EUCLEAN;
1807+
}
1808+
if (unlikely(!IS_ALIGNED(btrfs_dev_extent_length(leaf, de),
1809+
sectorsize))) {
1810+
generic_err(leaf, slot,
1811+
"invalid dev extent length, has %llu not aligned to %u",
1812+
btrfs_dev_extent_length(leaf, de), sectorsize);
1813+
return -EUCLEAN;
1814+
}
1815+
/* Overlap check with previous dev extent. */
1816+
if (slot && prev_key->objectid == key->objectid &&
1817+
prev_key->type == key->type) {
1818+
struct btrfs_dev_extent *prev_de;
1819+
u64 prev_len;
1820+
1821+
prev_de = btrfs_item_ptr(leaf, slot - 1, struct btrfs_dev_extent);
1822+
prev_len = btrfs_dev_extent_length(leaf, prev_de);
1823+
if (unlikely(prev_key->offset + prev_len > key->offset)) {
1824+
generic_err(leaf, slot,
1825+
"dev extent overlap, prev offset %llu len %llu current offset %llu",
1826+
prev_key->objectid, prev_len, key->offset);
1827+
return -EUCLEAN;
1828+
}
1829+
}
1830+
return 0;
1831+
}
1832+
17671833
/*
17681834
* Common point to switch the item-specific validation.
17691835
*/
@@ -1800,6 +1866,9 @@ static enum btrfs_tree_block_status check_leaf_item(struct extent_buffer *leaf,
18001866
case BTRFS_DEV_ITEM_KEY:
18011867
ret = check_dev_item(leaf, key, slot);
18021868
break;
1869+
case BTRFS_DEV_EXTENT_KEY:
1870+
ret = check_dev_extent_item(leaf, key, slot, prev_key);
1871+
break;
18031872
case BTRFS_INODE_ITEM_KEY:
18041873
ret = check_inode_item(leaf, key, slot);
18051874
break;

0 commit comments

Comments
 (0)