bcache: remove multiple caches code framework
Subsystems (3)
v2 cover bcache: remove multiple caches code framework
The multiple caches code framework in bcache is to store multiple copies of the cached data among multiple caches of the cache set. Current code framework just does simple data write to each cache without any extra condition handling (e.g. device failure, slow devices). This code framework is not and will never be completed. Considering people may use md raid1 for same similar data duplication purpose, the multiple caches framework is useless dead code indeed.
Due to the multiple caches code framework, bcache has two data structure struct cache and struct cache_set to manage the cache device. Indeed since bcache was merged into mainline kernel in Linux v3.10, a cache set only has one cache, the unnecessary two level abstraction makes extra effort to maintain redundant information between struct cache and struct cache set, for examaple the in-memmory super block struct cache_sb.
This is the first wave effort to remove multiple caches framework and make the code and data structure relation to be more clear. This series explicitly make each cache set only have single cache, and remove the embedded partial super block in struct cache_set and directly reference cache's in-memory super block.
The patch set now passes basic smoking testing, I post this series early for your review and comments. More fixes after testing will follow up soon.
Thanks in advance.
Coly Li
---
Changelog:
v2: Add reviewed-by from Hannes Reinecke, update patches by suggestion
from Hannes and Christoph.
v1: initial version.
Coly Li (12):
bcache: remove 'int n' from parameter list of bch_bucket_alloc_set()
bcache: explicitly make cache_set only have single cache
bcache: remove for_each_cache()
bcache: add set_uuid in struct cache_set
bcache: only use block_bytes() on struct cache
bcache: remove useless alloc_bucket_pages()
bcache: remove useless bucket_pages()
bcache: only use bucket_bytes() on struct cache
bcache: don't check seq numbers in register_cache_set()
bcache: remove can_attach_cache()
bcache: check and set sync status on cache's in-memory super block
bcache: remove embedded struct cache_sb from struct cache_set
drivers/md/bcache/alloc.c | 60 ++++----- drivers/md/bcache/bcache.h | 29 ++-- drivers/md/bcache/btree.c | 144 ++++++++++---------- drivers/md/bcache/btree.h | 2 +- drivers/md/bcache/debug.c | 10 +- drivers/md/bcache/extents.c | 6 +- drivers/md/bcache/features.c | 4 +- drivers/md/bcache/io.c | 2 +- drivers/md/bcache/journal.c | 246 ++++++++++++++++------------------ drivers/md/bcache/movinggc.c | 58 ++++---- drivers/md/bcache/request.c | 6 +- drivers/md/bcache/super.c | 232 ++++++++++++-------------------- drivers/md/bcache/sysfs.c | 10 +- drivers/md/bcache/writeback.c | 2 +- include/trace/events/bcache.h | 4 +- 15 files changed, 352 insertions(+), 463 deletions(-)
Signature · 1 line
2.26.2
PATCH v2 1/12 bcache: remove 'int n' from parameter list of bch_bucket_alloc_set()
The parameter 'int n' from bch_bucket_alloc_set() is not cleared defined. From the code comments n is the number of buckets to alloc, but from the code itself 'n' is the maximum cache to iterate. Indeed all the locations where bch_bucket_alloc_set() is called, 'n' is alwasy 1.
This patch removes the confused and unnecessary 'int n' from parameter list of bch_bucket_alloc_set(), and explicitly allocates only 1 bucket for its caller.
--- drivers/md/bcache/alloc.c | 35 +++++++++++++++-------------------- drivers/md/bcache/bcache.h | 4 ++-- drivers/md/bcache/btree.c | 2 +- drivers/md/bcache/super.c | 2 +- 4 files changed, 19 insertions(+), 24 deletions(-)
drivers/md/bcache/alloc.c +15 -20
@@ -49,7 +49,7 @@* * bch_bucket_alloc() allocates a single bucket from a specific cache. * -* bch_bucket_alloc_set() allocates one or more buckets from different caches +* bch_bucket_alloc_set() allocates one bucket from different caches * out of a cache set. * * free_some_buckets() drives all the processes described above. It's called
@@ -488,34 +488,29 @@ void bch_bucket_free(struct cache_set *c, struct bkey *k) }int __bch_bucket_alloc_set (struct cache_set *c,unsigned int reserve, -struct bkey *k,int n,bool wait) +struct bkey *k,bool wait) { -int i; +struct cache *ca; +long b;/* No allocation if CACHE_SET_IO_DISABLE bit is set */ if (unlikely (test_bit (CACHE_SET_IO_DISABLE , &c->flags)))return -1 ;lockdep_assert_held (&c->bucket_lock); -BUG_ON (!n || n > c->caches_loaded || n >MAX_CACHES_PER_SET );bkey_init (k); -/* sort by free space/prio of oldest data in caches */ - -for (i =0 ; i < n; i++) { -struct cache *ca = c->cache_by_alloc[i]; -long b =bch_bucket_alloc (ca, reserve, wait); + ca = c->cache_by_alloc[0 ]; + b =bch_bucket_alloc (ca, reserve, wait); +if (b ==-1 ) + goto err; -if (b ==-1 ) - goto err; + k->ptr[0 ] =MAKE_PTR (ca->buckets[b].gen, +bucket_to_sector (c, b), + ca->sb.nr_this_dev); - k->ptr[i] =MAKE_PTR (ca->buckets[b].gen, -bucket_to_sector (c, b), - ca->sb.nr_this_dev); - -SET_KEY_PTRS (k, i +1 ); - } +SET_KEY_PTRS (k,1 );return 0 ; err:
@@ -525,12 +520,12 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve, }int bch_bucket_alloc_set (struct cache_set *c,unsigned int reserve, -struct bkey *k,int n,bool wait) +struct bkey *k,bool wait) {int ret;mutex_lock (&c->bucket_lock); - ret =__bch_bucket_alloc_set (c, reserve, k, n, wait); + ret =__bch_bucket_alloc_set (c, reserve, k, wait);mutex_unlock (&c->bucket_lock);return ret; }
@@ -638,7 +633,7 @@ bool bch_alloc_sectors(struct cache_set *c,spin_unlock (&c->data_bucket_lock); -if (bch_bucket_alloc_set (c, watermark, &alloc.key,1 , wait)) +if (bch_bucket_alloc_set (c, watermark, &alloc.key, wait))return false;spin_lock (&c->data_bucket_lock);
drivers/md/bcache/bcache.h +2 -2
@@ -994,9 +994,9 @@ void bch_bucket_free(struct cache_set *c, struct bkey *k);long bch_bucket_alloc (struct cache *ca,unsigned int reserve,bool wait);int __bch_bucket_alloc_set (struct cache_set *c,unsigned int reserve, -struct bkey *k,int n,bool wait); +struct bkey *k,bool wait);int bch_bucket_alloc_set (struct cache_set *c,unsigned int reserve, -struct bkey *k,int n,bool wait); +struct bkey *k,bool wait);bool bch_alloc_sectors (struct cache_set *c,struct bkey *k,unsigned int sectors,unsigned int write_point,unsigned int write_prio,bool wait);
drivers/md/bcache/btree.c +1 -1
@@ -1091,7 +1091,7 @@ struct btree *__bch_btree_node_alloc(struct cache_set *c, struct btree_op *op,mutex_lock (&c->bucket_lock); retry: -if (__bch_bucket_alloc_set (c,RESERVE_BTREE , &k.key,1 , wait)) +if (__bch_bucket_alloc_set (c,RESERVE_BTREE , &k.key, wait)) goto err;bkey_put (c, &k.key);
drivers/md/bcache/super.c +1 -1
@@ -486,7 +486,7 @@ static int __uuid_write(struct cache_set *c)closure_init_stack (&cl);lockdep_assert_held (&bch_register_lock); -if (bch_bucket_alloc_set (c,RESERVE_BTREE , &k.key,1 , true)) +if (bch_bucket_alloc_set (c,RESERVE_BTREE , &k.key, true))return 1 ; size =meta_bucket_pages (&c->sb) *PAGE_SECTORS ;
Signature · 1 line
2.26.2
PATCH v2 2/12 bcache: explicitly make cache_set only have single cache
In reply to Coly LiCurrently although the bcache code has a framework for multiple caches in a cache set, but indeed the multiple caches never completed and users use md raid1 for multiple copies of the cached data.
This patch does the following change in struct cache_set, to explicitly make a cache_set only have single cache,
- Change pointer array "*cache[MAX_CACHES_PER_SET]" to a single pointer "*cache".
- Remove pointer array "*cache_by_alloc[MAX_CACHES_PER_SET]".
- Remove "caches_loaded".
Now the code looks as exactly what it does in practic: only one cache is used in the cache set.
--- drivers/md/bcache/alloc.c | 2 +- drivers/md/bcache/bcache.h | 8 +++----- drivers/md/bcache/super.c | 19 ++++++++----------- 3 files changed, 12 insertions(+), 17 deletions(-)
drivers/md/bcache/alloc.c +1 -1
@@ -501,7 +501,7 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,bkey_init (k); - ca = c->cache_by_alloc[0 ]; + ca = c->cache; b =bch_bucket_alloc (ca, reserve, wait);if (b ==-1 ) goto err;
drivers/md/bcache/bcache.h +3 -5
@@ -519,9 +519,7 @@ struct cache_set {struct cache_sb sb; -struct cache *cache[MAX_CACHES_PER_SET ]; -struct cache *cache_by_alloc[MAX_CACHES_PER_SET ]; -int caches_loaded; +struct cache *cache;struct bcache_device **devices;unsigned int devices_max_used;
@@ -808,7 +806,7 @@ static inline struct cache *PTR_CACHE(struct cache_set *c, const struct bkey *k, unsigned int ptr) { -return c->cache[PTR_DEV (k, ptr)]; +return c->cache; } static inline size_t PTR_BUCKET_NR(struct cache_set *c,
@@ -890,7 +888,7 @@ do { \/* Looping macros */ #define for_each_cache (ca, cs, iter) \ - for (iter = 0; ca = cs->cache[iter], iter < (cs)->sb.nr_in_set; iter++) + for (iter = 0; ca = cs->cache, iter < 1; iter++)#define for_each_bucket (b, ca) \ for (b = (ca)->buckets + (ca)->sb.first_bucket; \
drivers/md/bcache/super.c +8 -11
@@ -1675,7 +1675,7 @@ static void cache_set_free(struct closure *cl)for_each_cache (ca, c, i)if (ca) { ca->set =NULL ; - c->cache[ca->sb.nr_this_dev] =NULL ; + c->cache =NULL ;kobject_put (&ca->kobj); }
@@ -2166,7 +2166,7 @@ static const char *register_cache_set(struct cache *ca)list_for_each_entry (c, &bch_cache_sets, list)if (!memcmp (c->sb.set_uuid, ca->sb.set_uuid,16 )) { -if (c->cache[ca->sb.nr_this_dev]) +if (c->cache)return "duplicate cache set member" ;if (!can_attach_cache (ca, c))
@@ -2216,14 +2216,11 @@ static const char *register_cache_set(struct cache *ca)kobject_get (&ca->kobj); ca->set = c; - ca->set->cache[ca->sb.nr_this_dev] = ca; - c->cache_by_alloc[c->caches_loaded++] = ca; + ca->set->cache = ca; -if (c->caches_loaded == c->sb.nr_in_set) { - err ="failed to run cache set" ; -if (run_cache_set (c) <0 ) - goto err; - } + err ="failed to run cache set" ; +if (run_cache_set (c) <0 ) + goto err;return NULL ; err:
@@ -2240,8 +2237,8 @@ void bch_cache_release(struct kobject *kobj)unsigned int i;if (ca->set) { -BUG_ON (ca->set->cache[ca->sb.nr_this_dev] != ca); - ca->set->cache[ca->sb.nr_this_dev] =NULL ; +BUG_ON (ca->set->cache != ca); + ca->set->cache =NULL ; }free_pages ((unsigned long ) ca->disk_buckets,ilog2 (meta_bucket_pages (&ca->sb)));
Signature · 1 line
2.26.2
Re: [PATCH v2 02/12] bcache: explicitly make cache_set only have single cache
Quoted 72 lines · Coly Li
Currently although the bcache code has a framework for multiple caches in a cache set, but indeed the multiple caches never completed and users use md raid1 for multiple copies of the cached data.
This patch does the following change in struct
cache_set, to explicitly make acache_setonly have single cache,
- Change pointer array "*cache[MAX_CACHES_PER_SET]" to a single pointer "*cache".
- Remove pointer array "*cache_by_alloc[MAX_CACHES_PER_SET]".
- Remove "caches_loaded".Now the code looks as exactly what it does in practic: only one cache is used in the cache set.
Signed-off-by Coly Li <[email protected]>--- drivers/md/bcache/alloc.c | 2 +- drivers/md/bcache/bcache.h | 8 +++----- drivers/md/bcache/super.c | 19 ++++++++----------- 3 files changed, 12 insertions(+), 17 deletions(-)drivers/md/bcache/alloc.c +1
-1@@ -501,7 +501,7 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,bkey_init (k); - ca = c->cache_by_alloc[0 ]; + ca = c->cache; b =bch_bucket_alloc (ca, reserve, wait);if (b ==-1 ) goto err;drivers/md/bcache/bcache.h +3
-5@@ -519,9 +519,7 @@ struct cache_set {struct cache_sb sb; -struct cache *cache[MAX_CACHES_PER_SET ]; -struct cache *cache_by_alloc[MAX_CACHES_PER_SET ]; -int caches_loaded; +struct cache *cache;struct bcache_device **devices;unsigned int devices_max_used;@@ -808,7 +806,7 @@ static inline struct cache *PTR_CACHE(struct cache_set *c, const struct bkey *k, unsigned int ptr) { -return c->cache[PTR_DEV (k, ptr)]; +return c->cache; } static inline size_t PTR_BUCKET_NR(struct cache_set *c,@@ -890,7 +888,7 @@ do { \/* Looping macros */ #define for_each_cache (ca, cs, iter) \ - for (iter = 0; ca = cs->cache[iter], iter < (cs)->sb.nr_in_set; iter++) + for (iter = 0; ca = cs->cache, iter < 1; iter++)#define for_each_bucket (b, ca) \ for (b = (ca)->buckets + (ca)->sb.first_bucket; \drivers/md/bcache/super.c +0
-0
drivers/md/bcache/super.c static void cache_set_free(struct closure *cl) · line 1681
Quoted 8 lines
drivers/md/bcache/super.c +1
-1@@ -1675,7 +1675,7 @@ static void cache_set_free(struct closure *cl)for_each_cache (ca, c, i)if (ca) { ca->set =NULL ; - c->cache[ca->sb.nr_this_dev] =NULL ; + c->cache =NULL ;kobject_put (&ca->kobj); }
Please kill 'for_each_cache()', too, and replace it by an if clause.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v2 02/12] bcache: explicitly make cache_set only have single cache
Quoted 69 lines · Hannes Reinecke
Quoted 68 lines · Coly Li
Currently although the bcache code has a framework for multiple caches in a cache set, but indeed the multiple caches never completed and users use md raid1 for multiple copies of the cached data.
This patch does the following change in struct
cache_set, to explicitly make acache_setonly have single cache,
- Change pointer array "*cache[MAX_CACHES_PER_SET]" to a single pointer "*cache".
- Remove pointer array "*cache_by_alloc[MAX_CACHES_PER_SET]".
- Remove "caches_loaded".Now the code looks as exactly what it does in practic: only one cache is used in the cache set.
Signed-off-by Coly Li <[email protected]>---
drivers/md/bcache/alloc.c | 2 +-drivers/md/bcache/bcache.h| 8 +++----- drivers/md/bcache/super.c | 19 ++++++++-----------3 files changed, 12 insertions(+), 17 deletions(-)drivers/md/bcache/alloc.c +1
-0@@ -501,7 +501,7 @@ int __bch_bucket_alloc_set(struct cache_set *c,unsigned int reserve, bkey_init(k); - ca = c->cache_by_alloc[0]; + ca = c->cache; b = bch_bucket_alloc(ca, reserve, wait); if (b == -1) goto err;drivers/md/bcache/bcache.h +3
-4@@ -519,9 +519,7 @@ struct cache_set { struct cache_sb sb; - struct cache *cache[MAX_CACHES_PER_SET]; - struct cache *cache_by_alloc[MAX_CACHES_PER_SET]; - int caches_loaded; + struct cache *cache; struct bcache_device **devices; unsigned int devices_max_used;@@ -808,7 +806,7 @@ static inline struct cache *PTR_CACHE(struct cache_set *c, const struct bkey *k, unsigned int ptr) { - return c->cache[PTR_DEV(k, ptr)]; + return c->cache; } static inline size_t PTR_BUCKET_NR(struct cache_set *c,@@ -890,7 +888,7 @@ do { \ /* Looping macros */ #define for_each_cache(ca, cs, iter) \ - for (iter = 0; ca = cs->cache[iter], iter < (cs)->sb.nr_in_set; iter++) + for (iter = 0; ca = cs->cache, iter < 1; iter++) #define for_each_bucket(b, ca) \ for (b = (ca)->buckets + (ca)->sb.first_bucket; \drivers/md/bcache/super.c +0
-0@@ -1675,7 +1675,7 @@ static void cache_set_free(struct closure *cl) for_each_cache(ca, c, i)
Quoted 8 lines
Quoted 7 lines
drivers/md/bcache/super.c +1
-1if (ca) { ca->set = NULL; - c->cache[ca->sb.nr_this_dev] = NULL; + c->cache = NULL; kobject_put(&ca->kobj); }Please kill '
for_each_cache()', too, and replace it by an if clause.
Yes, it is done in next patch: [PATCH v2 03/12] bcache: remove for_each_cache()
Thanks.
Coly Li
PATCH v2 3/12 bcache: remove for_each_cache()
In reply to Coly LiSince now each cache_set explicitly has single cache, for_each_cache() is unnecessary. This patch removes this macro, and update all locations where it is used, and makes sure all code logic still being consistent.
--- drivers/md/bcache/alloc.c | 17 ++- drivers/md/bcache/bcache.h | 9 +- drivers/md/bcache/btree.c | 103 +++++++--------- drivers/md/bcache/journal.c | 229 ++++++++++++++++------------------- drivers/md/bcache/movinggc.c | 58 +++++---- drivers/md/bcache/super.c | 115 ++++++++---------- 6 files changed, 237 insertions(+), 294 deletions(-)
drivers/md/bcache/alloc.c +8 -9
@@ -88,7 +88,6 @@ void bch_rescale_priorities(struct cache_set *c, int sectors)struct cache *ca;struct bucket *b;unsigned long next = c->nbuckets * c->sb.bucket_size /1024 ; -unsigned int i;int r;atomic_sub (sectors, &c->rescale);
@@ -104,14 +103,14 @@ void bch_rescale_priorities(struct cache_set *c, int sectors) c->min_prio =USHRT_MAX ; -for_each_cache (ca, c, i) -for_each_bucket (b, ca) -if (b->prio && - b->prio !=BTREE_PRIO && - !atomic_read (&b->pin)) { - b->prio--; - c->min_prio =min (c->min_prio, b->prio); - } + ca = c->cache; +for_each_bucket (b, ca) +if (b->prio && + b->prio !=BTREE_PRIO && + !atomic_read (&b->pin)) { + b->prio--; + c->min_prio =min (c->min_prio, b->prio); + }mutex_unlock (&c->bucket_lock); }
drivers/md/bcache/bcache.h +2 -7
@@ -887,9 +887,6 @@ do { \/* Looping macros */ -#define for_each_cache (ca, cs, iter) \ - for (iter = 0; ca = cs->cache, iter < 1; iter++) -#define for_each_bucket (b, ca) \ for (b = (ca)->buckets + (ca)->sb.first_bucket; \ b < (ca)->buckets + (ca)->sb.nbuckets; b++)
@@ -931,11 +928,9 @@ static inline uint8_t bucket_gc_gen(struct bucket *b)static inline void wake_up_allocators (struct cache_set *c) { -struct cache *ca; -unsigned int i; +struct cache *ca = c->cache; -for_each_cache (ca, c, i) -wake_up_process (ca->alloc_thread); +wake_up_process (ca->alloc_thread); } static inline void closure_bio_submit(struct cache_set *c,
drivers/md/bcache/btree.c +47 -56
171 lines not on this page · raw message
drivers/md/bcache/journal.c +104 -125
299 lines not on this page · raw message
drivers/md/bcache/movinggc.c +28 -30
78 lines not on this page · raw message
drivers/md/bcache/super.c +48 -67
218 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 4/12 bcache: add set_uuid in struct cache_set
In reply to Coly LiThis patch adds a separated set_uuid[16] in struct cache_set, to store the uuid of the cache set. This is the preparation to remove the embedded struct cache_sb from struct cache_set.
--- drivers/md/bcache/bcache.h | 1 + drivers/md/bcache/debug.c | 2 +- drivers/md/bcache/super.c | 24 ++++++++++++------------ include/trace/events/bcache.h | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-)
drivers/md/bcache/bcache.h +1 -0
@@ -668,6 +668,7 @@ struct cache_set {struct mutex verify_lock;#endif +uint8_t set_uuid[16 ];unsigned int nr_uuids;struct uuid_entry *uuids;BKEY_PADDED (uuid_bucket);
drivers/md/bcache/debug.c +1 -1
@@ -238,7 +238,7 @@ void bch_debug_init_cache_set(struct cache_set *c)if (!IS_ERR_OR_NULL (bcache_debug)) {char name[50 ]; -snprintf (name,50 ,"bcache-%pU" , c->sb.set_uuid); +snprintf (name,50 ,"bcache-%pU" , c->set_uuid); c->debug =debugfs_create_file (name,0400 , bcache_debug, c, &cache_set_debug_ops); }
drivers/md/bcache/super.c +12 -12
@@ -1189,8 +1189,8 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,struct cached_dev *exist_dc, *t;int ret =0 ; -if ((set_uuid &&memcmp (set_uuid, c->sb.set_uuid,16 )) || - (!set_uuid &&memcmp (dc->sb.set_uuid, c->sb.set_uuid,16 ))) +if ((set_uuid &&memcmp (set_uuid, c->set_uuid,16 )) || + (!set_uuid &&memcmp (dc->sb.set_uuid, c->set_uuid,16 )))return -ENOENT ;if (dc->disk.c) {
@@ -1262,7 +1262,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c, u->first_reg = u->last_reg = rtime;bch_uuid_write (c); -memcpy (dc->sb.set_uuid, c->sb.set_uuid,16 ); +memcpy (dc->sb.set_uuid, c->set_uuid,16 );SET_BDEV_STATE (&dc->sb,BDEV_STATE_CLEAN );bch_write_bdev_super (dc, &cl);
@@ -1324,7 +1324,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,pr_info ("Caching %s as %s on set %pU\n" , dc->backing_dev_name, dc->disk.disk->disk_name, - dc->disk.c->sb.set_uuid); + dc->disk.c->set_uuid);return 0 ; }
@@ -1632,7 +1632,7 @@ bool bch_cache_set_error(struct cache_set *c, const char *fmt, ...) vaf.va = &args;pr_err ("error on %pU: %pV, disabling caching\n" , - c->sb.set_uuid, &vaf); + c->set_uuid, &vaf);va_end (args);
@@ -1685,7 +1685,7 @@ static void cache_set_free(struct closure *cl)list_del (&c->list);mutex_unlock (&bch_register_lock); -pr_info ("Cache set %pU unregistered\n" , c->sb.set_uuid); +pr_info ("Cache set %pU unregistered\n" , c->set_uuid);wake_up (&unregister_wait);closure_debug_destroy (&c->cl);
@@ -1755,7 +1755,7 @@ static void conditional_stop_bcache_device(struct cache_set *c, {if (dc->stop_when_cache_set_failed ==BCH_CACHED_DEV_STOP_ALWAYS ) {pr_warn ("stop_when_cache_set_failed of %s is \"always\", stop it for failed cache set %pU.\n" , - d->disk->disk_name, c->sb.set_uuid); + d->disk->disk_name, c->set_uuid);bcache_device_stop (d); }else if (atomic_read (&dc->has_dirty)) {/*
@@ -1862,7 +1862,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)bch_cache_accounting_init (&c->accounting, &c->cl); -memcpy (c->sb.set_uuid, sb->set_uuid,16 ); +memcpy (c->set_uuid, sb->set_uuid,16 ); c->sb.block_size = sb->block_size; c->sb.bucket_size = sb->bucket_size; c->sb.nr_in_set = sb->nr_in_set;
@@ -2145,7 +2145,7 @@ static const char *register_cache_set(struct cache *ca)struct cache_set *c;list_for_each_entry (c, &bch_cache_sets, list) -if (!memcmp (c->sb.set_uuid, ca->sb.set_uuid,16 )) { +if (!memcmp (c->set_uuid, ca->sb.set_uuid,16 )) {if (c->cache)return "duplicate cache set member" ;
@@ -2163,7 +2163,7 @@ static const char *register_cache_set(struct cache *ca)return err; err ="error creating kobject" ; -if (kobject_add (&c->kobj, bcache_kobj,"%pU" , c->sb.set_uuid) || +if (kobject_add (&c->kobj, bcache_kobj,"%pU" , c->set_uuid) ||kobject_add (&c->internal, &c->kobj,"internal" )) goto err;
@@ -2188,7 +2188,7 @@ static const char *register_cache_set(struct cache *ca)*/ if (ca->sb.seq > c->sb.seq || c->sb.seq ==0 ) { c->sb.version = ca->sb.version; -memcpy (c->sb.set_uuid, ca->sb.set_uuid,16 ); +memcpy (c->set_uuid, ca->sb.set_uuid,16 ); c->sb.flags = ca->sb.flags; c->sb.seq = ca->sb.seq;pr_debug ("set version = %llu\n" , c->sb.version);
@@ -2698,7 +2698,7 @@ static ssize_t bch_pending_bdevs_cleanup(struct kobject *k,list_for_each_entry_safe (pdev, tpdev, &pending_devs, list) {list_for_each_entry_safe (c, tc, &bch_cache_sets, list) {char *pdev_set_uuid = pdev->dc->sb.set_uuid; -char *set_uuid = c->sb.uuid; +char *set_uuid = c->set_uuid;if (!memcmp (pdev_set_uuid, set_uuid,16 )) {list_del (&pdev->list);
include/trace/events/bcache.h +2 -2
@@ -164,7 +164,7 @@ TRACE_EVENT(bcache_write, ), TP_fast_assign( - memcpy(__entry->uuid, c->sb.set_uuid, 16); + memcpy(__entry->uuid, c->set_uuid, 16); __entry->inode = inode; __entry->sector = bio->bi_iter.bi_sector; __entry->nr_sector = bio->bi_iter.bi_size >>9 ;
@@ -200,7 +200,7 @@ DECLARE_EVENT_CLASS(cache_set, ),TP_fast_assign ( - memcpy(__entry->uuid, c->sb.set_uuid, 16); + memcpy(__entry->uuid, c->set_uuid, 16); ),TP_printk ("%pU" , __entry->uuid)
Signature · 1 line
2.26.2
PATCH v2 5/12 bcache: only use block_bytes() on struct cache
In reply to Coly LiBecause struct cache_set and struct cache both have struct cache_sb, therefore macro block_bytes() can be used on both of them. When removing the embedded struct cache_sb from struct cache_set, this macro won't be used on struct cache_set anymore.
This patch unifies all block_bytes() usage only on struct cache, this is one of the preparation to remove the embedded struct cache_sb from struct cache_set.
--- drivers/md/bcache/bcache.h | 2 +- drivers/md/bcache/btree.c | 24 ++++++++++++------------ drivers/md/bcache/debug.c | 8 ++++---- drivers/md/bcache/journal.c | 8 ++++---- drivers/md/bcache/request.c | 2 +- drivers/md/bcache/super.c | 2 +- drivers/md/bcache/sysfs.c | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-)
drivers/md/bcache/bcache.h +1 -1
@@ -759,7 +759,7 @@ struct bbio {#define bucket_pages (c) ((c)->sb.bucket_size / PAGE_SECTORS)#define bucket_bytes (c) ((c)->sb.bucket_size << 9) -#define block_bytes (c) ((c)->sb.block_size << 9) +#define block_bytes (ca) ((ca)->sb.block_size << 9)static inline unsigned int meta_bucket_pages (struct cache_sb *sb) {
drivers/md/bcache/btree.c +12 -12
@@ -104,7 +104,7 @@static inline struct bset *write_block (struct btree *b) { -return ((void *)btree_bset_first (b)) + b->written *block_bytes (b->c); +return ((void *)btree_bset_first (b)) + b->written *block_bytes (b->c->cache); }static void bch_btree_init_next (struct btree *b)
@@ -173,7 +173,7 @@ void bch_btree_node_read_done(struct btree *b) goto err; err ="bad btree header" ; -if (b->written +set_blocks (i,block_bytes (b->c)) > +if (b->written +set_blocks (i,block_bytes (b->c->cache)) >btree_blocks (b)) goto err;
@@ -199,13 +199,13 @@ void bch_btree_node_read_done(struct btree *b)bch_btree_iter_push (iter, i->start,bset_bkey_last (i)); - b->written +=set_blocks (i,block_bytes (b->c)); + b->written +=set_blocks (i,block_bytes (b->c->cache)); } err ="corrupted btree" ;for (i =write_block (b);bset_sector_offset (&b->keys, i) <KEY_SIZE (&b->key); - i = ((void *) i) +block_bytes (b->c)) + i = ((void *) i) +block_bytes (b->c->cache))if (i->seq == b->keys.set[0 ].data->seq) goto err;
@@ -347,7 +347,7 @@ static void do_btree_node_write(struct btree *b) b->bio->bi_end_io = btree_node_write_endio; b->bio->bi_private = cl; - b->bio->bi_iter.bi_size =roundup (set_bytes (i),block_bytes (b->c)); + b->bio->bi_iter.bi_size =roundup (set_bytes (i),block_bytes (b->c->cache)); b->bio->bi_opf =REQ_OP_WRITE |REQ_META |REQ_FUA ;bch_bio_map (b->bio, i);
@@ -423,10 +423,10 @@ void __bch_btree_node_write(struct btree *b, struct closure *parent)do_btree_node_write (b); -atomic_long_add (set_blocks (i,block_bytes (b->c)) * b->c->sb.block_size, +atomic_long_add (set_blocks (i,block_bytes (b->c->cache)) * b->c->sb.block_size, &PTR_CACHE (b->c, &b->key,0 )->btree_sectors_written); - b->written +=set_blocks (i,block_bytes (b->c)); + b->written +=set_blocks (i,block_bytes (b->c->cache)); }void bch_btree_node_write (struct btree *b,struct closure *parent)
@@ -1344,7 +1344,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op,if (nodes <2 ||__set_blocks (b->keys.set[0 ].data, keys, -block_bytes (b->c)) > blocks * (nodes -1 )) +block_bytes (b->c->cache)) > blocks * (nodes -1 ))return 0 ;for (i =0 ; i < nodes; i++) {
@@ -1378,7 +1378,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, k = bkey_next(k)) {if (__set_blocks (n1, n1->keys + keys +bkey_u64s (k), -block_bytes (b->c)) > blocks) +block_bytes (b->c->cache)) > blocks)break ; last = k;
@@ -1394,7 +1394,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op,* though) */ if (__set_blocks (n1, n1->keys + n2->keys, -block_bytes (b->c)) > +block_bytes (b->c->cache)) >btree_blocks (new_nodes[i])) goto out_unlock_nocoalesce;
@@ -1403,7 +1403,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, last = &r->b->key; } -BUG_ON (__set_blocks (n1, n1->keys + keys,block_bytes (b->c)) > +BUG_ON (__set_blocks (n1, n1->keys + keys,block_bytes (b->c->cache)) >btree_blocks (new_nodes[i]));if (last)
@@ -2210,7 +2210,7 @@ static int btree_split(struct btree *b, struct btree_op *op, goto err; split =set_blocks (btree_bset_first (n1), -block_bytes (n1->c)) > (btree_blocks (b) *4 ) /5 ; +block_bytes (n1->c->cache)) > (btree_blocks (b) *4 ) /5 ;if (split) {unsigned int keys =0 ;
drivers/md/bcache/debug.c +4 -4
@@ -25,8 +25,8 @@ struct dentry *bcache_debug;for (i = (start); \ (void *) i < (void *) (start) + (KEY_SIZE (&b->key) <<9 ) &&\ i->seq == (start)->seq; \ - i = (void *) i +set_blocks (i,block_bytes (b->c)) * \ -block_bytes (b->c)) + i = (void *) i +set_blocks (i,block_bytes (b->c->cache)) * \ +block_bytes (b->c->cache)) void bch_btree_verify(struct btree *b) {
@@ -82,14 +82,14 @@ void bch_btree_verify(struct btree *b)for_each_written_bset (b, ondisk, i) {unsigned int block = ((void *) i - (void *) ondisk) / -block_bytes (b->c); +block_bytes (b->c->cache);pr_err ("*** on disk block %u:\n" , block);bch_dump_bset (&b->keys, i, block); }pr_err ("*** block %zu not written\n" , - ((void *) i - (void *) ondisk) /block_bytes (b->c)); + ((void *) i - (void *) ondisk) /block_bytes (b->c->cache));for (j =0 ; j < inmemory->keys; j++)if (inmemory->d[j] != sorted->d[j])
drivers/md/bcache/journal.c +4 -4
@@ -98,7 +98,7 @@ reread: left = ca->sb.bucket_size - offset;return ret; } - blocks =set_blocks (j,block_bytes (ca->set)); + blocks =set_blocks (j,block_bytes (ca));/* * Nodes in 'list' are in linear increasing order of
@@ -734,7 +734,7 @@ static void journal_write_unlocked(struct closure *cl)struct cache *ca = c->cache;struct journal_write *w = c->journal.cur;struct bkey *k = &c->journal.key; -unsigned int i, sectors =set_blocks (w->data,block_bytes (c)) * +unsigned int i, sectors =set_blocks (w->data,block_bytes (ca)) * c->sb.block_size;struct bio *bio;
@@ -754,7 +754,7 @@ static void journal_write_unlocked(struct closure *cl)return ; } - c->journal.blocks_free -=set_blocks (w->data,block_bytes (c)); + c->journal.blocks_free -=set_blocks (w->data,block_bytes (ca)); w->data->btree_level = c->root->level;
@@ -847,7 +847,7 @@ static struct journal_write *journal_wait_for_write(struct cache_set *c,struct journal_write *w = c->journal.cur; sectors =__set_blocks (w->data, w->data->keys + nkeys, -block_bytes (c)) * c->sb.block_size; +block_bytes (c->cache)) * c->sb.block_size; if (sectors <= min_t(size_t, c->journal.blocks_free * c->sb.block_size,
drivers/md/bcache/request.c +1 -1
@@ -99,7 +99,7 @@ static int bch_keylist_realloc(struct keylist *l, unsigned int u64s,* 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 )) +if (newsize *sizeof (uint64_t ) >block_bytes (c->cache) -sizeof (struct jset ))return -ENOMEM ;return __bch_keylist_realloc (l, u64s);
drivers/md/bcache/super.c +1 -1
@@ -1528,7 +1528,7 @@ static int flash_dev_run(struct cache_set *c, struct uuid_entry *u)kobject_init (&d->kobj, &bch_flash_dev_ktype); -if (bcache_device_init (d,block_bytes (c), u->sectors, +if (bcache_device_init (d,block_bytes (c->cache), u->sectors,NULL , &bcache_flash_ops)) goto err;
drivers/md/bcache/sysfs.c +1 -1
@@ -714,7 +714,7 @@ SHOW(__bch_cache_set)sysfs_print (synchronous,CACHE_SYNC (&c->sb));sysfs_print (journal_delay_ms, c->journal_delay_ms);sysfs_hprint (bucket_size,bucket_bytes (c)); -sysfs_hprint (block_size,block_bytes (c)); +sysfs_hprint (block_size,block_bytes (c->cache));sysfs_print (tree_depth, c->root->level);sysfs_print (root_usage_percent,bch_root_usage (c));
Signature · 1 line
2.26.2
PATCH v2 6/12 bcache: remove useless alloc_bucket_pages()
In reply to Coly LiNow no one uses alloc_bucket_pages() anymore, remove it from bcache.h.
--- drivers/md/bcache/super.c | 3 --- 1 file changed, 3 deletions(-)
drivers/md/bcache/super.c +0 -3
@@ -1832,9 +1832,6 @@ void bch_cache_set_unregister(struct cache_set *c)bch_cache_set_stop (c); } -#define alloc_bucket_pages (gfp, c) \ - ((void *) __get_free_pages(__GFP_ZERO|__GFP_COMP|gfp, ilog2(bucket_pages(c)))) -#define alloc_meta_bucket_pages (gfp, sb) \ ((void *) __get_free_pages(__GFP_ZERO|__GFP_COMP|gfp, ilog2(meta_bucket_pages(sb))))
Signature · 1 line
2.26.2
PATCH v2 7/12 bcache: remove useless bucket_pages()
In reply to Coly LiIt seems alloc_bucket_pages() is the only user of bucket_pages(). Considering alloc_bucket_pages() is removed from bcache code, it is safe to remove the useless macro bucket_pages() now.
--- drivers/md/bcache/bcache.h | 1 - 1 file changed, 1 deletion(-)
drivers/md/bcache/bcache.h +0 -1
@@ -757,7 +757,6 @@ struct bbio {#define btree_default_blocks (c) \ ((unsigned int) ((PAGE_SECTORS * (c)->btree_pages) >> (c)->block_bits)) -#define bucket_pages (c) ((c)->sb.bucket_size / PAGE_SECTORS)#define bucket_bytes (c) ((c)->sb.bucket_size << 9)#define block_bytes (ca) ((ca)->sb.block_size << 9)
Signature · 1 line
2.26.2
PATCH v2 8/12 bcache: only use bucket_bytes() on struct cache
In reply to Coly LiBecause struct cache_set and struct cache both have struct cache_sb, macro bucket_bytes() currently are used on both of them. When removing the embedded struct cache_sb from struct cache_set, this macro won't be used on struct cache_set anymore.
This patch unifies all bucket_bytes() usage only on struct cache, this is one of the preparation to remove the embedded struct cache_sb from struct cache_set.
--- drivers/md/bcache/bcache.h | 2 +- drivers/md/bcache/sysfs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/md/bcache/bcache.h +1 -1
@@ -757,7 +757,7 @@ struct bbio {#define btree_default_blocks (c) \ ((unsigned int) ((PAGE_SECTORS * (c)->btree_pages) >> (c)->block_bits)) -#define bucket_bytes (c) ((c)->sb.bucket_size << 9) +#define bucket_bytes (ca) ((ca)->sb.bucket_size << 9)#define block_bytes (ca) ((ca)->sb.block_size << 9)static inline unsigned int meta_bucket_pages (struct cache_sb *sb)
drivers/md/bcache/sysfs.c +1 -1
@@ -713,7 +713,7 @@ SHOW(__bch_cache_set)sysfs_print (synchronous,CACHE_SYNC (&c->sb));sysfs_print (journal_delay_ms, c->journal_delay_ms); -sysfs_hprint (bucket_size,bucket_bytes (c)); +sysfs_hprint (bucket_size,bucket_bytes (c->cache));sysfs_hprint (block_size,block_bytes (c->cache));sysfs_print (tree_depth, c->root->level);sysfs_print (root_usage_percent,bch_root_usage (c));
Signature · 1 line
2.26.2
PATCH v2 9/12 bcache: don't check seq numbers in register_cache_set()
In reply to Coly LiIn order to update the partial super block of cache set, the seq numbers of cache and cache set are checked in register_cache_set(). If cache's seq number is larger than cache set's seq number, cache set must update its partial super block from cache's super block. It is unncessary when the embedded struct cache_sb is removed from struct cache set.
This patch removed the seq numbers checking from register_cache_set(), because later there will be no such partial super block in struct cache set, the cache set will directly reference in-memory super block from struct cache. This is a preparation patch for removing embedded struct cache_sb from struct cache_set.
--- drivers/md/bcache/super.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/md/bcache/super.c +0 -15
@@ -2176,21 +2176,6 @@ static const char *register_cache_set(struct cache *ca) sysfs_create_link(&c->kobj, &ca->kobj, buf)) goto err; -/* -* A special case is both ca->sb.seq and c->sb.seq are 0, -* such condition happens on a new created cache device whose -* super block is never flushed yet. In this case c->sb.version -* and other members should be updated too, otherwise we will -* have a mistaken super block version in cache set. -*/ -if (ca->sb.seq > c->sb.seq || c->sb.seq ==0 ) { - c->sb.version = ca->sb.version; -memcpy (c->set_uuid, ca->sb.set_uuid,16 ); - c->sb.flags = ca->sb.flags; - c->sb.seq = ca->sb.seq; -pr_debug ("set version = %llu\n" , c->sb.version); - } -kobject_get (&ca->kobj); ca->set = c; ca->set->cache = ca;
Signature · 1 line
2.26.2
PATCH v2 10/12 bcache: remove can_attach_cache()
In reply to Coly LiAfter removing the embedded struct cache_sb from struct cache_set, cache set will directly reference the in-memory super block of struct cache. It is unnecessary to compare block_size, bucket_size and nr_in_set from the identical in-memory super block in can_attach_cache().
This is a preparation patch for latter removing cache_set->sb from struct cache_set.
--- drivers/md/bcache/super.c | 10 ---------- 1 file changed, 10 deletions(-)
drivers/md/bcache/super.c +0 -10
@@ -2128,13 +2128,6 @@ static int run_cache_set(struct cache_set *c)return -EIO ; } -static bool can_attach_cache (struct cache *ca,struct cache_set *c) -{ -return ca->sb.block_size == c->sb.block_size && - ca->sb.bucket_size == c->sb.bucket_size && - ca->sb.nr_in_set == c->sb.nr_in_set; -} -static const char *register_cache_set (struct cache *ca) {char buf[12 ];
@@ -2146,9 +2139,6 @@ static const char *register_cache_set(struct cache *ca)if (c->cache)return "duplicate cache set member" ; -if (!can_attach_cache (ca, c)) -return "cache sb does not match set" ; -if (!CACHE_SYNC (&ca->sb))SET_CACHE_SYNC (&c->sb, false);
Signature · 1 line
2.26.2
PATCH v2 11/12 bcache: check and set sync status on cache's in-memory super block
In reply to Coly LiCurrently the cache's sync status is checked and set on cache set's in- memory partial super block. After removing the embedded struct cache_sb from cache set and reference cache's in-memory super block from struct cache_set, the sync status can set and check directly on cache's super block.
This patch checks and sets the cache sync status directly on cache's in-memory super block. This is a preparation for later removing embedded struct cache_sb from struct cache_set.
--- drivers/md/bcache/alloc.c | 2 +- drivers/md/bcache/journal.c | 2 +- drivers/md/bcache/super.c | 7 ++----- drivers/md/bcache/sysfs.c | 6 +++--- 4 files changed, 7 insertions(+), 10 deletions(-)
drivers/md/bcache/alloc.c +1 -1
@@ -361,7 +361,7 @@ static int bch_allocator_thread(void *arg)* new stuff to them: */ allocator_wait (ca, !atomic_read (&ca->set->prio_blocked)); -if (CACHE_SYNC (&ca->set->sb)) { +if (CACHE_SYNC (&ca->sb)) {/* * This could deadlock if an allocation with a btree * node locked ever blocked - having the btree node
drivers/md/bcache/journal.c +1 -1
@@ -915,7 +915,7 @@ atomic_t *bch_journal(struct cache_set *c,if (unlikely (test_bit (CACHE_SET_IO_DISABLE , &c->flags)))return NULL ; -if (!CACHE_SYNC (&c->sb)) +if (!CACHE_SYNC (&c->cache->sb))return NULL ; w =journal_wait_for_write (c,bch_keylist_nkeys (keys));
drivers/md/bcache/super.c +2 -5
@@ -1970,7 +1970,7 @@ static int run_cache_set(struct cache_set *c) c->nbuckets = ca->sb.nbuckets;set_gc_sectors (c); -if (CACHE_SYNC (&c->sb)) { +if (CACHE_SYNC (&c->cache->sb)) {struct bkey *k;struct jset *j;
@@ -2093,7 +2093,7 @@ static int run_cache_set(struct cache_set *c)* everything is set up - fortunately journal entries won't be * written until the SET_CACHE_SYNC() here: */ -SET_CACHE_SYNC (&c->sb, true); +SET_CACHE_SYNC (&c->cache->sb, true);bch_journal_next (&c->journal);bch_journal_meta (c, &cl);
@@ -2139,9 +2139,6 @@ static const char *register_cache_set(struct cache *ca)if (c->cache)return "duplicate cache set member" ; -if (!CACHE_SYNC (&ca->sb)) -SET_CACHE_SYNC (&c->sb, false); - goto found; }
drivers/md/bcache/sysfs.c +3 -3
@@ -711,7 +711,7 @@ SHOW(__bch_cache_set) { struct cache_set *c = container_of(kobj, struct cache_set, kobj); -sysfs_print (synchronous,CACHE_SYNC (&c->sb)); +sysfs_print (synchronous,CACHE_SYNC (&c->cache->sb));sysfs_print (journal_delay_ms, c->journal_delay_ms);sysfs_hprint (bucket_size,bucket_bytes (c->cache));sysfs_hprint (block_size,block_bytes (c->cache));
@@ -812,8 +812,8 @@ STORE(__bch_cache_set)if (attr == &sysfs_synchronous) {bool sync =strtoul_or_return (buf); -if (sync !=CACHE_SYNC (&c->sb)) { -SET_CACHE_SYNC (&c->sb, sync); +if (sync !=CACHE_SYNC (&c->cache->sb)) { +SET_CACHE_SYNC (&c->cache->sb, sync);bcache_write_super (c); } }
Signature · 1 line
2.26.2
PATCH v2 12/12 bcache: remove embedded struct cache_sb from struct cache_set
In reply to Coly LiSince bcache code was merged into mainline kerrnel, each cache set only as one single cache in it. The multiple caches framework is here but the code is far from completed. Considering the multiple copies of cached data can also be stored on e.g. md raid1 devices, it is unnecessary to support multiple caches in one cache set indeed.
The previous preparation patches fix the dependencies of explicitly making a cache set only have single cache. Now we don't have to maintain an embedded partial super block in struct cache_set, the in-memory super block can be directly referenced from struct cache.
This patch removes the embedded struct cache_sb from struct cache_set, and fixes all locations where the superb lock was referenced from this removed super block by referencing the in-memory super block of struct cache.
--- drivers/md/bcache/alloc.c | 6 ++--- drivers/md/bcache/bcache.h | 4 +-- drivers/md/bcache/btree.c | 17 +++++++------ drivers/md/bcache/btree.h | 2 +- drivers/md/bcache/extents.c | 6 ++--- drivers/md/bcache/features.c | 4 +-- drivers/md/bcache/io.c | 2 +- drivers/md/bcache/journal.c | 11 ++++---- drivers/md/bcache/request.c | 4 +-- drivers/md/bcache/super.c | 47 +++++++++++++---------------------- drivers/md/bcache/writeback.c | 2 +- 11 files changed, 46 insertions(+), 59 deletions(-)
drivers/md/bcache/alloc.c +3 -3
@@ -87,7 +87,7 @@ void bch_rescale_priorities(struct cache_set *c, int sectors) {struct cache *ca;struct bucket *b; -unsigned long next = c->nbuckets * c->sb.bucket_size /1024 ; +unsigned long next = c->nbuckets * c->cache->sb.bucket_size /1024 ;int r;atomic_sub (sectors, &c->rescale);
@@ -583,7 +583,7 @@ static struct open_bucket *pick_data_bucket(struct cache_set *c, struct open_bucket, list); found:if (!ret->sectors_free &&KEY_PTRS (alloc)) { - ret->sectors_free = c->sb.bucket_size; + ret->sectors_free = c->cache->sb.bucket_size;bkey_copy (&ret->key, alloc);bkey_init (alloc); }
@@ -677,7 +677,7 @@ bool bch_alloc_sectors(struct cache_set *c, &PTR_CACHE(c, &b->key, i)->sectors_written); } -if (b->sectors_free < c->sb.block_size) +if (b->sectors_free < c->cache->sb.block_size) b->sectors_free =0 ;/*
drivers/md/bcache/bcache.h +1 -3
@@ -517,8 +517,6 @@ struct cache_set {atomic_t idle_counter;atomic_t at_max_writeback_rate; -struct cache_sb sb; -struct cache *cache;struct bcache_device **devices;
@@ -799,7 +797,7 @@ static inline sector_t bucket_to_sector(struct cache_set *c, size_t b)static inline sector_t bucket_remainder (struct cache_set *c,sector_t s) { -return s & (c->sb.bucket_size -1 ); +return s & (c->cache->sb.bucket_size -1 ); } static inline struct cache *PTR_CACHE(struct cache_set *c,
drivers/md/bcache/btree.c +9 -8
@@ -117,7 +117,7 @@ static void bch_btree_init_next(struct btree *b)if (b->written <btree_blocks (b))bch_bset_init_next (&b->keys,write_block (b), -bset_magic (&b->c->sb)); +bset_magic (&b->c->cache->sb)); }
@@ -155,7 +155,7 @@ void bch_btree_node_read_done(struct btree *b)* See the comment arount cache_set->fill_iter. */ iter =mempool_alloc (&b->c->fill_iter,GFP_NOIO ); - iter->size = b->c->sb.bucket_size / b->c->sb.block_size; + iter->size = b->c->cache->sb.bucket_size / b->c->cache->sb.block_size; iter->used =0 ;#ifdef CONFIG_BCACHE_DEBUG
@@ -178,7 +178,7 @@ void bch_btree_node_read_done(struct btree *b) goto err; err ="bad magic" ; -if (i->magic !=bset_magic (&b->c->sb)) +if (i->magic !=bset_magic (&b->c->cache->sb)) goto err; err ="bad checksum" ;
@@ -219,7 +219,7 @@ void bch_btree_node_read_done(struct btree *b)if (b->written <btree_blocks (b))bch_bset_init_next (&b->keys,write_block (b), -bset_magic (&b->c->sb)); +bset_magic (&b->c->cache->sb)); out:mempool_free (iter, &b->c->fill_iter);return ;
@@ -423,7 +423,7 @@ void __bch_btree_node_write(struct btree *b, struct closure *parent)do_btree_node_write (b); -atomic_long_add (set_blocks (i,block_bytes (b->c->cache)) * b->c->sb.block_size, +atomic_long_add (set_blocks (i,block_bytes (b->c->cache)) * b->c->cache->sb.block_size, &PTR_CACHE (b->c, &b->key,0 )->btree_sectors_written); b->written +=set_blocks (i,block_bytes (b->c->cache));
@@ -738,7 +738,7 @@ void bch_btree_cache_free(struct cache_set *c)if (c->verify_data)list_move (&c->verify_data->list, &c->btree_cache); -free_pages ((unsigned long ) c->verify_ondisk,ilog2 (meta_bucket_pages (&c->sb))); +free_pages ((unsigned long ) c->verify_ondisk,ilog2 (meta_bucket_pages (&c->cache->sb)));#endif list_splice(&c->btree_cache_freeable,
@@ -785,7 +785,8 @@ int bch_btree_cache_alloc(struct cache_set *c)mutex_init (&c->verify_lock); c->verify_ondisk = (void *) -__get_free_pages (GFP_KERNEL |__GFP_COMP,ilog2 (meta_bucket_pages (&c->sb))); +__get_free_pages (GFP_KERNEL |__GFP_COMP, +ilog2 (meta_bucket_pages (&c->cache->sb)));if (!c->verify_ondisk) {/* * Don't worry about the mca_rereserve buckets
@@ -1108,7 +1109,7 @@ struct btree *__bch_btree_node_alloc(struct cache_set *c, struct btree_op *op, } b->parent = parent; -bch_bset_init_next (&b->keys, b->keys.set->data,bset_magic (&b->c->sb)); +bch_bset_init_next (&b->keys, b->keys.set->data,bset_magic (&b->c->cache->sb));mutex_unlock (&c->bucket_lock);
drivers/md/bcache/btree.h +1 -1
@@ -194,7 +194,7 @@ static inline unsigned int bset_block_offset(struct btree *b, struct bset *i)static inline void set_gc_sectors (struct cache_set *c) { -atomic_set (&c->sectors_to_gc, c->sb.bucket_size * c->nbuckets /16 ); +atomic_set (&c->sectors_to_gc, c->cache->sb.bucket_size * c->nbuckets /16 ); }void bkey_put (struct cache_set *c,struct bkey *k);
drivers/md/bcache/extents.c +3 -3
@@ -54,7 +54,7 @@ static bool __ptr_invalid(struct cache_set *c, const struct bkey *k)size_t bucket =PTR_BUCKET_NR (c, k, i);size_t r =bucket_remainder (c,PTR_OFFSET (k, i)); -if (KEY_SIZE (k) + r > c->sb.bucket_size || +if (KEY_SIZE (k) + r > c->cache->sb.bucket_size || bucket < ca->sb.first_bucket || bucket >= ca->sb.nbuckets)return true;
@@ -75,7 +75,7 @@ static const char *bch_ptr_status(struct cache_set *c, const struct bkey *k)size_t bucket =PTR_BUCKET_NR (c, k, i);size_t r =bucket_remainder (c,PTR_OFFSET (k, i)); -if (KEY_SIZE (k) + r > c->sb.bucket_size) +if (KEY_SIZE (k) + r > c->cache->sb.bucket_size)return "bad, length too big" ;if (bucket < ca->sb.first_bucket)return "bad, short offset" ;
@@ -136,7 +136,7 @@ static void bch_bkey_dump(struct btree_keys *keys, const struct bkey *k)size_t n =PTR_BUCKET_NR (b->c, k, j);pr_cont (" bucket %zu" , n); -if (n >= b->c->sb.first_bucket && n < b->c->sb.nbuckets) +if (n >= b->c->cache->sb.first_bucket && n < b->c->cache->sb.nbuckets)pr_cont (" prio %i" ,PTR_BUCKET (b->c, k, j)->prio); }
drivers/md/bcache/features.c +2 -2
@@ -30,7 +30,7 @@ static struct feature feature_list[] = {for (f = &feature_list[0 ]; f->compat !=0 ; f++) { \ if (f->compat != BCH_FEATURE_ ## type) \ continue; \ - if (BCH_HAS_ ## type ## _FEATURE(&c->sb, f->mask)) { \ + if (BCH_HAS_ ## type ## _FEATURE(&c->cache->sb, f->mask)) { \ if (first) { \ out += snprintf(out, buf + size - out, \ "["); \
@@ -44,7 +44,7 @@ static struct feature feature_list[] = { \ out +=snprintf (out, buf + size - out,"%s" , f->string);\ \ - if (BCH_HAS_ ## type ## _FEATURE(&c->sb, f->mask)) \ + if (BCH_HAS_ ## type ## _FEATURE(&c->cache->sb, f->mask)) \ out +=snprintf (out, buf + size - out,"]" ); \ \ first = false; \
drivers/md/bcache/io.c +1 -1
@@ -26,7 +26,7 @@ struct bio *bch_bbio_alloc(struct cache_set *c)struct bbio *b =mempool_alloc (&c->bio_meta,GFP_NOIO );struct bio *bio = &b->bio; -bio_init (bio, bio->bi_inline_vecs,meta_bucket_pages (&c->sb)); +bio_init (bio, bio->bi_inline_vecs,meta_bucket_pages (&c->cache->sb));return bio; }
drivers/md/bcache/journal.c +6 -5
@@ -666,7 +666,7 @@ static void journal_reclaim(struct cache_set *c)bkey_init (k);SET_KEY_PTRS (k,1 ); - c->journal.blocks_free = c->sb.bucket_size >> c->block_bits; + c->journal.blocks_free = ca->sb.bucket_size >> c->block_bits; out:if (!journal_full (&c->journal))
@@ -735,7 +735,7 @@ static void journal_write_unlocked(struct closure *cl)struct journal_write *w = c->journal.cur;struct bkey *k = &c->journal.key;unsigned int i, sectors =set_blocks (w->data,block_bytes (ca)) * - c->sb.block_size; + ca->sb.block_size;struct bio *bio;struct bio_list list;
@@ -762,7 +762,7 @@ static void journal_write_unlocked(struct closure *cl)bkey_copy (&w->data->uuid_bucket, &c->uuid_bucket); w->data->prio_bucket[ca->sb.nr_this_dev] = ca->prio_buckets[0 ]; - w->data->magic =jset_magic (&c->sb); + w->data->magic =jset_magic (&ca->sb); w->data->version =BCACHE_JSET_VERSION ; w->data->last_seq =last_seq (&c->journal); w->data->csum =csum_set (w->data);
@@ -838,6 +838,7 @@ static struct journal_write *journal_wait_for_write(struct cache_set *c,size_t sectors;struct closure cl;bool wait = false; +struct cache *ca = c->cache;closure_init_stack (&cl);
@@ -847,10 +848,10 @@ static struct journal_write *journal_wait_for_write(struct cache_set *c,struct journal_write *w = c->journal.cur; sectors =__set_blocks (w->data, w->data->keys + nkeys, -block_bytes (c->cache)) * c->sb.block_size; +block_bytes (ca)) * ca->sb.block_size;if (sectors <=min_t (size_t, - c->journal.blocks_free * c->sb.block_size, + c->journal.blocks_free * ca->sb.block_size,PAGE_SECTORS <<JSET_BITS ))return w;
drivers/md/bcache/request.c +2 -2
@@ -394,8 +394,8 @@ static bool check_should_bypass(struct cached_dev *dc, struct bio *bio) goto skip; } -if (bio->bi_iter.bi_sector & (c->sb.block_size -1 ) || -bio_sectors (bio) & (c->sb.block_size -1 )) { +if (bio->bi_iter.bi_sector & (c->cache->sb.block_size -1 ) || +bio_sectors (bio) & (c->cache->sb.block_size -1 )) {pr_debug ("skipping unaligned io\n" ); goto skip; }
drivers/md/bcache/super.c +17 -30
124 lines not on this page · raw message
drivers/md/bcache/writeback.c +1 -1
@@ -35,7 +35,7 @@ static uint64_t __calc_target_rate(struct cached_dev *dc)* This is the size of the cache, minus the amount used for * flash-only devices */ -uint64_t cache_sectors = c->nbuckets * c->sb.bucket_size - +uint64_t cache_sectors = c->nbuckets * c->cache->sb.bucket_size -atomic_long_read (&c->flash_dev_dirty_sectors);/*
Signature · 1 line
2.26.2