btrfs: split btrfs_fs_closing() and change return type to bool
David Sterba
maintainerPATCH 1/1 btrfs: split btrfs_fs_closing() and change return type to bool
There are two tests in btrfs_fs_closing() but checking the BTRFS_FS_CLOSING_DONE bit is done only in one place load_extent_tree_free(). As this is an inline we can reduce size of the generated code. The types can be also changed to bool as this becomes a simple condition.
--- fs/btrfs/block-group.c | 2 +- fs/btrfs/fs.h | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-)
fs/btrfs/block-group.c +1 -1
@@ -761,7 +761,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) nritems =btrfs_header_nritems (leaf);while (1 ) { -if (btrfs_fs_closing (fs_info) >1 ) { +if (btrfs_fs_closing_done (fs_info)) { last = (u64)-1 ;break ; }
fs/btrfs/fs.h +13 -8
@@ -1110,15 +1110,20 @@ void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,#define btrfs_test_opt (fs_info, opt) ((fs_info)->mount_opt & \ BTRFS_MOUNT_##opt) -static inline int btrfs_fs_closing (const struct btrfs_fs_info *fs_info) +static inline bool btrfs_fs_closing (const struct btrfs_fs_info *fs_info) { -/* Do it this way so we only ever do one test_bit in the normal case. */ -if (test_bit (BTRFS_FS_CLOSING_START , &fs_info->flags)) { -if (test_bit (BTRFS_FS_CLOSING_DONE , &fs_info->flags)) -return 2 ; -return 1 ; - } -return 0 ; +if (unlikely (test_bit (BTRFS_FS_CLOSING_START , &fs_info->flags))) +return true; + +return false; +} + +static inline bool btrfs_fs_closing_done (const struct btrfs_fs_info *fs_info) +{ +if (btrfs_fs_closing (fs_info) &&test_bit (BTRFS_FS_CLOSING_DONE , &fs_info->flags)) +return true; + +return false; }/*
Signature · 1 line
2.51.1
Quoted 6 lines · David Sterba
There are two tests in
btrfs_fs_closing()but checking theBTRFS_FS_CLOSING_DONEbit is done only in one placeload_extent_tree_free(). As this is an inline we can reduce size of the generated code. The types can be also changed to bool as this becomes a simple condition.
Can you mention here how much was the reduction?
Quoted 32 lines
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/block-group.c | 2 +- fs/btrfs/fs.h | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-)fs/btrfs/block-group.c +1
-1@@ -761,7 +761,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) nritems =btrfs_header_nritems (leaf);while (1 ) { -if (btrfs_fs_closing (fs_info) >1 ) { +if (btrfs_fs_closing_done (fs_info)) { last = (u64)-1 ;break ; }fs/btrfs/fs.h +1
-2@@ -1110,15 +1110,20 @@ void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,#define btrfs_test_opt (fs_info, opt) ((fs_info)->mount_opt & \ BTRFS_MOUNT_##opt) -static inline int btrfs_fs_closing (const struct btrfs_fs_info *fs_info) +static inline bool btrfs_fs_closing (const struct btrfs_fs_info *fs_info) { -/* Do it this way so we only ever do one test_bit in the normal case. */
fs/btrfs/fs.h void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag, · line 1118
Quoted 10 lines
fs/btrfs/fs.h +4
-6-if (test_bit (BTRFS_FS_CLOSING_START , &fs_info->flags)) { -if (test_bit (BTRFS_FS_CLOSING_DONE , &fs_info->flags)) -return 2 ; -return 1 ; - } -return 0 ; +if (unlikely (test_bit (BTRFS_FS_CLOSING_START , &fs_info->flags))) +return true; + +return false;
This can simply be:
return unlikely(test_bit(BTRFS_FS_CLOSING_START, &fs_info->flags));
Thanks.
Quoted 15 lines
fs/btrfs/fs.h +8
-1+} + +static inline bool btrfs_fs_closing_done (const struct btrfs_fs_info *fs_info) +{ +if (btrfs_fs_closing (fs_info) &&test_bit (BTRFS_FS_CLOSING_DONE , &fs_info->flags)) +return true; + +return false; }/* -- 2.51.1
Quoted 9 lines · Filipe Manana
Quoted 6 lines · David Sterba
There are two tests in
btrfs_fs_closing()but checking theBTRFS_FS_CLOSING_DONEbit is done only in one placeload_extent_tree_free(). As this is an inline we can reduce size of the generated code. The types can be also changed to bool as this becomes a simple condition.Can you mention here how much was the reduction?
text data bss dec hex filename 1674006 146704 15560 1836270 1c04ee pre/btrfs.ko 1673772 146704 15560 1836036 1c0404 post/btrfs.ko
DELTA: -234
The code seems to be reorganized in bigger blocks where the unlikely hint applies and in summary it's shorter also due the function aligment removals.
The stack diff is not notable:
btrfs_qgroup_rescan_worker -8 (72 -> 64)
btrfs_add_inode_defrag +8 (48 -> 56)
Quoted 17 lines
Quoted 4 lines
fs/btrfs/fs.h +1
-2-static inline int btrfs_fs_closing (const struct btrfs_fs_info *fs_info) +static inline bool btrfs_fs_closing (const struct btrfs_fs_info *fs_info) { -/* Do it this way so we only ever do one test_bit in the normal case. */ fs/btrfs/fs.h void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag, · line 1118
Quoted 10 lines
fs/btrfs/fs.h +4
-6-if (test_bit (BTRFS_FS_CLOSING_START , &fs_info->flags)) { -if (test_bit (BTRFS_FS_CLOSING_DONE , &fs_info->flags)) -return 2 ; -return 1 ; - } -return 0 ; +if (unlikely (test_bit (BTRFS_FS_CLOSING_START , &fs_info->flags))) +return true; + +return false;This can simply be:
Quoted 1 line
return
unlikely(test_bit(BTRFS_FS_CLOSING_START, &fs_info->flags));
Ah of course, thanks. I'll fix it for-next.