Skip to content

Commit 17e4aed

Browse files
Coly Liaxboe
authored andcommitted
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. Signed-off-by: Coly Li <colyli@suse.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 84e5d13 commit 17e4aed

4 files changed

Lines changed: 19 additions & 24 deletions

File tree

‎drivers/md/bcache/alloc.c‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
*
5050
* bch_bucket_alloc() allocates a single bucket from a specific cache.
5151
*
52-
* bch_bucket_alloc_set() allocates one or more buckets from different caches
52+
* bch_bucket_alloc_set() allocates one bucket from different caches
5353
* out of a cache set.
5454
*
5555
* 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)
488488
}
489489

490490
int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
491-
struct bkey *k, int n, bool wait)
491+
struct bkey *k, bool wait)
492492
{
493-
int i;
493+
struct cache *ca;
494+
long b;
494495

495496
/* No allocation if CACHE_SET_IO_DISABLE bit is set */
496497
if (unlikely(test_bit(CACHE_SET_IO_DISABLE, &c->flags)))
497498
return -1;
498499

499500
lockdep_assert_held(&c->bucket_lock);
500-
BUG_ON(!n || n > c->caches_loaded || n > MAX_CACHES_PER_SET);
501501

502502
bkey_init(k);
503503

504-
/* sort by free space/prio of oldest data in caches */
505-
506-
for (i = 0; i < n; i++) {
507-
struct cache *ca = c->cache_by_alloc[i];
508-
long b = bch_bucket_alloc(ca, reserve, wait);
504+
ca = c->cache_by_alloc[0];
505+
b = bch_bucket_alloc(ca, reserve, wait);
506+
if (b == -1)
507+
goto err;
509508

510-
if (b == -1)
511-
goto err;
509+
k->ptr[0] = MAKE_PTR(ca->buckets[b].gen,
510+
bucket_to_sector(c, b),
511+
ca->sb.nr_this_dev);
512512

513-
k->ptr[i] = MAKE_PTR(ca->buckets[b].gen,
514-
bucket_to_sector(c, b),
515-
ca->sb.nr_this_dev);
516-
517-
SET_KEY_PTRS(k, i + 1);
518-
}
513+
SET_KEY_PTRS(k, 1);
519514

520515
return 0;
521516
err:
@@ -525,12 +520,12 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
525520
}
526521

527522
int bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
528-
struct bkey *k, int n, bool wait)
523+
struct bkey *k, bool wait)
529524
{
530525
int ret;
531526

532527
mutex_lock(&c->bucket_lock);
533-
ret = __bch_bucket_alloc_set(c, reserve, k, n, wait);
528+
ret = __bch_bucket_alloc_set(c, reserve, k, wait);
534529
mutex_unlock(&c->bucket_lock);
535530
return ret;
536531
}
@@ -638,7 +633,7 @@ bool bch_alloc_sectors(struct cache_set *c,
638633

639634
spin_unlock(&c->data_bucket_lock);
640635

641-
if (bch_bucket_alloc_set(c, watermark, &alloc.key, 1, wait))
636+
if (bch_bucket_alloc_set(c, watermark, &alloc.key, wait))
642637
return false;
643638

644639
spin_lock(&c->data_bucket_lock);

‎drivers/md/bcache/bcache.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,9 @@ void bch_bucket_free(struct cache_set *c, struct bkey *k);
994994

995995
long bch_bucket_alloc(struct cache *ca, unsigned int reserve, bool wait);
996996
int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
997-
struct bkey *k, int n, bool wait);
997+
struct bkey *k, bool wait);
998998
int bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
999-
struct bkey *k, int n, bool wait);
999+
struct bkey *k, bool wait);
10001000
bool bch_alloc_sectors(struct cache_set *c, struct bkey *k,
10011001
unsigned int sectors, unsigned int write_point,
10021002
unsigned int write_prio, bool wait);

‎drivers/md/bcache/btree.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ struct btree *__bch_btree_node_alloc(struct cache_set *c, struct btree_op *op,
10911091

10921092
mutex_lock(&c->bucket_lock);
10931093
retry:
1094-
if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, wait))
1094+
if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, wait))
10951095
goto err;
10961096

10971097
bkey_put(c, &k.key);

‎drivers/md/bcache/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static int __uuid_write(struct cache_set *c)
486486
closure_init_stack(&cl);
487487
lockdep_assert_held(&bch_register_lock);
488488

489-
if (bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, true))
489+
if (bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, true))
490490
return 1;
491491

492492
size = meta_bucket_pages(&c->sb) * PAGE_SECTORS;

0 commit comments

Comments
 (0)