2 * Copyright (C) 2010 Kent Overstreet <kent.overstreet@gmail.com>
3 * Copyright (C) 2014 Datera Inc.
8 #include "bkey_methods.h"
9 #include "btree_locking.h"
10 #include "btree_update.h"
22 #include "writeback.h"
24 #include <linux/slab.h>
25 #include <linux/bitops.h>
26 #include <linux/freezer.h>
27 #include <linux/kthread.h>
28 #include <linux/rcupdate.h>
29 #include <trace/events/bcache.h>
39 static void btree_node_range_checks_init(struct range_checks *r, unsigned depth)
43 for (i = 0; i < BTREE_MAX_DEPTH; i++)
44 r->l[i].min = r->l[i].max = POS_MIN;
48 static void btree_node_range_checks(struct cache_set *c, struct btree *b,
49 struct range_checks *r)
51 struct range_level *l = &r->l[b->level];
53 struct bpos expected_min = bkey_cmp(l->min, l->max)
54 ? btree_type_successor(b->btree_id, l->max)
57 bch_fs_inconsistent_on(bkey_cmp(b->data->min_key, expected_min), c,
58 "btree node has incorrect min key: %llu:%llu != %llu:%llu",
59 b->data->min_key.inode,
60 b->data->min_key.offset,
64 l->max = b->data->max_key;
66 if (b->level > r->depth) {
67 l = &r->l[b->level - 1];
69 bch_fs_inconsistent_on(bkey_cmp(b->data->min_key, l->min), c,
70 "btree node min doesn't match min of child nodes: %llu:%llu != %llu:%llu",
71 b->data->min_key.inode,
72 b->data->min_key.offset,
76 bch_fs_inconsistent_on(bkey_cmp(b->data->max_key, l->max), c,
77 "btree node max doesn't match max of child nodes: %llu:%llu != %llu:%llu",
78 b->data->max_key.inode,
79 b->data->max_key.offset,
83 if (bkey_cmp(b->data->max_key, POS_MAX))
85 btree_type_successor(b->btree_id,
90 u8 bch_btree_key_recalc_oldest_gen(struct cache_set *c, struct bkey_s_c k)
92 const struct bch_extent_ptr *ptr;
96 if (bkey_extent_is_data(k.k)) {
97 struct bkey_s_c_extent e = bkey_s_c_to_extent(k);
101 extent_for_each_online_device(c, e, ptr, ca) {
102 size_t b = PTR_BUCKET_NR(ca, ptr);
104 if (__gen_after(ca->oldest_gens[b], ptr->gen))
105 ca->oldest_gens[b] = ptr->gen;
107 max_stale = max(max_stale, ptr_stale(ca, ptr));
117 * For runtime mark and sweep:
119 static u8 bch_btree_mark_key(struct cache_set *c, enum bkey_type type,
123 case BKEY_TYPE_BTREE:
124 bch_gc_mark_key(c, k, c->sb.btree_node_size, true);
126 case BKEY_TYPE_EXTENTS:
127 bch_gc_mark_key(c, k, k.k->size, false);
128 return bch_btree_key_recalc_oldest_gen(c, k);
134 u8 bch_btree_mark_key_initial(struct cache_set *c, enum bkey_type type,
137 atomic64_set(&c->key_version,
138 max_t(u64, k.k->version.lo,
139 atomic64_read(&c->key_version)));
141 return bch_btree_mark_key(c, type, k);
144 static bool btree_gc_mark_node(struct cache_set *c, struct btree *b)
146 if (btree_node_has_ptrs(b)) {
147 struct btree_node_iter iter;
148 struct bkey unpacked;
152 for_each_btree_node_key_unpack(b, k, &iter,
153 btree_node_is_extents(b),
155 bkey_debugcheck(c, b, k);
156 stale = max(stale, bch_btree_mark_key(c,
157 btree_node_type(b), k));
160 if (btree_gc_rewrite_disabled(c))
167 if (btree_gc_always_rewrite(c))
173 static inline void __gc_pos_set(struct cache_set *c, struct gc_pos new_pos)
175 write_seqcount_begin(&c->gc_pos_lock);
177 write_seqcount_end(&c->gc_pos_lock);
180 static inline void gc_pos_set(struct cache_set *c, struct gc_pos new_pos)
182 BUG_ON(gc_pos_cmp(new_pos, c->gc_pos) <= 0);
183 __gc_pos_set(c, new_pos);
186 static int bch_gc_btree(struct cache_set *c, enum btree_id btree_id)
188 struct btree_iter iter;
191 struct range_checks r;
192 unsigned depth = btree_id == BTREE_ID_EXTENTS ? 0 : 1;
196 * if expensive_debug_checks is on, run range_checks on all leaf nodes:
198 if (expensive_debug_checks(c))
201 btree_node_range_checks_init(&r, depth);
203 for_each_btree_node(&iter, c, btree_id, POS_MIN, depth, b) {
204 btree_node_range_checks(c, b, &r);
206 bch_verify_btree_nr_keys(b);
208 should_rewrite = btree_gc_mark_node(c, b);
210 gc_pos_set(c, gc_pos_btree_node(b));
213 bch_btree_node_rewrite(&iter, b, NULL);
215 bch_btree_iter_cond_resched(&iter);
217 ret = bch_btree_iter_unlock(&iter);
221 mutex_lock(&c->btree_root_lock);
223 b = c->btree_roots[btree_id].b;
224 bch_btree_mark_key(c, BKEY_TYPE_BTREE, bkey_i_to_s_c(&b->key));
225 gc_pos_set(c, gc_pos_btree_root(b->btree_id));
227 mutex_unlock(&c->btree_root_lock);
231 static void bch_mark_allocator_buckets(struct cache_set *c)
234 struct open_bucket *ob;
238 for_each_cache(ca, c, ci) {
239 spin_lock(&ca->freelist_lock);
241 fifo_for_each_entry(i, &ca->free_inc, iter)
242 bch_mark_alloc_bucket(ca, &ca->buckets[i], true);
244 for (j = 0; j < RESERVE_NR; j++)
245 fifo_for_each_entry(i, &ca->free[j], iter)
246 bch_mark_alloc_bucket(ca, &ca->buckets[i], true);
248 spin_unlock(&ca->freelist_lock);
251 for (ob = c->open_buckets;
252 ob < c->open_buckets + ARRAY_SIZE(c->open_buckets);
254 const struct bch_extent_ptr *ptr;
256 mutex_lock(&ob->lock);
258 open_bucket_for_each_online_device(c, ob, ptr, ca)
259 bch_mark_alloc_bucket(ca, PTR_BUCKET(ca, ptr), true);
261 mutex_unlock(&ob->lock);
266 * Mark non btree metadata - prios, journal
268 static void bch_mark_metadata(struct cache_set *c)
274 for_each_cache(ca, c, i) {
275 for (j = 0; j < ca->journal.nr; j++) {
276 b = ca->journal.buckets[j];
277 bch_mark_metadata_bucket(ca, ca->buckets + b, true);
280 spin_lock(&ca->prio_buckets_lock);
282 for (j = 0; j < prio_buckets(ca) * 2; j++) {
283 b = ca->prio_buckets[j];
284 bch_mark_metadata_bucket(ca, ca->buckets + b, true);
287 spin_unlock(&ca->prio_buckets_lock);
291 /* Also see bch_pending_btree_node_free_insert_done() */
292 static void bch_mark_pending_btree_node_frees(struct cache_set *c)
294 struct bucket_stats_cache_set stats = { 0 };
295 struct btree_interior_update *as;
296 struct pending_btree_node_free *d;
298 mutex_lock(&c->btree_interior_update_lock);
299 gc_pos_set(c, gc_phase(GC_PHASE_PENDING_DELETE));
301 for_each_pending_btree_node_free(c, as, d)
302 if (d->index_update_done)
303 __bch_gc_mark_key(c, bkey_i_to_s_c(&d->key),
304 c->sb.btree_node_size, true,
307 * Don't apply stats - pending deletes aren't tracked in
311 mutex_unlock(&c->btree_interior_update_lock);
315 * bch_gc - recompute bucket marks and oldest_gen, rewrite btree nodes
317 void bch_gc(struct cache_set *c)
321 struct bucket_mark new;
322 u64 start_time = local_clock();
327 * Walk _all_ references to buckets, and recompute them:
329 * Order matters here:
330 * - Concurrent GC relies on the fact that we have a total ordering for
331 * everything that GC walks - see gc_will_visit_node(),
332 * gc_will_visit_root()
334 * - also, references move around in the course of index updates and
335 * various other crap: everything needs to agree on the ordering
336 * references are allowed to move around in - e.g., we're allowed to
337 * start with a reference owned by an open_bucket (the allocator) and
338 * move it to the btree, but not the reverse.
340 * This is necessary to ensure that gc doesn't miss references that
341 * move around - if references move backwards in the ordering GC
342 * uses, GC could skip past them
345 if (test_bit(BCH_FS_GC_FAILURE, &c->flags))
348 trace_bcache_gc_start(c);
351 * Do this before taking gc_lock - bch_disk_reservation_get() blocks on
352 * gc_lock if sectors_available goes to 0:
354 bch_recalc_sectors_available(c);
356 down_write(&c->gc_lock);
358 lg_global_lock(&c->bucket_stats_lock);
361 * Indicates to buckets code that gc is now in progress - done under
362 * bucket_stats_lock to avoid racing with bch_mark_key():
364 __gc_pos_set(c, GC_POS_MIN);
366 /* Save a copy of the existing bucket stats while we recompute them: */
367 for_each_cache(ca, c, i) {
368 ca->bucket_stats_cached = __bch_bucket_stats_read_cache(ca);
369 for_each_possible_cpu(cpu) {
370 struct bucket_stats_cache *p =
371 per_cpu_ptr(ca->bucket_stats_percpu, cpu);
372 memset(p, 0, sizeof(*p));
376 c->bucket_stats_cached = __bch_bucket_stats_read_cache_set(c);
377 for_each_possible_cpu(cpu) {
378 struct bucket_stats_cache_set *p =
379 per_cpu_ptr(c->bucket_stats_percpu, cpu);
381 memset(p->s, 0, sizeof(p->s));
382 p->persistent_reserved = 0;
385 lg_global_unlock(&c->bucket_stats_lock);
387 /* Clear bucket marks: */
388 for_each_cache(ca, c, i)
389 for_each_bucket(g, ca) {
390 bucket_cmpxchg(g, new, ({
391 new.owned_by_allocator = 0;
393 new.cached_sectors = 0;
394 new.dirty_sectors = 0;
396 ca->oldest_gens[g - ca->buckets] = new.gen;
399 /* Walk allocator's references: */
400 bch_mark_allocator_buckets(c);
403 while (c->gc_pos.phase < (int) BTREE_ID_NR) {
404 int ret = c->btree_roots[c->gc_pos.phase].b
405 ? bch_gc_btree(c, (int) c->gc_pos.phase)
409 bch_err(c, "btree gc failed: %d", ret);
410 set_bit(BCH_FS_GC_FAILURE, &c->flags);
411 up_write(&c->gc_lock);
415 gc_pos_set(c, gc_phase(c->gc_pos.phase + 1));
418 bch_mark_metadata(c);
419 bch_mark_pending_btree_node_frees(c);
420 bch_writeback_recalc_oldest_gens(c);
422 for_each_cache(ca, c, i)
423 atomic_long_set(&ca->saturated_count, 0);
425 /* Indicates that gc is no longer in progress: */
426 gc_pos_set(c, gc_phase(GC_PHASE_DONE));
428 up_write(&c->gc_lock);
429 trace_bcache_gc_end(c);
430 bch_time_stats_update(&c->btree_gc_time, start_time);
433 * Wake up allocator in case it was waiting for buckets
434 * because of not being able to inc gens
436 for_each_cache(ca, c, i)
437 bch_wake_allocator(ca);
440 /* Btree coalescing */
442 static void recalc_packed_keys(struct btree *b)
444 struct bkey_packed *k;
446 memset(&b->nr, 0, sizeof(b->nr));
448 BUG_ON(b->nsets != 1);
450 for (k = btree_bkey_first(b, b->set);
451 k != btree_bkey_last(b, b->set);
453 btree_keys_account_key_add(&b->nr, 0, k);
456 static void bch_coalesce_nodes(struct btree *old_nodes[GC_MERGE_NODES],
457 struct btree_iter *iter)
459 struct btree *parent = iter->nodes[old_nodes[0]->level + 1];
460 struct cache_set *c = iter->c;
461 unsigned i, nr_old_nodes, nr_new_nodes, u64s = 0;
462 unsigned blocks = btree_blocks(c) * 2 / 3;
463 struct btree *new_nodes[GC_MERGE_NODES];
464 struct btree_interior_update *as;
465 struct btree_reserve *res;
466 struct keylist keylist;
467 struct bkey_format_state format_state;
468 struct bkey_format new_format;
470 memset(new_nodes, 0, sizeof(new_nodes));
471 bch_keylist_init(&keylist, NULL, 0);
473 /* Count keys that are not deleted */
474 for (i = 0; i < GC_MERGE_NODES && old_nodes[i]; i++)
475 u64s += old_nodes[i]->nr.live_u64s;
477 nr_old_nodes = nr_new_nodes = i;
479 /* Check if all keys in @old_nodes could fit in one fewer node */
480 if (nr_old_nodes <= 1 ||
481 __vstruct_blocks(struct btree_node, c->block_bits,
482 DIV_ROUND_UP(u64s, nr_old_nodes - 1)) > blocks)
485 res = bch_btree_reserve_get(c, parent, nr_old_nodes,
487 BTREE_INSERT_USE_RESERVE,
490 trace_bcache_btree_gc_coalesce_fail(c,
491 BTREE_GC_COALESCE_FAIL_RESERVE_GET);
495 if (bch_keylist_realloc(&keylist, NULL, 0,
496 (BKEY_U64s + BKEY_EXTENT_U64s_MAX) * nr_old_nodes)) {
497 trace_bcache_btree_gc_coalesce_fail(c,
498 BTREE_GC_COALESCE_FAIL_KEYLIST_REALLOC);
502 /* Find a format that all keys in @old_nodes can pack into */
503 bch_bkey_format_init(&format_state);
505 for (i = 0; i < nr_old_nodes; i++)
506 __bch_btree_calc_format(&format_state, old_nodes[i]);
508 new_format = bch_bkey_format_done(&format_state);
510 /* Check if repacking would make any nodes too big to fit */
511 for (i = 0; i < nr_old_nodes; i++)
512 if (!bch_btree_node_format_fits(c, old_nodes[i], &new_format)) {
513 trace_bcache_btree_gc_coalesce_fail(c,
514 BTREE_GC_COALESCE_FAIL_FORMAT_FITS);
518 trace_bcache_btree_gc_coalesce(c, parent, nr_old_nodes);
520 as = bch_btree_interior_update_alloc(c);
522 for (i = 0; i < nr_old_nodes; i++)
523 bch_btree_interior_update_will_free_node(c, as, old_nodes[i]);
525 /* Repack everything with @new_format and sort down to one bset */
526 for (i = 0; i < nr_old_nodes; i++)
527 new_nodes[i] = __btree_node_alloc_replacement(c, old_nodes[i],
531 * Conceptually we concatenate the nodes together and slice them
532 * up at different boundaries.
534 for (i = nr_new_nodes - 1; i > 0; --i) {
535 struct btree *n1 = new_nodes[i];
536 struct btree *n2 = new_nodes[i - 1];
538 struct bset *s1 = btree_bset_first(n1);
539 struct bset *s2 = btree_bset_first(n2);
540 struct bkey_packed *k, *last = NULL;
542 /* Calculate how many keys from @n2 we could fit inside @n1 */
546 k < vstruct_last(s2) &&
547 vstruct_blocks_plus(n1->data, c->block_bits,
548 u64s + k->u64s) <= blocks;
554 if (u64s == le16_to_cpu(s2->u64s)) {
555 /* n2 fits entirely in n1 */
556 n1->key.k.p = n1->data->max_key = n2->data->max_key;
558 memcpy_u64s(vstruct_last(s1),
560 le16_to_cpu(s2->u64s));
561 le16_add_cpu(&s1->u64s, le16_to_cpu(s2->u64s));
563 set_btree_bset_end(n1, n1->set);
565 six_unlock_write(&n2->lock);
566 bch_btree_node_free_never_inserted(c, n2);
567 six_unlock_intent(&n2->lock);
569 memmove(new_nodes + i - 1,
571 sizeof(new_nodes[0]) * (nr_new_nodes - i));
572 new_nodes[--nr_new_nodes] = NULL;
574 /* move part of n2 into n1 */
575 n1->key.k.p = n1->data->max_key =
576 bkey_unpack_pos(n1, last);
579 btree_type_successor(iter->btree_id,
582 memcpy_u64s(vstruct_last(s1),
584 le16_add_cpu(&s1->u64s, u64s);
587 vstruct_idx(s2, u64s),
588 (le16_to_cpu(s2->u64s) - u64s) * sizeof(u64));
589 s2->u64s = cpu_to_le16(le16_to_cpu(s2->u64s) - u64s);
591 set_btree_bset_end(n1, n1->set);
592 set_btree_bset_end(n2, n2->set);
596 for (i = 0; i < nr_new_nodes; i++) {
597 struct btree *n = new_nodes[i];
599 recalc_packed_keys(n);
600 btree_node_reset_sib_u64s(n);
602 bch_btree_build_aux_trees(n);
603 six_unlock_write(&n->lock);
605 bch_btree_node_write(c, n, &as->cl, SIX_LOCK_intent, -1);
609 * The keys for the old nodes get deleted. We don't want to insert keys
610 * that compare equal to the keys for the new nodes we'll also be
611 * inserting - we can't because keys on a keylist must be strictly
612 * greater than the previous keys, and we also don't need to since the
613 * key for the new node will serve the same purpose (overwriting the key
616 for (i = 0; i < nr_old_nodes; i++) {
617 struct bkey_i delete;
620 for (j = 0; j < nr_new_nodes; j++)
621 if (!bkey_cmp(old_nodes[i]->key.k.p,
622 new_nodes[j]->key.k.p))
625 bkey_init(&delete.k);
626 delete.k.p = old_nodes[i]->key.k.p;
627 bch_keylist_add_in_order(&keylist, &delete);
633 * Keys for the new nodes get inserted: bch_btree_insert_keys() only
634 * does the lookup once and thus expects the keys to be in sorted order
635 * so we have to make sure the new keys are correctly ordered with
636 * respect to the deleted keys added in the previous loop
638 for (i = 0; i < nr_new_nodes; i++)
639 bch_keylist_add_in_order(&keylist, &new_nodes[i]->key);
641 /* Insert the newly coalesced nodes */
642 bch_btree_insert_node(parent, iter, &keylist, res, as);
644 BUG_ON(!bch_keylist_empty(&keylist));
646 BUG_ON(iter->nodes[old_nodes[0]->level] != old_nodes[0]);
648 BUG_ON(!bch_btree_iter_node_replace(iter, new_nodes[0]));
650 for (i = 0; i < nr_new_nodes; i++)
651 btree_open_bucket_put(c, new_nodes[i]);
653 /* Free the old nodes and update our sliding window */
654 for (i = 0; i < nr_old_nodes; i++) {
655 bch_btree_node_free_inmem(iter, old_nodes[i]);
656 six_unlock_intent(&old_nodes[i]->lock);
659 * the index update might have triggered a split, in which case
660 * the nodes we coalesced - the new nodes we just created -
661 * might not be sibling nodes anymore - don't add them to the
662 * sliding window (except the first):
665 old_nodes[i] = new_nodes[i];
669 six_unlock_intent(&new_nodes[i]->lock);
673 bch_keylist_free(&keylist, NULL);
674 bch_btree_reserve_put(c, res);
677 static int bch_coalesce_btree(struct cache_set *c, enum btree_id btree_id)
679 struct btree_iter iter;
683 /* Sliding window of adjacent btree nodes */
684 struct btree *merge[GC_MERGE_NODES];
685 u32 lock_seq[GC_MERGE_NODES];
688 * XXX: We don't have a good way of positively matching on sibling nodes
689 * that have the same parent - this code works by handling the cases
690 * where they might not have the same parent, and is thus fragile. Ugh.
692 * Perhaps redo this to use multiple linked iterators?
694 memset(merge, 0, sizeof(merge));
696 __for_each_btree_node(&iter, c, btree_id, POS_MIN, 0, b, U8_MAX) {
697 memmove(merge + 1, merge,
698 sizeof(merge) - sizeof(merge[0]));
699 memmove(lock_seq + 1, lock_seq,
700 sizeof(lock_seq) - sizeof(lock_seq[0]));
704 for (i = 1; i < GC_MERGE_NODES; i++) {
706 !six_relock_intent(&merge[i]->lock, lock_seq[i]))
709 if (merge[i]->level != merge[0]->level) {
710 six_unlock_intent(&merge[i]->lock);
714 memset(merge + i, 0, (GC_MERGE_NODES - i) * sizeof(merge[0]));
716 bch_coalesce_nodes(merge, &iter);
718 for (i = 1; i < GC_MERGE_NODES && merge[i]; i++) {
719 lock_seq[i] = merge[i]->lock.state.seq;
720 six_unlock_intent(&merge[i]->lock);
723 lock_seq[0] = merge[0]->lock.state.seq;
725 if (test_bit(BCH_FS_GC_STOPPING, &c->flags)) {
726 bch_btree_iter_unlock(&iter);
730 bch_btree_iter_cond_resched(&iter);
733 * If the parent node wasn't relocked, it might have been split
734 * and the nodes in our sliding window might not have the same
735 * parent anymore - blow away the sliding window:
737 if (iter.nodes[iter.level + 1] &&
738 !btree_node_intent_locked(&iter, iter.level + 1))
740 (GC_MERGE_NODES - 1) * sizeof(merge[0]));
742 return bch_btree_iter_unlock(&iter);
746 * bch_coalesce - coalesce adjacent nodes with low occupancy
748 void bch_coalesce(struct cache_set *c)
753 if (btree_gc_coalesce_disabled(c))
756 if (test_bit(BCH_FS_GC_FAILURE, &c->flags))
759 down_read(&c->gc_lock);
760 trace_bcache_gc_coalesce_start(c);
761 start_time = local_clock();
763 for (id = 0; id < BTREE_ID_NR; id++) {
764 int ret = c->btree_roots[id].b
765 ? bch_coalesce_btree(c, id)
769 if (ret != -ESHUTDOWN)
770 bch_err(c, "btree coalescing failed: %d", ret);
771 set_bit(BCH_FS_GC_FAILURE, &c->flags);
776 bch_time_stats_update(&c->btree_coalesce_time, start_time);
777 trace_bcache_gc_coalesce_end(c);
778 up_read(&c->gc_lock);
781 static int bch_gc_thread(void *arg)
783 struct cache_set *c = arg;
784 struct io_clock *clock = &c->io_clock[WRITE];
785 unsigned long last = atomic_long_read(&clock->now);
786 unsigned last_kick = atomic_read(&c->kick_gc);
791 unsigned long next = last + c->capacity / 16;
793 while (atomic_long_read(&clock->now) < next) {
794 set_current_state(TASK_INTERRUPTIBLE);
796 if (kthread_should_stop()) {
797 __set_current_state(TASK_RUNNING);
801 if (atomic_read(&c->kick_gc) != last_kick) {
802 __set_current_state(TASK_RUNNING);
806 bch_io_clock_schedule_timeout(clock, next);
810 last = atomic_long_read(&clock->now);
811 last_kick = atomic_read(&c->kick_gc);
816 debug_check_no_locks_held();
822 void bch_gc_thread_stop(struct cache_set *c)
824 set_bit(BCH_FS_GC_STOPPING, &c->flags);
826 if (!IS_ERR_OR_NULL(c->gc_thread))
827 kthread_stop(c->gc_thread);
830 int bch_gc_thread_start(struct cache_set *c)
832 clear_bit(BCH_FS_GC_STOPPING, &c->flags);
834 c->gc_thread = kthread_create(bch_gc_thread, c, "bcache_gc");
835 if (IS_ERR(c->gc_thread))
836 return PTR_ERR(c->gc_thread);
838 wake_up_process(c->gc_thread);
842 /* Initial GC computes bucket marks during startup */
844 static void bch_initial_gc_btree(struct cache_set *c, enum btree_id id)
846 struct btree_iter iter;
848 struct range_checks r;
850 btree_node_range_checks_init(&r, 0);
852 if (!c->btree_roots[id].b)
856 * We have to hit every btree node before starting journal replay, in
857 * order for the journal seq blacklist machinery to work:
859 for_each_btree_node(&iter, c, id, POS_MIN, 0, b) {
860 btree_node_range_checks(c, b, &r);
862 if (btree_node_has_ptrs(b)) {
863 struct btree_node_iter node_iter;
864 struct bkey unpacked;
867 for_each_btree_node_key_unpack(b, k, &node_iter,
868 btree_node_is_extents(b),
870 bch_btree_mark_key_initial(c, btree_node_type(b), k);
873 bch_btree_iter_cond_resched(&iter);
876 bch_btree_iter_unlock(&iter);
878 bch_btree_mark_key(c, BKEY_TYPE_BTREE,
879 bkey_i_to_s_c(&c->btree_roots[id].b->key));
882 int bch_initial_gc(struct cache_set *c, struct list_head *journal)
887 for (id = 0; id < BTREE_ID_NR; id++)
888 bch_initial_gc_btree(c, id);
890 bch_journal_mark(c, journal);
894 * Skip past versions that might have possibly been used (as nonces),
895 * but hadn't had their pointers written:
897 if (c->sb.encryption_type)
898 atomic64_add(1 << 16, &c->key_version);
900 bch_mark_metadata(c);
902 gc_pos_set(c, gc_phase(GC_PHASE_DONE));
903 set_bit(BCH_FS_INITIAL_GC_DONE, &c->flags);