forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/md/bcache/alloc.c
....@@ -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
....@@ -87,8 +87,7 @@
8787 {
8888 struct cache *ca;
8989 struct bucket *b;
90
- unsigned int next = c->nbuckets * c->sb.bucket_size / 1024;
91
- unsigned int i;
90
+ unsigned long next = c->nbuckets * c->cache->sb.bucket_size / 1024;
9291 int r;
9392
9493 atomic_sub(sectors, &c->rescale);
....@@ -104,14 +103,14 @@
104103
105104 c->min_prio = USHRT_MAX;
106105
107
- for_each_cache(ca, c, i)
108
- for_each_bucket(b, ca)
109
- if (b->prio &&
110
- b->prio != BTREE_PRIO &&
111
- !atomic_read(&b->pin)) {
112
- b->prio--;
113
- c->min_prio = min(c->min_prio, b->prio);
114
- }
106
+ ca = c->cache;
107
+ for_each_bucket(b, ca)
108
+ if (b->prio &&
109
+ b->prio != BTREE_PRIO &&
110
+ !atomic_read(&b->pin)) {
111
+ b->prio--;
112
+ c->min_prio = min(c->min_prio, b->prio);
113
+ }
115114
116115 mutex_unlock(&c->bucket_lock);
117116 }
....@@ -362,7 +361,7 @@
362361 * new stuff to them:
363362 */
364363 allocator_wait(ca, !atomic_read(&ca->set->prio_blocked));
365
- if (CACHE_SYNC(&ca->set->sb)) {
364
+ if (CACHE_SYNC(&ca->sb)) {
366365 /*
367366 * This could deadlock if an allocation with a btree
368367 * node locked ever blocked - having the btree node
....@@ -488,34 +487,29 @@
488487 }
489488
490489 int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
491
- struct bkey *k, int n, bool wait)
490
+ struct bkey *k, bool wait)
492491 {
493
- int i;
492
+ struct cache *ca;
493
+ long b;
494494
495495 /* No allocation if CACHE_SET_IO_DISABLE bit is set */
496496 if (unlikely(test_bit(CACHE_SET_IO_DISABLE, &c->flags)))
497497 return -1;
498498
499499 lockdep_assert_held(&c->bucket_lock);
500
- BUG_ON(!n || n > c->caches_loaded || n > 8);
501500
502501 bkey_init(k);
503502
504
- /* sort by free space/prio of oldest data in caches */
503
+ ca = c->cache;
504
+ b = bch_bucket_alloc(ca, reserve, wait);
505
+ if (b == -1)
506
+ goto err;
505507
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);
508
+ k->ptr[0] = MAKE_PTR(ca->buckets[b].gen,
509
+ bucket_to_sector(c, b),
510
+ ca->sb.nr_this_dev);
509511
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
- }
512
+ SET_KEY_PTRS(k, 1);
519513
520514 return 0;
521515 err:
....@@ -525,12 +519,12 @@
525519 }
526520
527521 int bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
528
- struct bkey *k, int n, bool wait)
522
+ struct bkey *k, bool wait)
529523 {
530524 int ret;
531525
532526 mutex_lock(&c->bucket_lock);
533
- ret = __bch_bucket_alloc_set(c, reserve, k, n, wait);
527
+ ret = __bch_bucket_alloc_set(c, reserve, k, wait);
534528 mutex_unlock(&c->bucket_lock);
535529 return ret;
536530 }
....@@ -589,7 +583,7 @@
589583 struct open_bucket, list);
590584 found:
591585 if (!ret->sectors_free && KEY_PTRS(alloc)) {
592
- ret->sectors_free = c->sb.bucket_size;
586
+ ret->sectors_free = c->cache->sb.bucket_size;
593587 bkey_copy(&ret->key, alloc);
594588 bkey_init(alloc);
595589 }
....@@ -638,7 +632,7 @@
638632
639633 spin_unlock(&c->data_bucket_lock);
640634
641
- if (bch_bucket_alloc_set(c, watermark, &alloc.key, 1, wait))
635
+ if (bch_bucket_alloc_set(c, watermark, &alloc.key, wait))
642636 return false;
643637
644638 spin_lock(&c->data_bucket_lock);
....@@ -683,7 +677,7 @@
683677 &PTR_CACHE(c, &b->key, i)->sectors_written);
684678 }
685679
686
- if (b->sectors_free < c->sb.block_size)
680
+ if (b->sectors_free < c->cache->sb.block_size)
687681 b->sectors_free = 0;
688682
689683 /*