Skip to content

Commit 08fdb2c

Browse files
Coly Liaxboe
authored andcommitted
bcache: remove for_each_cache()
Since 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. 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 697e234 commit 08fdb2c

6 files changed

Lines changed: 237 additions & 294 deletions

File tree

‎drivers/md/bcache/alloc.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ void bch_rescale_priorities(struct cache_set *c, int sectors)
8888
struct cache *ca;
8989
struct bucket *b;
9090
unsigned long next = c->nbuckets * c->sb.bucket_size / 1024;
91-
unsigned int i;
9291
int r;
9392

9493
atomic_sub(sectors, &c->rescale);
@@ -104,14 +103,14 @@ void bch_rescale_priorities(struct cache_set *c, int sectors)
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
}

‎drivers/md/bcache/bcache.h‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,6 @@ do { \
887887

888888
/* Looping macros */
889889

890-
#define for_each_cache(ca, cs, iter) \
891-
for (iter = 0; ca = cs->cache, iter < 1; iter++)
892-
893890
#define for_each_bucket(b, ca) \
894891
for (b = (ca)->buckets + (ca)->sb.first_bucket; \
895892
b < (ca)->buckets + (ca)->sb.nbuckets; b++)
@@ -931,11 +928,9 @@ static inline uint8_t bucket_gc_gen(struct bucket *b)
931928

932929
static inline void wake_up_allocators(struct cache_set *c)
933930
{
934-
struct cache *ca;
935-
unsigned int i;
931+
struct cache *ca = c->cache;
936932

937-
for_each_cache(ca, c, i)
938-
wake_up_process(ca->alloc_thread);
933+
wake_up_process(ca->alloc_thread);
939934
}
940935

941936
static inline void closure_bio_submit(struct cache_set *c,

‎drivers/md/bcache/btree.c‎

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,19 +1167,18 @@ static void make_btree_freeing_key(struct btree *b, struct bkey *k)
11671167
static int btree_check_reserve(struct btree *b, struct btree_op *op)
11681168
{
11691169
struct cache_set *c = b->c;
1170-
struct cache *ca;
1171-
unsigned int i, reserve = (c->root->level - b->level) * 2 + 1;
1170+
struct cache *ca = c->cache;
1171+
unsigned int reserve = (c->root->level - b->level) * 2 + 1;
11721172

11731173
mutex_lock(&c->bucket_lock);
11741174

1175-
for_each_cache(ca, c, i)
1176-
if (fifo_used(&ca->free[RESERVE_BTREE]) < reserve) {
1177-
if (op)
1178-
prepare_to_wait(&c->btree_cache_wait, &op->wait,
1179-
TASK_UNINTERRUPTIBLE);
1180-
mutex_unlock(&c->bucket_lock);
1181-
return -EINTR;
1182-
}
1175+
if (fifo_used(&ca->free[RESERVE_BTREE]) < reserve) {
1176+
if (op)
1177+
prepare_to_wait(&c->btree_cache_wait, &op->wait,
1178+
TASK_UNINTERRUPTIBLE);
1179+
mutex_unlock(&c->bucket_lock);
1180+
return -EINTR;
1181+
}
11831182

11841183
mutex_unlock(&c->bucket_lock);
11851184

@@ -1695,7 +1694,6 @@ static void btree_gc_start(struct cache_set *c)
16951694
{
16961695
struct cache *ca;
16971696
struct bucket *b;
1698-
unsigned int i;
16991697

17001698
if (!c->gc_mark_valid)
17011699
return;
@@ -1705,14 +1703,14 @@ static void btree_gc_start(struct cache_set *c)
17051703
c->gc_mark_valid = 0;
17061704
c->gc_done = ZERO_KEY;
17071705

1708-
for_each_cache(ca, c, i)
1709-
for_each_bucket(b, ca) {
1710-
b->last_gc = b->gen;
1711-
if (!atomic_read(&b->pin)) {
1712-
SET_GC_MARK(b, 0);
1713-
SET_GC_SECTORS_USED(b, 0);
1714-
}
1706+
ca = c->cache;
1707+
for_each_bucket(b, ca) {
1708+
b->last_gc = b->gen;
1709+
if (!atomic_read(&b->pin)) {
1710+
SET_GC_MARK(b, 0);
1711+
SET_GC_SECTORS_USED(b, 0);
17151712
}
1713+
}
17161714

17171715
mutex_unlock(&c->bucket_lock);
17181716
}
@@ -1721,7 +1719,8 @@ static void bch_btree_gc_finish(struct cache_set *c)
17211719
{
17221720
struct bucket *b;
17231721
struct cache *ca;
1724-
unsigned int i;
1722+
unsigned int i, j;
1723+
uint64_t *k;
17251724

17261725
mutex_lock(&c->bucket_lock);
17271726

@@ -1739,7 +1738,6 @@ static void bch_btree_gc_finish(struct cache_set *c)
17391738
struct bcache_device *d = c->devices[i];
17401739
struct cached_dev *dc;
17411740
struct keybuf_key *w, *n;
1742-
unsigned int j;
17431741

17441742
if (!d || UUID_FLASH_ONLY(&c->uuids[i]))
17451743
continue;
@@ -1756,29 +1754,27 @@ static void bch_btree_gc_finish(struct cache_set *c)
17561754
rcu_read_unlock();
17571755

17581756
c->avail_nbuckets = 0;
1759-
for_each_cache(ca, c, i) {
1760-
uint64_t *i;
17611757

1762-
ca->invalidate_needs_gc = 0;
1758+
ca = c->cache;
1759+
ca->invalidate_needs_gc = 0;
17631760

1764-
for (i = ca->sb.d; i < ca->sb.d + ca->sb.keys; i++)
1765-
SET_GC_MARK(ca->buckets + *i, GC_MARK_METADATA);
1761+
for (k = ca->sb.d; k < ca->sb.d + ca->sb.keys; k++)
1762+
SET_GC_MARK(ca->buckets + *k, GC_MARK_METADATA);
17661763

1767-
for (i = ca->prio_buckets;
1768-
i < ca->prio_buckets + prio_buckets(ca) * 2; i++)
1769-
SET_GC_MARK(ca->buckets + *i, GC_MARK_METADATA);
1764+
for (k = ca->prio_buckets;
1765+
k < ca->prio_buckets + prio_buckets(ca) * 2; k++)
1766+
SET_GC_MARK(ca->buckets + *k, GC_MARK_METADATA);
17701767

1771-
for_each_bucket(b, ca) {
1772-
c->need_gc = max(c->need_gc, bucket_gc_gen(b));
1768+
for_each_bucket(b, ca) {
1769+
c->need_gc = max(c->need_gc, bucket_gc_gen(b));
17731770

1774-
if (atomic_read(&b->pin))
1775-
continue;
1771+
if (atomic_read(&b->pin))
1772+
continue;
17761773

1777-
BUG_ON(!GC_MARK(b) && GC_SECTORS_USED(b));
1774+
BUG_ON(!GC_MARK(b) && GC_SECTORS_USED(b));
17781775

1779-
if (!GC_MARK(b) || GC_MARK(b) == GC_MARK_RECLAIMABLE)
1780-
c->avail_nbuckets++;
1781-
}
1776+
if (!GC_MARK(b) || GC_MARK(b) == GC_MARK_RECLAIMABLE)
1777+
c->avail_nbuckets++;
17821778
}
17831779

17841780
mutex_unlock(&c->bucket_lock);
@@ -1830,12 +1826,10 @@ static void bch_btree_gc(struct cache_set *c)
18301826

18311827
static bool gc_should_run(struct cache_set *c)
18321828
{
1833-
struct cache *ca;
1834-
unsigned int i;
1829+
struct cache *ca = c->cache;
18351830

1836-
for_each_cache(ca, c, i)
1837-
if (ca->invalidate_needs_gc)
1838-
return true;
1831+
if (ca->invalidate_needs_gc)
1832+
return true;
18391833

18401834
if (atomic_read(&c->sectors_to_gc) < 0)
18411835
return true;
@@ -2081,9 +2075,8 @@ int bch_btree_check(struct cache_set *c)
20812075

20822076
void bch_initial_gc_finish(struct cache_set *c)
20832077
{
2084-
struct cache *ca;
2078+
struct cache *ca = c->cache;
20852079
struct bucket *b;
2086-
unsigned int i;
20872080

20882081
bch_btree_gc_finish(c);
20892082

@@ -2098,20 +2091,18 @@ void bch_initial_gc_finish(struct cache_set *c)
20982091
* This is only safe for buckets that have no live data in them, which
20992092
* there should always be some of.
21002093
*/
2101-
for_each_cache(ca, c, i) {
2102-
for_each_bucket(b, ca) {
2103-
if (fifo_full(&ca->free[RESERVE_PRIO]) &&
2104-
fifo_full(&ca->free[RESERVE_BTREE]))
2105-
break;
2094+
for_each_bucket(b, ca) {
2095+
if (fifo_full(&ca->free[RESERVE_PRIO]) &&
2096+
fifo_full(&ca->free[RESERVE_BTREE]))
2097+
break;
21062098

2107-
if (bch_can_invalidate_bucket(ca, b) &&
2108-
!GC_MARK(b)) {
2109-
__bch_invalidate_one_bucket(ca, b);
2110-
if (!fifo_push(&ca->free[RESERVE_PRIO],
2111-
b - ca->buckets))
2112-
fifo_push(&ca->free[RESERVE_BTREE],
2113-
b - ca->buckets);
2114-
}
2099+
if (bch_can_invalidate_bucket(ca, b) &&
2100+
!GC_MARK(b)) {
2101+
__bch_invalidate_one_bucket(ca, b);
2102+
if (!fifo_push(&ca->free[RESERVE_PRIO],
2103+
b - ca->buckets))
2104+
fifo_push(&ca->free[RESERVE_BTREE],
2105+
b - ca->buckets);
21152106
}
21162107
}
21172108

0 commit comments

Comments
 (0)