Skip to content

Commit 122d032

Browse files
fdmananaboryas
authored andcommitted
btrfs: add missing unlikely to if branches leading to a DEBUG_WARN()
If statement branches that lead to a DEBUG_WARN() are unexpected to happen and in most places we surround their expressions with the unlikely tag, however a few places are missing. Add the unlikely tag to those missing places to make it explicit to a reader that it's not expected and to hint the compiler to generate better code. Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 04de7e4 commit 122d032

7 files changed

Lines changed: 17 additions & 17 deletions

File tree

fs/btrfs/block-group.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4117,7 +4117,7 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type)
41174117
struct btrfs_space_info *space_info;
41184118

41194119
space_info = btrfs_find_space_info(trans->fs_info, type);
4120-
if (!space_info) {
4120+
if (unlikely(!space_info)) {
41214121
DEBUG_WARN();
41224122
return -EINVAL;
41234123
}

fs/btrfs/disk-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4398,7 +4398,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
43984398
ASSERT(list_empty(&fs_info->delayed_iputs));
43994399
set_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags);
44004400

4401-
if (btrfs_check_quota_leak(fs_info)) {
4401+
if (unlikely(btrfs_check_quota_leak(fs_info))) {
44024402
DEBUG_WARN("qgroup reserved space leaked");
44034403
btrfs_err(fs_info, "qgroup reserved space leaked");
44044404
}

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6655,7 +6655,7 @@ static int btrfs_trim_free_extents_throttle(struct btrfs_device *device,
66556655
start = max(start, cur_start);
66566656

66576657
/* Check if there are any CHUNK_* bits left */
6658-
if (start > device->total_bytes) {
6658+
if (unlikely(start > device->total_bytes)) {
66596659
DEBUG_WARN();
66606660
btrfs_warn(fs_info,
66616661
"ignoring attempt to trim beyond device size: offset %llu length %llu device %s device size %llu",

fs/btrfs/free-space-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct btrfs_free_space_info *btrfs_search_free_space_info(
109109
ret = btrfs_search_slot(trans, root, &key, path, 0, cow);
110110
if (ret < 0)
111111
return ERR_PTR(ret);
112-
if (ret != 0) {
112+
if (unlikely(ret != 0)) {
113113
btrfs_warn(fs_info, "missing free space info for %llu",
114114
block_group->start);
115115
DEBUG_WARN();

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ static inline int inode_need_compress(struct btrfs_inode *inode, u64 start,
755755
{
756756
struct btrfs_fs_info *fs_info = inode->root->fs_info;
757757

758-
if (!btrfs_inode_can_compress(inode)) {
758+
if (unlikely(!btrfs_inode_can_compress(inode))) {
759759
DEBUG_WARN("BTRFS: unexpected compression for ino %llu", btrfs_ino(inode));
760760
return 0;
761761
}

fs/btrfs/qgroup.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,9 +1836,9 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
18361836
* Thus its reserved space should all be zero, no matter if qgroup
18371837
* is consistent or the mode.
18381838
*/
1839-
if (qgroup->rsv.values[BTRFS_QGROUP_RSV_DATA] ||
1840-
qgroup->rsv.values[BTRFS_QGROUP_RSV_META_PREALLOC] ||
1841-
qgroup->rsv.values[BTRFS_QGROUP_RSV_META_PERTRANS]) {
1839+
if (unlikely(qgroup->rsv.values[BTRFS_QGROUP_RSV_DATA] ||
1840+
qgroup->rsv.values[BTRFS_QGROUP_RSV_META_PREALLOC] ||
1841+
qgroup->rsv.values[BTRFS_QGROUP_RSV_META_PERTRANS])) {
18421842
DEBUG_WARN();
18431843
btrfs_warn_rl(fs_info,
18441844
"to be deleted qgroup %u/%llu has non-zero numbers, data %llu meta prealloc %llu meta pertrans %llu",
@@ -1857,8 +1857,8 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
18571857
*/
18581858
if (btrfs_qgroup_mode(fs_info) == BTRFS_QGROUP_MODE_FULL &&
18591859
!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)) {
1860-
if (qgroup->rfer || qgroup->excl ||
1861-
qgroup->rfer_cmpr || qgroup->excl_cmpr) {
1860+
if (unlikely(qgroup->rfer || qgroup->excl ||
1861+
qgroup->rfer_cmpr || qgroup->excl_cmpr)) {
18621862
DEBUG_WARN();
18631863
qgroup_mark_inconsistent(fs_info,
18641864
"to be deleted qgroup %u/%llu has non-zero numbers, rfer %llu rfer_cmpr %llu excl %llu excl_cmpr %llu",
@@ -4800,9 +4800,9 @@ int btrfs_qgroup_add_swapped_blocks(struct btrfs_root *subvol_root,
48004800

48014801
entry = rb_entry(node, struct btrfs_qgroup_swapped_block, node);
48024802

4803-
if (entry->subvol_generation != block->subvol_generation ||
4804-
entry->reloc_bytenr != block->reloc_bytenr ||
4805-
entry->reloc_generation != block->reloc_generation) {
4803+
if (unlikely(entry->subvol_generation != block->subvol_generation ||
4804+
entry->reloc_bytenr != block->reloc_bytenr ||
4805+
entry->reloc_generation != block->reloc_generation)) {
48064806
/*
48074807
* Duplicated but mismatch entry found. Shouldn't happen.
48084808
* Marking qgroup inconsistent should be enough for end

fs/btrfs/volumes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6081,7 +6081,7 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
60816081

60826082
lockdep_assert_held(&info->chunk_mutex);
60836083

6084-
if (!alloc_profile_is_valid(type, 0)) {
6084+
if (unlikely(!alloc_profile_is_valid(type, 0))) {
60856085
DEBUG_WARN("invalid alloc profile for type %llu", type);
60866086
return ERR_PTR(-EINVAL);
60876087
}
@@ -6092,7 +6092,7 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
60926092
return ERR_PTR(-ENOSPC);
60936093
}
60946094

6095-
if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) {
6095+
if (unlikely(!(type & BTRFS_BLOCK_GROUP_TYPE_MASK))) {
60966096
btrfs_err(info, "invalid chunk type 0x%llx requested", type);
60976097
DEBUG_WARN();
60986098
return ERR_PTR(-EINVAL);
@@ -6262,7 +6262,7 @@ static noinline int init_first_rw_device(struct btrfs_trans_handle *trans)
62626262

62636263
alloc_profile = btrfs_metadata_alloc_profile(fs_info);
62646264
meta_space_info = btrfs_find_space_info(fs_info, alloc_profile);
6265-
if (!meta_space_info) {
6265+
if (unlikely(!meta_space_info)) {
62666266
DEBUG_WARN();
62676267
return -EINVAL;
62686268
}
@@ -6272,7 +6272,7 @@ static noinline int init_first_rw_device(struct btrfs_trans_handle *trans)
62726272

62736273
alloc_profile = btrfs_system_alloc_profile(fs_info);
62746274
sys_space_info = btrfs_find_space_info(fs_info, alloc_profile);
6275-
if (!sys_space_info) {
6275+
if (unlikely(!sys_space_info)) {
62766276
DEBUG_WARN();
62776277
return -EINVAL;
62786278
}

0 commit comments

Comments
 (0)