Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Coly Li and committed by
Jens Axboe
17e4aed8 84e5d136

+19 -24
+15 -20
drivers/md/bcache/alloc.c
··· 49 49 * 50 50 * bch_bucket_alloc() allocates a single bucket from a specific cache. 51 51 * 52 - * bch_bucket_alloc_set() allocates one or more buckets from different caches 52 + * bch_bucket_alloc_set() allocates one bucket from different caches 53 53 * out of a cache set. 54 54 * 55 55 * free_some_buckets() drives all the processes described above. It's called ··· 488 488 } 489 489 490 490 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) 492 492 { 493 - int i; 493 + struct cache *ca; 494 + long b; 494 495 495 496 /* No allocation if CACHE_SET_IO_DISABLE bit is set */ 496 497 if (unlikely(test_bit(CACHE_SET_IO_DISABLE, &c->flags))) 497 498 return -1; 498 499 499 500 lockdep_assert_held(&c->bucket_lock); 500 - BUG_ON(!n || n > c->caches_loaded || n > MAX_CACHES_PER_SET); 501 501 502 502 bkey_init(k); 503 503 504 - /* sort by free space/prio of oldest data in caches */ 504 + ca = c->cache_by_alloc[0]; 505 + b = bch_bucket_alloc(ca, reserve, wait); 506 + if (b == -1) 507 + goto err; 505 508 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); 509 + k->ptr[0] = MAKE_PTR(ca->buckets[b].gen, 510 + bucket_to_sector(c, b), 511 + ca->sb.nr_this_dev); 509 512 510 - if (b == -1) 511 - goto err; 512 - 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); 519 514 520 515 return 0; 521 516 err: ··· 520 525 } 521 526 522 527 int bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve, 523 - struct bkey *k, int n, bool wait) 528 + struct bkey *k, bool wait) 524 529 { 525 530 int ret; 526 531 527 532 mutex_lock(&c->bucket_lock); 528 - ret = __bch_bucket_alloc_set(c, reserve, k, n, wait); 533 + ret = __bch_bucket_alloc_set(c, reserve, k, wait); 529 534 mutex_unlock(&c->bucket_lock); 530 535 return ret; 531 536 } ··· 633 638 634 639 spin_unlock(&c->data_bucket_lock); 635 640 636 - if (bch_bucket_alloc_set(c, watermark, &alloc.key, 1, wait)) 641 + if (bch_bucket_alloc_set(c, watermark, &alloc.key, wait)) 637 642 return false; 638 643 639 644 spin_lock(&c->data_bucket_lock);
+2 -2
drivers/md/bcache/bcache.h
··· 994 994 995 995 long bch_bucket_alloc(struct cache *ca, unsigned int reserve, bool wait); 996 996 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); 998 998 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); 1000 1000 bool bch_alloc_sectors(struct cache_set *c, struct bkey *k, 1001 1001 unsigned int sectors, unsigned int write_point, 1002 1002 unsigned int write_prio, bool wait);
+1 -1
drivers/md/bcache/btree.c
··· 1091 1091 1092 1092 mutex_lock(&c->bucket_lock); 1093 1093 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)) 1095 1095 goto err; 1096 1096 1097 1097 bkey_put(c, &k.key);
+1 -1
drivers/md/bcache/super.c
··· 486 486 closure_init_stack(&cl); 487 487 lockdep_assert_held(&bch_register_lock); 488 488 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)) 490 490 return 1; 491 491 492 492 size = meta_bucket_pages(&c->sb) * PAGE_SECTORS;