@@ -1167,19 +1167,18 @@ static void make_btree_freeing_key(struct btree *b, struct bkey *k)
11671167static 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
18311827static 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
20822076void 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