Skip to content

Commit db524fd

Browse files
fdmananakdave
authored andcommitted
btrfs: annotate btrfs_is_testing() as unlikely and make it return bool
We can annotate btrfs_is_testing() as unlikely since that's the most expected scenario and it's desirable for the compiler to optimize for the case we are not running the self tests. So add the annotation to btrfs_is_testing() and while at it also make it return bool instead of int. Also make two of the existing callers use btrfs_is_testing() directly instead of storing its result in a local variable. On x86_64 with Debian's gcc 14.2.0-19 this resulted in a very tiny object code reduction. Before this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1913263 161567 15592 2090422 1fe5b6 fs/btrfs/btrfs.ko After this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1913257 161567 15592 2090416 1fe5b0 fs/btrfs/btrfs.ko Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> 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 f07575b commit db524fd

3 files changed

Lines changed: 8 additions & 10 deletions

File tree

fs/btrfs/delayed-ref.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,6 @@ void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans)
12511251
{
12521252
struct btrfs_delayed_ref_root *delayed_refs = &trans->delayed_refs;
12531253
struct btrfs_fs_info *fs_info = trans->fs_info;
1254-
bool testing = btrfs_is_testing(fs_info);
12551254

12561255
spin_lock(&delayed_refs->lock);
12571256
while (true) {
@@ -1281,7 +1280,7 @@ void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans)
12811280
spin_unlock(&delayed_refs->lock);
12821281
mutex_unlock(&head->mutex);
12831282

1284-
if (!testing && pin_bytes) {
1283+
if (!btrfs_is_testing(fs_info) && pin_bytes) {
12851284
struct btrfs_block_group *bg;
12861285

12871286
bg = btrfs_lookup_block_group(fs_info, head->bytenr);
@@ -1312,14 +1311,14 @@ void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans)
13121311
btrfs_error_unpin_extent_range(fs_info, head->bytenr,
13131312
head->bytenr + head->num_bytes - 1);
13141313
}
1315-
if (!testing)
1314+
if (!btrfs_is_testing(fs_info))
13161315
btrfs_cleanup_ref_head_accounting(fs_info, delayed_refs, head);
13171316
btrfs_put_delayed_ref_head(head);
13181317
cond_resched();
13191318
spin_lock(&delayed_refs->lock);
13201319
}
13211320

1322-
if (!testing)
1321+
if (!btrfs_is_testing(fs_info))
13231322
btrfs_qgroup_destroy_extent_records(trans);
13241323

13251324
spin_unlock(&delayed_refs->lock);

fs/btrfs/disk-io.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,6 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
639639
u64 objectid, gfp_t flags)
640640
{
641641
struct btrfs_root *root;
642-
bool dummy = btrfs_is_testing(fs_info);
643642

644643
root = kzalloc(sizeof(*root), flags);
645644
if (!root)
@@ -696,7 +695,7 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
696695
root->log_transid_committed = -1;
697696
btrfs_set_root_last_log_commit(root, 0);
698697
root->anon_dev = 0;
699-
if (!dummy) {
698+
if (!btrfs_is_testing(fs_info)) {
700699
btrfs_extent_io_tree_init(fs_info, &root->dirty_log_pages,
701700
IO_TREE_ROOT_DIRTY_LOG_PAGES);
702701
btrfs_extent_io_tree_init(fs_info, &root->log_csum_range,

fs/btrfs/fs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,9 @@ static inline void btrfs_wake_unfinished_drop(struct btrfs_fs_info *fs_info)
11261126

11271127
#define EXPORT_FOR_TESTS
11281128

1129-
static inline int btrfs_is_testing(const struct btrfs_fs_info *fs_info)
1129+
static inline bool btrfs_is_testing(const struct btrfs_fs_info *fs_info)
11301130
{
1131-
return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
1131+
return unlikely(test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state));
11321132
}
11331133

11341134
void btrfs_test_destroy_inode(struct inode *inode);
@@ -1137,9 +1137,9 @@ void btrfs_test_destroy_inode(struct inode *inode);
11371137

11381138
#define EXPORT_FOR_TESTS static
11391139

1140-
static inline int btrfs_is_testing(const struct btrfs_fs_info *fs_info)
1140+
static inline bool btrfs_is_testing(const struct btrfs_fs_info *fs_info)
11411141
{
1142-
return 0;
1142+
return false;
11431143
}
11441144
#endif
11451145

0 commit comments

Comments
 (0)