Skip to content

Commit 697e234

Browse files
Coly Liaxboe
authored andcommitted
bcache: explicitly make cache_set only have single cache
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 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. Signed-off-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 17e4aed commit 697e234

3 files changed

Lines changed: 12 additions & 17 deletions

File tree

‎drivers/md/bcache/alloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
501501

502502
bkey_init(k);
503503

504-
ca = c->cache_by_alloc[0];
504+
ca = c->cache;
505505
b = bch_bucket_alloc(ca, reserve, wait);
506506
if (b == -1)
507507
goto err;

‎drivers/md/bcache/bcache.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,7 @@ struct cache_set {
519519

520520
struct cache_sb sb;
521521

522-
struct cache *cache[MAX_CACHES_PER_SET];
523-
struct cache *cache_by_alloc[MAX_CACHES_PER_SET];
524-
int caches_loaded;
522+
struct cache *cache;
525523

526524
struct bcache_device **devices;
527525
unsigned int devices_max_used;
@@ -808,7 +806,7 @@ static inline struct cache *PTR_CACHE(struct cache_set *c,
808806
const struct bkey *k,
809807
unsigned int ptr)
810808
{
811-
return c->cache[PTR_DEV(k, ptr)];
809+
return c->cache;
812810
}
813811

814812
static inline size_t PTR_BUCKET_NR(struct cache_set *c,
@@ -890,7 +888,7 @@ do { \
890888
/* Looping macros */
891889

892890
#define for_each_cache(ca, cs, iter) \
893-
for (iter = 0; ca = cs->cache[iter], iter < (cs)->sb.nr_in_set; iter++)
891+
for (iter = 0; ca = cs->cache, iter < 1; iter++)
894892

895893
#define for_each_bucket(b, ca) \
896894
for (b = (ca)->buckets + (ca)->sb.first_bucket; \

‎drivers/md/bcache/super.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ static void cache_set_free(struct closure *cl)
16741674
for_each_cache(ca, c, i)
16751675
if (ca) {
16761676
ca->set = NULL;
1677-
c->cache[ca->sb.nr_this_dev] = NULL;
1677+
c->cache = NULL;
16781678
kobject_put(&ca->kobj);
16791679
}
16801680

@@ -2165,7 +2165,7 @@ static const char *register_cache_set(struct cache *ca)
21652165

21662166
list_for_each_entry(c, &bch_cache_sets, list)
21672167
if (!memcmp(c->sb.set_uuid, ca->sb.set_uuid, 16)) {
2168-
if (c->cache[ca->sb.nr_this_dev])
2168+
if (c->cache)
21692169
return "duplicate cache set member";
21702170

21712171
if (!can_attach_cache(ca, c))
@@ -2215,14 +2215,11 @@ static const char *register_cache_set(struct cache *ca)
22152215

22162216
kobject_get(&ca->kobj);
22172217
ca->set = c;
2218-
ca->set->cache[ca->sb.nr_this_dev] = ca;
2219-
c->cache_by_alloc[c->caches_loaded++] = ca;
2218+
ca->set->cache = ca;
22202219

2221-
if (c->caches_loaded == c->sb.nr_in_set) {
2222-
err = "failed to run cache set";
2223-
if (run_cache_set(c) < 0)
2224-
goto err;
2225-
}
2220+
err = "failed to run cache set";
2221+
if (run_cache_set(c) < 0)
2222+
goto err;
22262223

22272224
return NULL;
22282225
err:
@@ -2239,8 +2236,8 @@ void bch_cache_release(struct kobject *kobj)
22392236
unsigned int i;
22402237

22412238
if (ca->set) {
2242-
BUG_ON(ca->set->cache[ca->sb.nr_this_dev] != ca);
2243-
ca->set->cache[ca->sb.nr_this_dev] = NULL;
2239+
BUG_ON(ca->set->cache != ca);
2240+
ca->set->cache = NULL;
22442241
}
22452242

22462243
free_pages((unsigned long) ca->disk_buckets, ilog2(meta_bucket_pages(&ca->sb)));

0 commit comments

Comments
 (0)