Coldify, constify, purify (function attributes)
David Sterba
maintainercover Coldify, constify, purify (function attributes)
There's a gcc option -Wsuggest-attribute that, as it says, suggests some function attributes to provide some hints and allowing more optimizations.
Debug build
text data bss dec hex filename
1514058 146768 27496 1688322 19c302 pre/btrfs.ko 1512603 146736 27496 1686835 19bd33 post/btrfs.ko
DELTA: -1455
Release build
text data bss dec hex filename
1079288 17316 14912 1111516 10f5dc pre/btrfs.ko 1078138 17316 14912 1110366 10f15e post/btrfs.ko
DELTA: -1150
David Sterba (3):
btrfs: add __cold attribute to more functions
btrfs: add const function attribute
btrfs: add __pure attribute to functions
fs/btrfs/async-thread.c | 6 ++---- fs/btrfs/async-thread.h | 4 ++-- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 6 +++--- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/dev-replace.h | 2 +- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/disk-io.h | 4 ++-- fs/btrfs/ioctl.c | 2 +- fs/btrfs/space-info.c | 2 +- fs/btrfs/space-info.h | 2 +- fs/btrfs/super.c | 4 ++-- fs/btrfs/volumes.c | 4 ++-- fs/btrfs/volumes.h | 2 +- 14 files changed, 22 insertions(+), 24 deletions(-)
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 1/3 btrfs: add __cold attribute to more functions
The attribute can mark functions supposed to be called rarely if at all and the text can be moved to sections far from the other code. The attribute has been added to several functions already, this patch is based on hints given by gcc -Wsuggest-attribute=cold.
The net effect of this patch is decrease of btrfs.ko by 1000-1300, depending on the config options.
--- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/disk-io.h | 4 ++-- fs/btrfs/super.c | 2 +- fs/btrfs/volumes.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
fs/btrfs/disk-io.c +2 -2
@@ -2583,7 +2583,7 @@ static int btrfs_validate_write_super(struct btrfs_fs_info *fs_info,return ret; } -int open_ctree (struct super_block *sb, +int __cold open_ctree (struct super_block *sb,struct btrfs_fs_devices *fs_devices,char *options) {
@@ -3968,7 +3968,7 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info)return btrfs_commit_transaction (trans); } -void close_ctree (struct btrfs_fs_info *fs_info) +void __cold close_ctree (struct btrfs_fs_info *fs_info) {int ret;
fs/btrfs/disk-io.h +2 -2
@@ -49,10 +49,10 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr);void btrfs_clean_tree_block (struct extent_buffer *buf); -int open_ctree (struct super_block *sb, +int __cold open_ctree (struct super_block *sb,struct btrfs_fs_devices *fs_devices,char *options); -void close_ctree (struct btrfs_fs_info *fs_info); +void __cold close_ctree (struct btrfs_fs_info *fs_info);int write_all_supers (struct btrfs_fs_info *fs_info,int max_mirrors);struct buffer_head *btrfs_read_dev_super (struct block_device *bdev); int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
fs/btrfs/super.c +1 -1
@@ -187,7 +187,7 @@ static struct ratelimit_state printk_limits[] = { RATELIMIT_STATE_INIT(printk_limits[7], DEFAULT_RATELIMIT_INTERVAL, 100), }; -void btrfs_printk (const struct btrfs_fs_info *fs_info,const char *fmt, ...) +void __cold btrfs_printk (const struct btrfs_fs_info *fs_info,const char *fmt, ...) {char lvl[PRINTK_MAX_SINGLE_HEADER_LEN +1 ] ="\0" ;struct va_format vaf;
fs/btrfs/volumes.c +1 -1
@@ -2048,7 +2048,7 @@ static struct btrfs_device * btrfs_find_next_active_device(* where this function called, there should be always be another device (or * this_dev) which is active. */ -void btrfs_assign_next_active_device (struct btrfs_device *device, +void __cold btrfs_assign_next_active_device (struct btrfs_device *device,struct btrfs_device *this_dev) {struct btrfs_fs_info *fs_info = device->fs_info;
Signature · 1 line
2.23.0
Re: [PATCH 1/3] btrfs: add __cold attribute to more functions
Quoted 21 lines · David Sterba
The attribute can mark functions supposed to be called rarely if at all and the text can be moved to sections far from the other code. The attribute has been added to several functions already, this patch is based on hints given by gcc -Wsuggest-attribute=cold.
The net effect of this patch is decrease of btrfs.ko by 1000-1300, depending on the config options.
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/disk-io.h | 4 ++-- fs/btrfs/super.c | 2 +- fs/btrfs/volumes.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)fs/btrfs/disk-io.c +0
-0
fs/btrfs/disk-io.c static int btrfs_validate_write_super(struct btrfs_fs_info *fs_info, · line 2586
Quoted 5 lines
fs/btrfs/disk-io.c +1
-1@@ -2583,7 +2583,7 @@ static int btrfs_validate_write_super(struct btrfs_fs_info *fs_info,return ret; } -int open_ctree(struct super_block *sb, +int __cold open_ctree(struct super_block *sb,
According to the documentation
(https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html) of gcc attributes are placed in the declaration of a function (3rd paragraph):
"Function attributes are introduced by the __attribute__ keyword in the declaration of a function, ..."
Quoted 33 lines
fs/btrfs/disk-io.c +1
-1struct btrfs_fs_devices *fs_devices, char *options) {@@ -3968,7 +3968,7 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info)return btrfs_commit_transaction (trans); } -void close_ctree (struct btrfs_fs_info *fs_info) +void __cold close_ctree (struct btrfs_fs_info *fs_info) {int ret;fs/btrfs/disk-io.h +2
-2@@ -49,10 +49,10 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr);void btrfs_clean_tree_block (struct extent_buffer *buf); -int open_ctree (struct super_block *sb, +int __cold open_ctree (struct super_block *sb,struct btrfs_fs_devices *fs_devices,char *options); -void close_ctree (struct btrfs_fs_info *fs_info); +void __cold close_ctree (struct btrfs_fs_info *fs_info);int write_all_supers (struct btrfs_fs_info *fs_info,int max_mirrors);struct buffer_head *btrfs_read_dev_super (struct block_device *bdev); int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
fs/btrfs/super.c static struct ratelimit_state printk_limits[] = { · line 191
Quoted 6 lines
fs/btrfs/super.c +1
-1@@ -187,7 +187,7 @@ static struct ratelimit_state printk_limits[] = { RATELIMIT_STATE_INIT(printk_limits[7], DEFAULT_RATELIMIT_INTERVAL, 100), }; -void btrfs_printk (const struct btrfs_fs_info *fs_info,const char *fmt, ...) +void __cold btrfs_printk (const struct btrfs_fs_info *fs_info,const char *fmt, ...) {
Is printk really cold though? It's used in the various print helpers, even for info level print which might not be rare once the fs is mounted? What's a possible negative effect of this size optimisation - runtime cost?
Quoted 16 lines
fs/btrfs/super.c +0
-0char lvl[PRINTK_MAX_SINGLE_HEADER_LEN +1 ] ="\0" ;struct va_format vaf;fs/btrfs/volumes.c +1
-1@@ -2048,7 +2048,7 @@ static struct btrfs_device * btrfs_find_next_active_device(* where this function called, there should be always be another device (or * this_dev) which is active. */ -void btrfs_assign_next_active_device (struct btrfs_device *device, +void __cold btrfs_assign_next_active_device (struct btrfs_device *device,struct btrfs_device *this_dev) {struct btrfs_fs_info *fs_info = device->fs_info;
Re: [PATCH 1/3] btrfs: add __cold attribute to more functions
Quoted 33 lines · Nikolay Borisov
Quoted 21 lines · David Sterba
The attribute can mark functions supposed to be called rarely if at all and the text can be moved to sections far from the other code. The attribute has been added to several functions already, this patch is based on hints given by gcc -Wsuggest-attribute=cold.
The net effect of this patch is decrease of btrfs.ko by 1000-1300, depending on the config options.
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/disk-io.h | 4 ++-- fs/btrfs/super.c | 2 +- fs/btrfs/volumes.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)fs/btrfs/disk-io.c +0
-0fs/btrfs/disk-io.c static int btrfs_validate_write_super(struct btrfs_fs_info *fs_info, · line 2586
Quoted 5 lines
fs/btrfs/disk-io.c +1
-1@@ -2583,7 +2583,7 @@ static int btrfs_validate_write_super(struct btrfs_fs_info *fs_info,return ret; } -int open_ctree(struct super_block *sb, +int __cold open_ctree(struct super_block *sb,According to the documentation
(https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html) of gcc attributes are placed in the declaration of a function (3rd paragraph):
Quoted 2 lines
"Function attributes are introduced by the
__attribute__keyword in the declaration of a function, ..."
I'd rather keep the attributes to declaration and definition so it's in sync and looks consistent without further questions.
Quoted 7 lines
fs/btrfs/disk-io.c static int btrfs_validate_write_super(struct btrfs_fs_info *fs_info, · line 2588
Quoted 2 lines
fs/btrfs/disk-io.c +1
-0+void __cold btrfs_printk (const struct btrfs_fs_info *fs_info,const char *fmt, ...) {Is printk really cold though? It's used in the various print helpers, even for info level print which might not be rare once the fs is mounted? What's a possible negative effect of this size optimisation - runtime cost?
Messages are printed rarely under normal circumstances, ie. a message once in a few minutes maybe. The penalty of loading the code into caches is IMO justified here, there's not much chance of reusing the cache hot code. And that it also involves all other helpers is kind of intentional.
A very frequent pattern:
x = find_some_structure();
if (!x) {
btrfs_err("there is a problem");
ret = -EUCLEAN;
goto out_error;
}In this case the cold attribute is another hint to the compiler that the whole code block following the 'if' is cold and can be rearranged out of the way.
If you have counter examples for printk-related functions that are on a hot path in btrfs, I'd like to hear about them. To move them out of the that hot path :)
David Sterba
maintainerPATCH 2/3 btrfs: add const function attribute
In reply to David SterbaFor some reason the attribute is called __attribute_const__ and not __const, marks functions that have no observable effects on program state, IOW not reading pointers, just the arguments and calculating a value. Allows the compiler to do some optimizations, based on -Wsuggest-attribute=const . The effects are rather small, though, about 60 bytes decrese of btrfs.ko.
--- fs/btrfs/ctree.h | 2 +- fs/btrfs/super.c | 2 +- fs/btrfs/volumes.c | 2 +- fs/btrfs/volumes.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/ctree.h +1 -1
@@ -3146,7 +3146,7 @@ __coldvoid __btrfs_handle_fs_error (struct btrfs_fs_info *fs_info,const char *function,unsigned int line,int errno,const char *fmt, ...); -const char *btrfs_decode_error (int errno); +const char * __attribute_const__ btrfs_decode_error(int errno);__cold void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
fs/btrfs/super.c +1 -1
@@ -66,7 +66,7 @@ static struct file_system_type btrfs_root_fs_type;static int btrfs_remount (struct super_block *sb,int *flags,char *data); -const char *btrfs_decode_error (int errno) +const char * __attribute_const__ btrfs_decode_error(int errno) {char *errstr ="unknown" ;
fs/btrfs/volumes.c +1 -1
@@ -297,7 +297,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,DEFINE_MUTEX (uuid_mutex);static LIST_HEAD (fs_uuids); -struct list_head *btrfs_get_fs_uuids (void ) +struct list_head * __attribute_const__ btrfs_get_fs_uuids(void) {return &fs_uuids; }
fs/btrfs/volumes.h +1 -1
@@ -571,7 +571,7 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)void btrfs_commit_device_sizes (struct btrfs_transaction *trans); -struct list_head *btrfs_get_fs_uuids (void ); +struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);void btrfs_set_fs_info_ptr (struct btrfs_fs_info *fs_info);void btrfs_reset_fs_info_ptr (struct btrfs_fs_info *fs_info); bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
Signature · 1 line
2.23.0
Re: [PATCH 2/3] btrfs: add const function attribute
Quoted 46 lines · David Sterba
For some reason the attribute is called
__attribute_const__and not__const, marks functions that have no observable effects on program state, IOW not reading pointers, just the arguments and calculating a value. Allows the compiler to do some optimizations, based on -Wsuggest-attribute=const . The effects are rather small, though, about 60 bytes decrese of btrfs.ko.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ctree.h | 2 +- fs/btrfs/super.c | 2 +- fs/btrfs/volumes.c | 2 +- fs/btrfs/volumes.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)fs/btrfs/ctree.h +1
-1@@ -3146,7 +3146,7 @@ __coldvoid __btrfs_handle_fs_error (struct btrfs_fs_info *fs_info,const char *function,unsigned int line,int errno,const char *fmt, ...); -const char *btrfs_decode_error (int errno); +const char * __attribute_const__ btrfs_decode_error(int errno);__cold void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,fs/btrfs/super.c +1
-1@@ -66,7 +66,7 @@ static struct file_system_type btrfs_root_fs_type;static int btrfs_remount (struct super_block *sb,int *flags,char *data); -const char *btrfs_decode_error (int errno) +const char * __attribute_const__ btrfs_decode_error(int errno) {char *errstr ="unknown" ;fs/btrfs/volumes.c +0
-0
fs/btrfs/volumes.c static int __btrfs_map_block(struct btrfs_fs_info *fs_info, · line 300
Quoted 5 lines
fs/btrfs/volumes.c +1
-1@@ -297,7 +297,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,DEFINE_MUTEX (uuid_mutex);static LIST_HEAD (fs_uuids); -struct list_head *btrfs_get_fs_uuids (void ) +struct list_head * __attribute_const__ btrfs_get_fs_uuids(void)
I'm not entirely sure this function is cons. According to the manual:
Calls to functions whose return value is not affected by changes to the observable state of the program and that have no observable effects on such state other than to return a value may lend themselves to optimizations such as common subexpression elimination.
The const attribute prohibits a function from reading objects that affect its return value between successive invocations. However, functions declared with the attribute can safely read objects that do not change their return value, such as non-volatile constants.
My doubt stems from the fact this function actually references outside memory, namely gets the ptr to fs_uuids. There is a specific remark not to use const when the function takes a ptr argument but it doesn't say anything when getting a ptr from a global var.
Quoted 17 lines
fs/btrfs/volumes.c +0
-0{return &fs_uuids; }fs/btrfs/volumes.h +1
-1@@ -571,7 +571,7 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)void btrfs_commit_device_sizes (struct btrfs_transaction *trans); -struct list_head *btrfs_get_fs_uuids (void ); +struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);void btrfs_set_fs_info_ptr (struct btrfs_fs_info *fs_info);void btrfs_reset_fs_info_ptr (struct btrfs_fs_info *fs_info); bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
Re: [PATCH 2/3] btrfs: add const function attribute
Quoted 15 lines · Nikolay Borisov
Quoted 1 line
+struct
list_head*__attribute_const__btrfs_get_fs_uuids(void)I'm not entirely sure this function is cons. According to the manual:
Calls to functions whose return value is not affected by changes to the observable state of the program and that have no observable effects on such state other than to return a value may lend themselves to optimizations such as common subexpression elimination.
The const attribute prohibits a function from reading objects that affect its return value between successive invocations. However, functions declared with the attribute can safely read objects that do not change their return value, such as non-volatile constants.
Quoted 4 lines
My doubt stems from the fact this function actually references outside memory, namely gets the ptr to
fs_uuids. There is a specific remark not to use const when the function takes a ptr argument but it doesn't say anything when getting a ptr from a global var.
The fs_uuids are a non-volatile constant. It does not change accross the lifetime of the module, so all code executed will always see the same value.
David Sterba
maintainerPATCH 3/3 btrfs: add __pure attribute to functions
In reply to David SterbaThe attribute is more relaxed than const and the functions could dereference pointers, as long as the observable state is not changed. We do have such functions, based on -Wsuggest-attribute=pure .
The visible effects of this patch are negligible, there are differences in the assembly but hard to summarize.
--- fs/btrfs/async-thread.c | 6 ++---- fs/btrfs/async-thread.h | 4 ++-- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/dev-replace.h | 2 +- fs/btrfs/ioctl.c | 2 +- fs/btrfs/space-info.c | 2 +- fs/btrfs/space-info.h | 2 +- 9 files changed, 12 insertions(+), 14 deletions(-)
fs/btrfs/async-thread.c +2 -4
@@ -53,14 +53,12 @@ struct btrfs_workqueue {struct __btrfs_workqueue *high; }; -struct btrfs_fs_info * -btrfs_workqueue_owner (const struct __btrfs_workqueue *wq) +struct btrfs_fs_info *__pure btrfs_workqueue_owner (const struct __btrfs_workqueue *wq) {return wq->fs_info; } -struct btrfs_fs_info * -btrfs_work_owner (const struct btrfs_work *work) +struct btrfs_fs_info *__pure btrfs_work_owner (const struct btrfs_work *work) {return work->wq->fs_info; }
fs/btrfs/async-thread.h +2 -2
@@ -41,8 +41,8 @@ void btrfs_queue_work(struct btrfs_workqueue *wq,void btrfs_destroy_workqueue (struct btrfs_workqueue *wq);void btrfs_workqueue_set_max (struct btrfs_workqueue *wq,int max);void btrfs_set_work_high_priority (struct btrfs_work *work); -struct btrfs_fs_info *btrfs_work_owner (const struct btrfs_work *work); -struct btrfs_fs_info *btrfs_workqueue_owner (const struct __btrfs_workqueue *wq); +struct btrfs_fs_info *__pure btrfs_work_owner (const struct btrfs_work *work); +struct btrfs_fs_info *__pure btrfs_workqueue_owner (const struct __btrfs_workqueue *wq);bool btrfs_workqueue_normal_congested (const struct btrfs_workqueue *wq);#endif
fs/btrfs/ctree.c +1 -1
@@ -1538,7 +1538,7 @@ static int comp_keys(const struct btrfs_disk_key *disk,/* * same as comp_keys only with two btrfs_key's */ -int btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2) +int __pure btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2) {if (k1->objectid > k2->objectid)return 1 ;
fs/btrfs/ctree.h +2 -2
@@ -2511,7 +2511,7 @@ void btrfs_wait_for_snapshot_creation(struct btrfs_root *root);/* ctree.c */ int btrfs_bin_search (struct extent_buffer *eb,const struct btrfs_key *key,int level,int *slot); -int btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2); +int __pure btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2);int btrfs_previous_item (struct btrfs_root *root,struct btrfs_path *path,u64 min_objectid,int type);
@@ -2912,7 +2912,7 @@ long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);long btrfs_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg);int btrfs_ioctl_get_supported_features (void __user *arg);void btrfs_sync_inode_flags_to_i_flags (struct inode *inode); -int btrfs_is_empty_uuid (u8 *uuid); +int __pure btrfs_is_empty_uuid (u8 *uuid);int btrfs_defrag_file (struct inode *inode,struct file *file,struct btrfs_ioctl_defrag_range_args *range,u64 newer_than,unsigned long max_pages);
fs/btrfs/dev-replace.c +1 -1
@@ -986,7 +986,7 @@ static int btrfs_dev_replace_kthread(void *data)return 0 ; } -int btrfs_dev_replace_is_ongoing (struct btrfs_dev_replace *dev_replace) +int __pure btrfs_dev_replace_is_ongoing (struct btrfs_dev_replace *dev_replace) {if (!dev_replace->is_valid)return 0 ;
fs/btrfs/dev-replace.h +1 -1
@@ -17,6 +17,6 @@ void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info,int btrfs_dev_replace_cancel (struct btrfs_fs_info *fs_info);void btrfs_dev_replace_suspend_for_unmount (struct btrfs_fs_info *fs_info);int btrfs_resume_dev_replace_async (struct btrfs_fs_info *fs_info); -int btrfs_dev_replace_is_ongoing (struct btrfs_dev_replace *dev_replace); +int __pure btrfs_dev_replace_is_ongoing (struct btrfs_dev_replace *dev_replace);#endif
fs/btrfs/ioctl.c +1 -1
@@ -541,7 +541,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)return 0 ; } -int btrfs_is_empty_uuid (u8 *uuid) +int __pure btrfs_is_empty_uuid (u8 *uuid) {int i;
fs/btrfs/space-info.c +1 -1
@@ -10,7 +10,7 @@#include "transaction.h" #include "block-group.h" -u64 btrfs_space_info_used (struct btrfs_space_info *s_info, +u64 __pure btrfs_space_info_used (struct btrfs_space_info *s_info,bool may_use_included) {ASSERT (s_info);
fs/btrfs/space-info.h +1 -1
@@ -116,7 +116,7 @@ void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags, struct btrfs_space_info **space_info);struct btrfs_space_info *btrfs_find_space_info (struct btrfs_fs_info *info,u64 flags); -u64 btrfs_space_info_used (struct btrfs_space_info *s_info, +u64 __pure btrfs_space_info_used (struct btrfs_space_info *s_info,bool may_use_included);void btrfs_clear_space_info_full (struct btrfs_fs_info *info); void btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
Signature · 1 line
2.23.0
Re: [PATCH 3/3] btrfs: add __pure attribute to functions
Quoted 8 lines · David Sterba
The attribute is more relaxed than const and the functions could dereference pointers, as long as the observable state is not changed. We do have such functions, based on -Wsuggest-attribute=pure .
The visible effects of this patch are negligible, there are differences in the assembly but hard to summarize.
Signed-off-by David Sterba <[email protected]>
one remark: I'm not sure the attribute needs to be duplicated in the declaration and definition.
Quoted 148 lines
--- fs/btrfs/async-thread.c | 6 ++---- fs/btrfs/async-thread.h | 4 ++-- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/dev-replace.h | 2 +- fs/btrfs/ioctl.c | 2 +- fs/btrfs/space-info.c | 2 +- fs/btrfs/space-info.h | 2 +- 9 files changed, 12 insertions(+), 14 deletions(-)fs/btrfs/async-thread.c +2
-4@@ -53,14 +53,12 @@ struct btrfs_workqueue {struct __btrfs_workqueue *high; }; -struct btrfs_fs_info * -btrfs_workqueue_owner (const struct __btrfs_workqueue *wq) +struct btrfs_fs_info *__pure btrfs_workqueue_owner (const struct __btrfs_workqueue *wq) {return wq->fs_info; } -struct btrfs_fs_info * -btrfs_work_owner (const struct btrfs_work *work) +struct btrfs_fs_info *__pure btrfs_work_owner (const struct btrfs_work *work) {return work->wq->fs_info; }fs/btrfs/async-thread.h +2
-2@@ -41,8 +41,8 @@ void btrfs_queue_work(struct btrfs_workqueue *wq,void btrfs_destroy_workqueue (struct btrfs_workqueue *wq);void btrfs_workqueue_set_max (struct btrfs_workqueue *wq,int max);void btrfs_set_work_high_priority (struct btrfs_work *work); -struct btrfs_fs_info *btrfs_work_owner (const struct btrfs_work *work); -struct btrfs_fs_info *btrfs_workqueue_owner (const struct __btrfs_workqueue *wq); +struct btrfs_fs_info *__pure btrfs_work_owner (const struct btrfs_work *work); +struct btrfs_fs_info *__pure btrfs_workqueue_owner (const struct __btrfs_workqueue *wq);bool btrfs_workqueue_normal_congested (const struct btrfs_workqueue *wq);#endif fs/btrfs/ctree.c +1
-1@@ -1538,7 +1538,7 @@ static int comp_keys(const struct btrfs_disk_key *disk,/* * same as comp_keys only with two btrfs_key's */ -int btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2) +int __pure btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2) {if (k1->objectid > k2->objectid)return 1 ;fs/btrfs/ctree.h +2
-2@@ -2511,7 +2511,7 @@ void btrfs_wait_for_snapshot_creation(struct btrfs_root *root);/* ctree.c */ int btrfs_bin_search (struct extent_buffer *eb,const struct btrfs_key *key,int level,int *slot); -int btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2); +int __pure btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2);int btrfs_previous_item (struct btrfs_root *root,struct btrfs_path *path,u64 min_objectid,int type);@@ -2912,7 +2912,7 @@ long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);long btrfs_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg);int btrfs_ioctl_get_supported_features (void __user *arg);void btrfs_sync_inode_flags_to_i_flags (struct inode *inode); -int btrfs_is_empty_uuid (u8 *uuid); +int __pure btrfs_is_empty_uuid (u8 *uuid);int btrfs_defrag_file (struct inode *inode,struct file *file,struct btrfs_ioctl_defrag_range_args *range,u64 newer_than,unsigned long max_pages);fs/btrfs/dev-replace.c +1
-1@@ -986,7 +986,7 @@ static int btrfs_dev_replace_kthread(void *data)return 0 ; } -int btrfs_dev_replace_is_ongoing (struct btrfs_dev_replace *dev_replace) +int __pure btrfs_dev_replace_is_ongoing (struct btrfs_dev_replace *dev_replace) {if (!dev_replace->is_valid)return 0 ;fs/btrfs/dev-replace.h +1
-1@@ -17,6 +17,6 @@ void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info,int btrfs_dev_replace_cancel (struct btrfs_fs_info *fs_info);void btrfs_dev_replace_suspend_for_unmount (struct btrfs_fs_info *fs_info);int btrfs_resume_dev_replace_async (struct btrfs_fs_info *fs_info); -int btrfs_dev_replace_is_ongoing (struct btrfs_dev_replace *dev_replace); +int __pure btrfs_dev_replace_is_ongoing (struct btrfs_dev_replace *dev_replace);#endif fs/btrfs/ioctl.c +1
-1@@ -541,7 +541,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)return 0 ; } -int btrfs_is_empty_uuid (u8 *uuid) +int __pure btrfs_is_empty_uuid (u8 *uuid) {int i;fs/btrfs/space-info.c +1
-1@@ -10,7 +10,7 @@#include "transaction.h" #include "block-group.h" -u64 btrfs_space_info_used (struct btrfs_space_info *s_info, +u64 __pure btrfs_space_info_used (struct btrfs_space_info *s_info,bool may_use_included) {ASSERT (s_info);fs/btrfs/space-info.h +1
-1@@ -116,7 +116,7 @@ void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags, struct btrfs_space_info **space_info);struct btrfs_space_info *btrfs_find_space_info (struct btrfs_fs_info *info,u64 flags); -u64 btrfs_space_info_used (struct btrfs_space_info *s_info, +u64 __pure btrfs_space_info_used (struct btrfs_space_info *s_info,bool may_use_included);void btrfs_clear_space_info_full (struct btrfs_fs_info *info); void btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
Quoted 14 lines · David Sterba
There's a gcc option -Wsuggest-attribute that, as it says, suggests some function attributes to provide some hints and allowing more optimizations.
Debug build
text data bss dec hex filename
1514058 146768 27496 1688322 19c302 pre/btrfs.ko 1512603 146736 27496 1686835 19bd33 post/btrfs.koDELTA: -1455
Release build
text data bss dec hex filename
Quoted 8 lines
1079288 17316 14912 1111516 10f5dc pre/btrfs.ko 1078138 17316 14912 1110366 10f15e post/btrfs.koDELTA: -1150
David Sterba (3):
btrfs: add__coldattribute to more functions
btrfs: add const function attribute
btrfs: add__pureattribute to functions
Checking up the with compiler ppl and discussing I can say:
Quoted 17 lines
fs/btrfs/async-thread.c | 6 ++---- fs/btrfs/async-thread.h | 4 ++-- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 6 +++--- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/dev-replace.h | 2 +- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/disk-io.h | 4 ++-- fs/btrfs/ioctl.c | 2 +- fs/btrfs/space-info.c | 2 +- fs/btrfs/space-info.h | 2 +- fs/btrfs/super.c | 4 ++-- fs/btrfs/volumes.c | 4 ++-- fs/btrfs/volumes.h | 2 +- 14 files changed, 22 insertions(+), 24 deletions(-)