Pending bcache patches for review
Subsystems (3)
PATCH 9/9 bcache: set max writeback rate when I/O request is idle
In reply to Coly LiCommit b1092c9af9ed ("bcache: allow quick writeback when backing idle") allows the writeback rate to be faster if there is no I/O request on a bcache device. It works well if there is only one bcache device attached to the cache set. If there are many bcache devices attached to a cache set, it may introduce performance regression because multiple faster writeback threads of the idle bcache devices will compete the btree level locks with the bcache device who have I/O requests coming.
This patch fixes the above issue by only permitting fast writebac when all bcache devices attached on the cache set are idle. And if one of the bcache devices has new I/O request coming, minimized all writeback throughput immediately and let PI controller __update_writeback_rate() to decide the upcoming writeback rate for each bcache device.
Also when all bcache devices are idle, limited wrieback rate to a small number is wast of thoughput, especially when backing devices are slower non-rotation devices (e.g. SATA SSD). This patch sets a max writeback rate for each backing device if the whole cache set is idle. A faster writeback rate in idle time means new I/Os may have more available space for dirty data, and people may observe a better write performance then.
Please note bcache may change its cache mode in run time, and this patch still works if the cache mode is switched from writeback mode and there is still dirty data on cache.
--- drivers/md/bcache/bcache.h | 10 ++-- drivers/md/bcache/request.c | 54 ++++++++++++++++++++- drivers/md/bcache/super.c | 4 ++ drivers/md/bcache/sysfs.c | 15 ++++-- drivers/md/bcache/util.c | 2 +- drivers/md/bcache/util.h | 2 +- drivers/md/bcache/writeback.c | 91 +++++++++++++++++++++++------------ 7 files changed, 134 insertions(+), 44 deletions(-)
drivers/md/bcache/bcache.h +3 -7
@@ -328,13 +328,6 @@ struct cached_dev {*/ atomic_t has_dirty; -/* -* Set to zero by things that touch the backing volume-- except -* writeback. Incremented by writeback. Used to determine when to -* accelerate idle writeback. -*/ -atomic_t backing_idle; -struct bch_ratelimit writeback_rate;struct delayed_work writeback_rate_update;
@@ -515,6 +508,8 @@ struct cache_set {struct cache_accounting accounting;unsigned long flags; +atomic_t idle_counter; +atomic_t at_max_writeback_rate;struct cache_sb sb;
@@ -524,6 +519,7 @@ struct cache_set {struct bcache_device **devices;unsigned devices_max_used; +atomic_t attached_dev_nr;struct list_head cached_devs;uint64_t cached_dev_sectors;atomic_long_t flash_dev_dirty_sectors;
drivers/md/bcache/request.c +53 -1
66 lines not on this page · raw message
drivers/md/bcache/super.c +4 -0
@@ -696,6 +696,8 @@ static void bcache_device_detach(struct bcache_device *d) {lockdep_assert_held (&bch_register_lock); +atomic_dec (&d->c->attached_dev_nr); +if (test_bit (BCACHE_DEV_DETACHING , &d->flags)) {struct uuid_entry *u = d->c->uuids + d->id;
@@ -1144,6 +1146,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,bch_cached_dev_run (dc);bcache_device_link (&dc->disk, c,"bdev" ); +atomic_inc (&c->attached_dev_nr);/* Allow the writeback thread to proceed */ up_write (&dc->writeback_lock);
@@ -1696,6 +1699,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb) c->block_bits =ilog2 (sb->block_size); c->nr_uuids =bucket_bytes (c) /sizeof (struct uuid_entry ); c->devices_max_used =0 ; +atomic_set (&c->attached_dev_nr,0 ); c->btree_pages =bucket_pages (c);if (c->btree_pages >BTREE_MAX_PAGES ) c->btree_pages = max_t(int, c->btree_pages / 4,
drivers/md/bcache/sysfs.c +11 -4
@@ -171,7 +171,8 @@ SHOW(__bch_cached_dev)var_printf (writeback_running,"%i" );var_print (writeback_delay);var_print (writeback_percent); -sysfs_hprint (writeback_rate, wb ? dc->writeback_rate.rate <<9 :0 ); +sysfs_hprint (writeback_rate, + wb ?atomic_long_read (&dc->writeback_rate.rate) <<9 :0 );sysfs_hprint (io_errors,atomic_read (&dc->io_errors));sysfs_printf (io_error_limit,"%i" , dc->error_limit);sysfs_printf (io_disable,"%i" , dc->io_disable);
@@ -193,7 +194,9 @@ SHOW(__bch_cached_dev)* Except for dirty and target, other values should * be 0 if writeback is not running. */ -bch_hprint (rate, wb ? dc->writeback_rate.rate <<9 :0 ); +bch_hprint (rate, + wb ?atomic_long_read (&dc->writeback_rate.rate) <<9 + :0 );bch_hprint (dirty,bcache_dev_sectors_dirty (&dc->disk) <<9 );bch_hprint (target, dc->writeback_rate_target <<9 ); bch_hprint(proportional,
@@ -261,8 +264,12 @@ STORE(__cached_dev)sysfs_strtoul_clamp (writeback_percent, dc->writeback_percent,0 ,40 ); -sysfs_strtoul_clamp (writeback_rate, - dc->writeback_rate.rate,1 ,INT_MAX ); +if (attr == &sysfs_writeback_rate) { +int v; + +sysfs_strtoul_clamp (writeback_rate, v,1 ,INT_MAX ); +atomic_long_set (&dc->writeback_rate.rate, v); + } sysfs_strtoul_clamp(writeback_rate_update_seconds, dc->writeback_rate_update_seconds,
drivers/md/bcache/util.c +1 -1
@@ -200,7 +200,7 @@ uint64_t bch_next_delay(struct bch_ratelimit *d, uint64_t done) {uint64_t now =local_clock (); - d->next +=div_u64 (done *NSEC_PER_SEC , d->rate); + d->next +=div_u64 (done *NSEC_PER_SEC ,atomic_long_read (&d->rate));/* Bound the time. Don't let us fall further than 2 seconds behind * (this prevents unnecessary backlog that would make it impossible
drivers/md/bcache/util.h +1 -1
@@ -443,7 +443,7 @@ struct bch_ratelimit {* Rate at which we want to do work, in units per second * The units here correspond to the units passed to bch_next_delay() */ -uint32_t rate; +atomic_long_t rate; };static inline void bch_ratelimit_reset (struct bch_ratelimit *d)
drivers/md/bcache/writeback.c +61 -30
119 lines not on this page · raw message
Signature · 1 line
2.17.1
cover Pending bcache patches for review
Hi folks,
I ask for help to review these patches, some of them are posted for months. They are OK with my test for a while, still tt would be great to have more reviewer before these patches go into v4.19.
Thanks in advance.
Coly Li
---
Coly Li (9):
bcache: do not check return value of debugfs_create_dir()
bcache: display rate debug parameters to 0 when writeback is not
running
bcache: avoid unncessary cache prefetch bch_btree_node_get()
bcache: add a comment in register_bdev()
bcache: fix mistaken code comments in struct cache
bcache: fix mistaken comments in bch_keylist_realloc()
bcache: add code comments for bset.c
bcache: initiate bcache_debug to NULL
bcache: set max writeback rate when I/O request is idle
drivers/md/bcache/bcache.h | 16 +++--- drivers/md/bcache/bset.c | 63 ++++++++++++++++++++++++ drivers/md/bcache/btree.c | 14 +++--- drivers/md/bcache/closure.c | 13 +++-- drivers/md/bcache/closure.h | 4 +- drivers/md/bcache/debug.c | 13 ++--- drivers/md/bcache/request.c | 56 ++++++++++++++++++++- drivers/md/bcache/super.c | 9 +++- drivers/md/bcache/sysfs.c | 37 +++++++++----- drivers/md/bcache/util.c | 2 +- drivers/md/bcache/util.h | 2 +- drivers/md/bcache/writeback.c | 91 +++++++++++++++++++++++------------ 12 files changed, 244 insertions(+), 76 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/9 bcache: do not check return value of debugfs_create_dir()
Greg KH suggests that normal code should not care about debugfs. Therefore no matter successful or failed of debugfs_create_dir() execution, it is unncessary to check its return value.
There are two functions called debugfs_create_dir() and check the return value, which are bch_debug_init() and closure_debug_init(). This patch changes these two functions from int to void type, and ignore return values of debugfs_create_dir().
This patch does not fix exact bug, just makes things work as they should.
--- drivers/md/bcache/bcache.h | 2 +- drivers/md/bcache/closure.c | 13 +++++++++---- drivers/md/bcache/closure.h | 4 ++-- drivers/md/bcache/debug.c | 11 ++++++----- drivers/md/bcache/super.c | 4 +++- 5 files changed, 21 insertions(+), 13 deletions(-)
drivers/md/bcache/bcache.h +1 -1
@@ -1001,7 +1001,7 @@ void bch_open_buckets_free(struct cache_set *);int bch_cache_allocator_start (struct cache *ca);void bch_debug_exit (void ); -int bch_debug_init (struct kobject *); +void bch_debug_init (struct kobject *);void bch_request_exit (void );int bch_request_init (void );
drivers/md/bcache/closure.c +9 -4
@@ -199,11 +199,16 @@ static const struct file_operations debug_ops = { .release = single_release }; -int __init closure_debug_init (void ) +void __init closure_debug_init (void ) { - closure_debug =debugfs_create_file ("closures" , -0400 , bcache_debug,NULL , &debug_ops); -return IS_ERR_OR_NULL (closure_debug); +if (!IS_ERR_OR_NULL (bcache_debug)) +/* +* it is unnecessary to check return value of +* debugfs_create_file(), we should not care +* about this. +*/ + closure_debug =debugfs_create_file ( +"closures" ,0400 , bcache_debug,NULL , &debug_ops); }#endif
drivers/md/bcache/closure.h +2 -2
@@ -186,13 +186,13 @@ static inline void closure_sync(struct closure *cl)#ifdef CONFIG_BCACHE_CLOSURES_DEBUG -int closure_debug_init (void ); +void closure_debug_init (void );void closure_debug_create (struct closure *cl);void closure_debug_destroy (struct closure *cl);#else -static inline int closure_debug_init (void ) {return 0 ; } +static inline void closure_debug_init (void ) {}static inline void closure_debug_create (struct closure *cl) {}static inline void closure_debug_destroy (struct closure *cl) {}
drivers/md/bcache/debug.c +6 -5
@@ -248,11 +248,12 @@ void bch_debug_exit(void)debugfs_remove_recursive (bcache_debug); } -int __init bch_debug_init (struct kobject *kobj) +void __init bch_debug_init (struct kobject *kobj) { -if (!IS_ENABLED (CONFIG_DEBUG_FS )) -return 0 ; - +/* +* it is unnecessary to check return value of +* debugfs_create_file(), we should not care +* about this. +*/ bcache_debug =debugfs_create_dir ("bcache" ,NULL ); -return IS_ERR_OR_NULL (bcache_debug); }
drivers/md/bcache/super.c +3 -1
@@ -2345,10 +2345,12 @@ static int __init bcache_init(void) goto err;if (bch_request_init () || -bch_debug_init (bcache_kobj) ||closure_debug_init () ||sysfs_create_files (bcache_kobj, files)) goto err; +bch_debug_init (bcache_kobj); +closure_debug_init (); +return 0 ; err:bcache_exit ();
Signature · 1 line
2.17.1
PATCH 2/9 bcache: display rate debug parameters to 0 when writeback is not running
In reply to Coly LiWhen writeback is not running, writeback rate should be 0, other value is misleading. And the following dyanmic writeback rate debug parameters should be 0 too,
rate, proportional, integral, change
otherwise they are misleading when writeback is not running.
--- drivers/md/bcache/sysfs.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/md/bcache/sysfs.c +16 -10
@@ -149,6 +149,7 @@ SHOW(__bch_cached_dev) struct cached_dev *dc = container_of(kobj, struct cached_dev, disk.kobj);const char *states[] = {"no cache" ,"clean" ,"dirty" ,"inconsistent" }; +int wb = dc->writeback_running;#define var (stat) (dc->stat)
@@ -170,7 +171,7 @@ SHOW(__bch_cached_dev)var_printf (writeback_running,"%i" );var_print (writeback_delay);var_print (writeback_percent); -sysfs_hprint (writeback_rate, dc->writeback_rate.rate <<9 ); +sysfs_hprint (writeback_rate, wb ? dc->writeback_rate.rate <<9 :0 );sysfs_hprint (io_errors,atomic_read (&dc->io_errors));sysfs_printf (io_error_limit,"%i" , dc->error_limit);sysfs_printf (io_disable,"%i" , dc->io_disable);
@@ -188,15 +189,20 @@ SHOW(__bch_cached_dev)char change[20 ];s64 next_io; -bch_hprint (rate, dc->writeback_rate.rate <<9 ); -bch_hprint (dirty,bcache_dev_sectors_dirty (&dc->disk) <<9 ); -bch_hprint (target, dc->writeback_rate_target <<9 ); -bch_hprint (proportional,dc->writeback_rate_proportional <<9 ); -bch_hprint (integral, dc->writeback_rate_integral_scaled <<9 ); -bch_hprint (change, dc->writeback_rate_change <<9 ); - - next_io =div64_s64 (dc->writeback_rate.next -local_clock (), -NSEC_PER_MSEC ); +/* +* Except for dirty and target, other values should +* be 0 if writeback is not running. +*/ +bch_hprint (rate, wb ? dc->writeback_rate.rate <<9 :0 ); +bch_hprint (dirty,bcache_dev_sectors_dirty (&dc->disk) <<9 ); +bch_hprint (target, dc->writeback_rate_target <<9 ); +bch_hprint (proportional, + wb ? dc->writeback_rate_proportional <<9 :0 ); +bch_hprint (integral, + wb ? dc->writeback_rate_integral_scaled <<9 :0 ); +bch_hprint (change, wb ? dc->writeback_rate_change <<9 :0 ); + next_io = wb ?div64_s64 (dc->writeback_rate.next-local_clock (), +NSEC_PER_MSEC ) :0 ;return sprintf (buf, "rate:\t\t%s/sec\n"
Signature · 1 line
2.17.1
PATCH 3/9 bcache: avoid unncessary cache prefetch bch_btree_node_get()
In reply to Coly LiIn bch_btree_node_get() the read-in btree node will be partially prefetched into L1 cache for following bset iteration (if there is). But if the btree node read is failed, the perfetch operations will waste L1 cache space. This patch checkes whether read operation and only does cache prefetch when read I/O successed.
--- drivers/md/bcache/btree.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/md/bcache/btree.c +7 -7
@@ -1011,6 +1011,13 @@ struct btree *bch_btree_node_get(struct cache_set *c, struct btree_op *op,BUG_ON (b->level != level); } +if (btree_node_io_error (b)) { +rw_unlock (write, b); +return ERR_PTR (-EIO ); + } + +BUG_ON (!b->written); + b->parent = parent; b->accessed =1 ;
@@ -1022,13 +1029,6 @@ struct btree *bch_btree_node_get(struct cache_set *c, struct btree_op *op,for (; i <= b->keys.nsets; i++)prefetch (b->keys.set[i].data); -if (btree_node_io_error (b)) { -rw_unlock (write, b); -return ERR_PTR (-EIO ); - } - -BUG_ON (!b->written); -return b; }
Signature · 1 line
2.17.1
PATCH 4/9 bcache: add a comment in register_bdev()
In reply to Coly Li--- drivers/md/bcache/super.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/bcache/super.c +1 -0
@@ -1291,6 +1291,7 @@ static void register_bdev(struct cache_sb *sb, struct page *sb_page,pr_info ("registered backing device %s" , dc->backing_dev_name);list_add (&dc->list, &uncached_devices); +/* attch to a matched cache set if it exists */ list_for_each_entry (c, &bch_cache_sets, list)bch_cached_dev_attach (dc, c,NULL );
Signature · 1 line
2.17.1
PATCH 5/9 bcache: fix mistaken code comments in struct cache
In reply to Coly Li--- drivers/md/bcache/bcache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/bcache/bcache.h +2 -2
@@ -423,8 +423,8 @@ struct cache {/* * When allocating new buckets, prio_write() gets first dibs - since we * may not be allocate at all without writing priorities and gens. -* prio_buckets[] contains the last buckets we wrote priorities to (so -* gc can mark them as metadata), prio_next[] contains the buckets +* prio_last_buckets[] contains the last buckets we wrote priorities to (so +* gc can mark them as metadata), prio_buckets[] contains the buckets * allocated for the next prio write. */ uint64_t *prio_buckets;
Signature · 1 line
2.17.1
PATCH 6/9 bcache: fix mistaken comments in bch_keylist_realloc()
In reply to Coly Li--- drivers/md/bcache/request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/request.c +1 -1
@@ -107,7 +107,7 @@ static int bch_keylist_realloc(struct keylist *l, unsigned u64s,/* * The journalling code doesn't handle the case where the keys to insert * is bigger than an empty write: If we just return -ENOMEM here, -* bio_insert() and bio_invalidate() will insert the keys created so far +* bch_data_insert_keys() will insert the keys created so far * and finish the rest when the keylist is empty. */ if (newsize *sizeof (uint64_t ) >block_bytes (c) -sizeof (struct jset ))
Signature · 1 line
2.17.1
PATCH 7/9 bcache: add code comments for bset.c
In reply to Coly LiThis patch tries to add code comments in bset.c, to make some tricky code and designment to be more comprehensible. Most information of this patch comes from the discussion between Kent and I, he offers very informative details. If there is any mistake
of the idea behind the code, no doubt that's from me misrepresentation.
--- drivers/md/bcache/bset.c | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
drivers/md/bcache/bset.c +63 -0
@@ -366,6 +366,10 @@ EXPORT_SYMBOL(bch_btree_keys_init);/* Binary tree stuff for auxiliary search trees */ +/* +* return array index next to j when does in-order traverse +* of a binary tree which is stored in a linear array +*/ static unsigned inorder_next (unsigned j,unsigned size) {if (j *2 +1 < size) {
@@ -379,6 +383,10 @@ static unsigned inorder_next(unsigned j, unsigned size)return j; } +/* +* return array index previous to j when does in-order traverse +* of a binary tree which is stored in a linear array +*/ static unsigned inorder_prev (unsigned j,unsigned size) {if (j *2 < size) {
@@ -421,6 +429,10 @@ static unsigned __to_inorder(unsigned j, unsigned size, unsigned extra)return j; } +/* +* Return the cacheline index in bset_tree->data, where j is index +* from a linear array which stores the auxiliar binary tree +*/ static unsigned to_inorder (unsigned j,struct bset_tree *t) {return __to_inorder (j, t->size, t->extra);
@@ -441,6 +453,10 @@ static unsigned __inorder_to_tree(unsigned j, unsigned size, unsigned extra)return j; } +/* +* Return an index from a linear array which stores the auxiliar binary +* tree, j is the cacheline index of t->data. +*/ static unsigned inorder_to_tree (unsigned j,struct bset_tree *t) {return __inorder_to_tree (j, t->size, t->extra);
@@ -546,6 +562,20 @@ static inline uint64_t shrd128(uint64_t high, uint64_t low, uint8_t shift)return low; } +/* +* Calculate mantissa value for struct bkey_float. +* If most significant bit of f->exponent is not set, then +* - f->exponent >> 6 is 0 +* - p[0] points to bkey->low +* - p[-1] borrows bits from KEY_INODE() of bkey->high +* if most isgnificant bits of f->exponent is set, then +* - f->exponent >> 6 is 1 +* - p[0] points to bits from KEY_INODE() of bkey->high +* - p[-1] points to other bits from KEY_INODE() of +* bkey->high too. +* See make_bfloat() to check when most significant bit of f->exponent +* is set or not. +*/ static inline unsigned bfloat_mantissa (const struct bkey *k,struct bkey_float *f) {
@@ -570,6 +600,16 @@ static void make_bfloat(struct bset_tree *t, unsigned j)BUG_ON (m < l || m > r);BUG_ON (bkey_next (p) != m); +/* +* If l and r have different KEY_INODE values (different backing +* device), f->exponent records how many least significant bits +* are different in KEY_INODE values and sets most significant +* bits to 1 (by +64). +* If l and r have same KEY_INODE value, f->exponent records +* how many different bits in least significant bits of bkey->low. +* See bfloat_mantiss() how the most significant bit of +* f->exponent is used to calculate bfloat mantissa value. +*/ if (KEY_INODE (l) !=KEY_INODE (r)) f->exponent =fls64 (KEY_INODE (r) ^KEY_INODE (l)) +64 ;else
@@ -633,6 +673,15 @@ void bch_bset_init_next(struct btree_keys *b, struct bset *i, uint64_t magic) }EXPORT_SYMBOL (bch_bset_init_next); +/* +* Build auxiliary binary tree 'struct bset_tree *t', this tree is used to +* accelerate bkey search in a btree node (pointed by bset_tree->data in +* memory). After search in the auxiliar tree by calling bset_search_tree(), +* a struct bset_search_iter is returned which indicates range [l, r] from +* bset_tree->data where the searching bkey might be inside. Then a followed +* linear comparison does the exact search, see __bch_bset_search() for how +* the auxiliary tree is used. +*/ void bch_bset_build_written_tree (struct btree_keys *b) {struct bset_tree *t =bset_tree_last (b);
@@ -898,6 +947,17 @@ static struct bset_search_iter bset_search_tree(struct bset_tree *t,unsigned inorder, j, n =1 ; do { + /* + * A bit trick here. + * If p < t->size, (int)(p - t->size) is a minus value and + * the most significant bit is set, right shifting 31 bits + * gets 1. If p >= t->size, the most significant bit is + * not set, right shifting 31 bits gets 0. + * So the following 2 lines equals to + * if (p >= t->size) + * p = 0; + * but a branch instruction is avoided. + */ unsigned p = n << 4; p &= ((int) (p - t->size)) >> 31;
@@ -907,6 +967,9 @@ static struct bset_search_iter bset_search_tree(struct bset_tree *t, f = &t->tree[j];/* +* Similar bit trick, use subtract operation to avoid a branch +* instruction. +* * n = (f->mantissa > bfloat_mantissa()) * ? j * 2 * : j * 2 + 1;
Signature · 1 line
2.17.1
PATCH 8/9 bcache: initiate bcache_debug to NULL
In reply to Coly LiGlobal variable bcache_debug is firstly initialized in bch_debug_init(), and destroyed in bch_debug_exit(). bch_debug_init() is called in bcache_init() with many other functions, if one of the previous calling onces failed, bcache_exit() will be called in the failure path.
The problem is, if bcache_init() fails before bch_debug_init() is called, then in bcache_exit() when bch_debug_exit() is called to destroy global variable bcache_debug, at this moment bcache_debug is unndefined, then the test of "if (!IS_ERR_OR_NULL(bcache_debug))" might be buggy.
This patch initializes global varabile bcache_debug to be NULL, to make the failure code path to be predictable.
--- drivers/md/bcache/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/debug.c +1 -1
@@ -17,7 +17,7 @@#include <linux/random.h> #include <linux/seq_file.h> -struct dentry *bcache_debug; +struct dentry *bcache_debug =NULL ;#ifdef CONFIG_BCACHE_DEBUG
Signature · 1 line
2.17.1
Re: [PATCH 8/9] bcache: initiate bcache_debug to NULL
Quoted 10 lines · Coly Li
Global variable
bcache_debugis firstly initialized inbch_debug_init(), and destroyed inbch_debug_exit().bch_debug_init()is called inbcache_init()with many other functions, if one of the previous calling onces failed,bcache_exit()will be called in the failure path.The problem is, if
bcache_init()fails beforebch_debug_init()is called, then inbcache_exit()whenbch_debug_exit()is called to destroy global variablebcache_debug, at this momentbcache_debugis unndefined, then the test of "if (!IS_ERR_OR_NULL(bcache_debug))" might be buggy.
Quoted 6 lines
This patch initializes global varabile
bcache_debugto be NULL, to make the failure code path to be predictable.Signed-off-by Coly Li <[email protected]>---
Makes sense
drivers/md/bcache/debug.c | 2 +-
Quoted 23 lines
1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/bcache/debug.c +1
-2@@ -17,7 +17,7 @@#include <linux/random.h> #include <linux/seq_file.h> -struct dentry *bcache_debug; +struct dentry *bcache_debug =NULL ;#ifdef CONFIG_BCACHE_DEBUG --2.17.1
--
To unsubscribe from this list: send the line "unsubscribe linux-bcache" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 8/9] bcache: initiate bcache_debug to NULL
Quoted 15 lines · Noah Massey
Quoted 14 lines · Coly Li
Global variable
bcache_debugis firstly initialized inbch_debug_init(), and destroyed inbch_debug_exit().bch_debug_init()is called inbcache_init()with many other functions, if one of the previous calling onces failed,bcache_exit()will be called in the failure path.The problem is, if
bcache_init()fails beforebch_debug_init()is called, then inbcache_exit()whenbch_debug_exit()is called to destroy global variablebcache_debug, at this momentbcache_debugis unndefined, then the test of "if (!IS_ERR_OR_NULL(bcache_debug))" might be buggy.This patch initializes global varabile
bcache_debugto be NULL, to make the failure code path to be predictable.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Coly Li <[email protected]>---
Makes sense
Reviewed-by Noah Massey <[email protected]>
Wait... aren't static variables already initialized to 0?
So this makes it explicit, but no code change to generated binary, right?
Quoted 23 lines
Quoted 23 lines
drivers/md/bcache/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/bcache/debug.c +1
-2@@ -17,7 +17,7 @@#include <linux/random.h> #include <linux/seq_file.h> -struct dentry *bcache_debug; +struct dentry *bcache_debug =NULL ;#ifdef CONFIG_BCACHE_DEBUG --2.17.1
--
To unsubscribe from this list: send the line "unsubscribe linux-bcache" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 8/9] bcache: initiate bcache_debug to NULL
In reply to Coly LiQuoted 1 line · Coly Li
Global variable
bcache_debugis firstly initialized in bch_de=
bug_init(),
Quoted 1 line
and destroyed in
bch_debug_exit().bch_debug_init()i=
s called in
Quoted 1 line
bcache_init()with many other functions, if one of the previous c=
alling
Quoted 3 lines
onces failed,
bcache_exit()will be called in the failure path. =20
The problem is, ifbcache_init()fails before bch_debug_i=
nit() is called,
Quoted 1 line
then in
bcache_exit()whenbch_debug_exit()is called to =
destroy global
Quoted 1 line
variable
bcache_debug, at this momentbcache_debugis unndefi=
ned, then the
Quoted 1 line
test of "if (!IS_ERR_OR_NULL(bcache_debug))�
CI- might be buggy.
Quoted 2 lines
=20
This patch initializes global varabilebcache_debugto be NULL, t=
o make
Quoted 11 lines
the failure code path to be predictable.
=20Signed-off-by Coly Li <[email protected]>--- drivers/md/bcache/debug.c | 2 +-- 1 file changed, 1 insertion(+-), 1 deletion(-)=20
drivers/md/bcache/debug.c +1
-1--- a/drivers/md/bcache/debug.c +-+-+- b/drivers/md/bcache/debug.c
Quoted 8 lines
@@ -17,7 +-17,7 @@
#include <linux/random.h>
#include <linux/seq_file.h>
=20
-struct dentry*bcache_debug;
+-struct dentry*bcache_debug= NULL;
=20
#ifdefCONFIG_BCACHE_DEBUG
Please verify patches with checkpatch before posting these. Checkpatch is n= amely
able to detect that this patch is useless:
$ scripts/checkpatch.pl \[PATCH_8_9\]_bcache\:= _initiate_bcache_debug_to_NULL.mbox=20 ERROR: do not initialise globals to NULL #217: FILE: drivers/md/bcache/debug.c:20: +-struct dentry *bcache_debug = NULL;
Bart.
Re: [PATCH 8/9] bcache: initiate bcache_debug to NULL
In reply to Noah MasseyQuoted 15 lines · Noah Massey
Quoted 13 lines · Coly Li
Global variable
bcache_debugis firstly initialized inbch_debug_init(), and destroyed inbch_debug_exit().bch_debug_init()is called inbcache_init()with many other functions, if one of the previous calling onces failed,bcache_exit()will be called in the failure path.The problem is, if
bcache_init()fails beforebch_debug_init()is called, then inbcache_exit()whenbch_debug_exit()is called to destroy global variablebcache_debug, at this momentbcache_debugis unndefined, then the test of "if (!IS_ERR_OR_NULL(bcache_debug))" might be buggy.This patch initializes global varabile
bcache_debugto be NULL, to make the failure code path to be predictable.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Coly Li <[email protected]>---
Makes sense
Reviewed-by Noah Massey <[email protected]>
Aren't global variables zeroed by default anyway?
Quoted 24 lines
drivers/md/bcache/debug.c | 2 +-Quoted 23 lines
1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/bcache/debug.c +1
-2@@ -17,7 +17,7 @@#include <linux/random.h> #include <linux/seq_file.h> -struct dentry *bcache_debug; +struct dentry *bcache_debug =NULL ;#ifdef CONFIG_BCACHE_DEBUG --2.17.1
--
To unsubscribe from this list: send the line "unsubscribe linux-bcache" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Vojtech Pavlik Director SUSE Labs
Re: [PATCH 8/9] bcache: initiate bcache_debug to NULL
In reply to Noah MasseyQuoted 20 lines · Noah Massey
Quoted 19 lines · Noah Massey
Quoted 16 lines · Coly Li
Global variable
bcache_debugis firstly initialized inbch_debug_init(), and destroyed inbch_debug_exit().bch_debug_init()is called inbcache_init()with many other functions, if one of the previous calling onces failed,bcache_exit()will be called in the failure path.The problem is, if
bcache_init()fails beforebch_debug_init()is called, then inbcache_exit()whenbch_debug_exit()is called to destroy global variablebcache_debug, at this momentbcache_debugis unndefined, then the test of "if (!IS_ERR_OR_NULL(bcache_debug))" might be buggy.This patch initializes global varabile
bcache_debugto be NULL, to make the failure code path to be predictable.Signed-off-by Coly Li <[email protected]>---
Quoted 7 lines
Quoted 4 lines
Makes sense
Reviewed-by Noah Massey <[email protected]>Wait... aren't static variables already initialized to 0?
So this makes it explicit, but no code change to generated binary, right?
Hi Noah, Vojtech and Bart,
You are right, of course. I just notice this is already in C11 (and early versions) for static duration storage,
6.7.9 Initialization
10 If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. If an object that has static or thread storage duration is not initialized explicitly, then:
— if it has pointer type, it is initialized to a null pointer; — if it has arithmetic type, it is initialized to (positive or unsigned) zero;
— if it is an aggregate, every member is initialized (recursively) according to these rules, and any padding is initialized to zero bits; — if it is a union, the first named member is initialized (recursively) according to these rules, and any padding is initialized to zero bits;
Then this patch is useless, it is unnecessary.
Thank you all for the comments, I am about to read the C11 document :-)
Coly Li