.. | .. |
---|
99 | 99 | #define PTR_HASH(c, k) \ |
---|
100 | 100 | (((k)->ptr[0] >> c->bucket_bits) | PTR_GEN(k, 0)) |
---|
101 | 101 | |
---|
| 102 | +static struct workqueue_struct *btree_io_wq; |
---|
| 103 | + |
---|
102 | 104 | #define insert_lock(s, b) ((b)->level <= (s)->lock) |
---|
103 | 105 | |
---|
104 | | -/* |
---|
105 | | - * These macros are for recursing down the btree - they handle the details of |
---|
106 | | - * locking and looking up nodes in the cache for you. They're best treated as |
---|
107 | | - * mere syntax when reading code that uses them. |
---|
108 | | - * |
---|
109 | | - * op->lock determines whether we take a read or a write lock at a given depth. |
---|
110 | | - * If you've got a read lock and find that you need a write lock (i.e. you're |
---|
111 | | - * going to have to split), set op->lock and return -EINTR; btree_root() will |
---|
112 | | - * call you again and you'll have the correct lock. |
---|
113 | | - */ |
---|
114 | | - |
---|
115 | | -/** |
---|
116 | | - * btree - recurse down the btree on a specified key |
---|
117 | | - * @fn: function to call, which will be passed the child node |
---|
118 | | - * @key: key to recurse on |
---|
119 | | - * @b: parent btree node |
---|
120 | | - * @op: pointer to struct btree_op |
---|
121 | | - */ |
---|
122 | | -#define btree(fn, key, b, op, ...) \ |
---|
123 | | -({ \ |
---|
124 | | - int _r, l = (b)->level - 1; \ |
---|
125 | | - bool _w = l <= (op)->lock; \ |
---|
126 | | - struct btree *_child = bch_btree_node_get((b)->c, op, key, l, \ |
---|
127 | | - _w, b); \ |
---|
128 | | - if (!IS_ERR(_child)) { \ |
---|
129 | | - _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__); \ |
---|
130 | | - rw_unlock(_w, _child); \ |
---|
131 | | - } else \ |
---|
132 | | - _r = PTR_ERR(_child); \ |
---|
133 | | - _r; \ |
---|
134 | | -}) |
---|
135 | | - |
---|
136 | | -/** |
---|
137 | | - * btree_root - call a function on the root of the btree |
---|
138 | | - * @fn: function to call, which will be passed the child node |
---|
139 | | - * @c: cache set |
---|
140 | | - * @op: pointer to struct btree_op |
---|
141 | | - */ |
---|
142 | | -#define btree_root(fn, c, op, ...) \ |
---|
143 | | -({ \ |
---|
144 | | - int _r = -EINTR; \ |
---|
145 | | - do { \ |
---|
146 | | - struct btree *_b = (c)->root; \ |
---|
147 | | - bool _w = insert_lock(op, _b); \ |
---|
148 | | - rw_lock(_w, _b, _b->level); \ |
---|
149 | | - if (_b == (c)->root && \ |
---|
150 | | - _w == insert_lock(op, _b)) { \ |
---|
151 | | - _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__); \ |
---|
152 | | - } \ |
---|
153 | | - rw_unlock(_w, _b); \ |
---|
154 | | - bch_cannibalize_unlock(c); \ |
---|
155 | | - if (_r == -EINTR) \ |
---|
156 | | - schedule(); \ |
---|
157 | | - } while (_r == -EINTR); \ |
---|
158 | | - \ |
---|
159 | | - finish_wait(&(c)->btree_cache_wait, &(op)->wait); \ |
---|
160 | | - _r; \ |
---|
161 | | -}) |
---|
162 | 106 | |
---|
163 | 107 | static inline struct bset *write_block(struct btree *b) |
---|
164 | 108 | { |
---|
165 | | - return ((void *) btree_bset_first(b)) + b->written * block_bytes(b->c); |
---|
| 109 | + return ((void *) btree_bset_first(b)) + b->written * block_bytes(b->c->cache); |
---|
166 | 110 | } |
---|
167 | 111 | |
---|
168 | 112 | static void bch_btree_init_next(struct btree *b) |
---|
.. | .. |
---|
175 | 119 | |
---|
176 | 120 | if (b->written < btree_blocks(b)) |
---|
177 | 121 | bch_bset_init_next(&b->keys, write_block(b), |
---|
178 | | - bset_magic(&b->c->sb)); |
---|
| 122 | + bset_magic(&b->c->cache->sb)); |
---|
179 | 123 | |
---|
180 | 124 | } |
---|
181 | 125 | |
---|
.. | .. |
---|
207 | 151 | struct bset *i = btree_bset_first(b); |
---|
208 | 152 | struct btree_iter *iter; |
---|
209 | 153 | |
---|
| 154 | + /* |
---|
| 155 | + * c->fill_iter can allocate an iterator with more memory space |
---|
| 156 | + * than static MAX_BSETS. |
---|
| 157 | + * See the comment arount cache_set->fill_iter. |
---|
| 158 | + */ |
---|
210 | 159 | iter = mempool_alloc(&b->c->fill_iter, GFP_NOIO); |
---|
211 | | - iter->size = b->c->sb.bucket_size / b->c->sb.block_size; |
---|
| 160 | + iter->size = b->c->cache->sb.bucket_size / b->c->cache->sb.block_size; |
---|
212 | 161 | iter->used = 0; |
---|
213 | 162 | |
---|
214 | 163 | #ifdef CONFIG_BCACHE_DEBUG |
---|
.. | .. |
---|
226 | 175 | goto err; |
---|
227 | 176 | |
---|
228 | 177 | err = "bad btree header"; |
---|
229 | | - if (b->written + set_blocks(i, block_bytes(b->c)) > |
---|
| 178 | + if (b->written + set_blocks(i, block_bytes(b->c->cache)) > |
---|
230 | 179 | btree_blocks(b)) |
---|
231 | 180 | goto err; |
---|
232 | 181 | |
---|
233 | 182 | err = "bad magic"; |
---|
234 | | - if (i->magic != bset_magic(&b->c->sb)) |
---|
| 183 | + if (i->magic != bset_magic(&b->c->cache->sb)) |
---|
235 | 184 | goto err; |
---|
236 | 185 | |
---|
237 | 186 | err = "bad checksum"; |
---|
.. | .. |
---|
252 | 201 | |
---|
253 | 202 | bch_btree_iter_push(iter, i->start, bset_bkey_last(i)); |
---|
254 | 203 | |
---|
255 | | - b->written += set_blocks(i, block_bytes(b->c)); |
---|
| 204 | + b->written += set_blocks(i, block_bytes(b->c->cache)); |
---|
256 | 205 | } |
---|
257 | 206 | |
---|
258 | 207 | err = "corrupted btree"; |
---|
259 | 208 | for (i = write_block(b); |
---|
260 | 209 | bset_sector_offset(&b->keys, i) < KEY_SIZE(&b->key); |
---|
261 | | - i = ((void *) i) + block_bytes(b->c)) |
---|
| 210 | + i = ((void *) i) + block_bytes(b->c->cache)) |
---|
262 | 211 | if (i->seq == b->keys.set[0].data->seq) |
---|
263 | 212 | goto err; |
---|
264 | 213 | |
---|
.. | .. |
---|
272 | 221 | |
---|
273 | 222 | if (b->written < btree_blocks(b)) |
---|
274 | 223 | bch_bset_init_next(&b->keys, write_block(b), |
---|
275 | | - bset_magic(&b->c->sb)); |
---|
| 224 | + bset_magic(&b->c->cache->sb)); |
---|
276 | 225 | out: |
---|
277 | 226 | mempool_free(iter, &b->c->fill_iter); |
---|
278 | 227 | return; |
---|
.. | .. |
---|
361 | 310 | btree_complete_write(b, w); |
---|
362 | 311 | |
---|
363 | 312 | if (btree_node_dirty(b)) |
---|
364 | | - schedule_delayed_work(&b->work, 30 * HZ); |
---|
| 313 | + queue_delayed_work(btree_io_wq, &b->work, 30 * HZ); |
---|
365 | 314 | |
---|
366 | 315 | closure_return_with_destructor(cl, btree_node_write_unlock); |
---|
367 | 316 | } |
---|
.. | .. |
---|
400 | 349 | |
---|
401 | 350 | b->bio->bi_end_io = btree_node_write_endio; |
---|
402 | 351 | b->bio->bi_private = cl; |
---|
403 | | - b->bio->bi_iter.bi_size = roundup(set_bytes(i), block_bytes(b->c)); |
---|
| 352 | + b->bio->bi_iter.bi_size = roundup(set_bytes(i), block_bytes(b->c->cache)); |
---|
404 | 353 | b->bio->bi_opf = REQ_OP_WRITE | REQ_META | REQ_FUA; |
---|
405 | 354 | bch_bio_map(b->bio, i); |
---|
406 | 355 | |
---|
.. | .. |
---|
424 | 373 | bset_sector_offset(&b->keys, i)); |
---|
425 | 374 | |
---|
426 | 375 | if (!bch_bio_alloc_pages(b->bio, __GFP_NOWARN|GFP_NOWAIT)) { |
---|
427 | | - int j; |
---|
428 | 376 | struct bio_vec *bv; |
---|
429 | | - void *base = (void *) ((unsigned long) i & ~(PAGE_SIZE - 1)); |
---|
| 377 | + void *addr = (void *) ((unsigned long) i & ~(PAGE_SIZE - 1)); |
---|
| 378 | + struct bvec_iter_all iter_all; |
---|
430 | 379 | |
---|
431 | | - bio_for_each_segment_all(bv, b->bio, j) |
---|
432 | | - memcpy(page_address(bv->bv_page), |
---|
433 | | - base + j * PAGE_SIZE, PAGE_SIZE); |
---|
| 380 | + bio_for_each_segment_all(bv, b->bio, iter_all) { |
---|
| 381 | + memcpy(page_address(bv->bv_page), addr, PAGE_SIZE); |
---|
| 382 | + addr += PAGE_SIZE; |
---|
| 383 | + } |
---|
434 | 384 | |
---|
435 | 385 | bch_submit_bbio(b->bio, b->c, &k.key, 0); |
---|
436 | 386 | |
---|
.. | .. |
---|
475 | 425 | |
---|
476 | 426 | do_btree_node_write(b); |
---|
477 | 427 | |
---|
478 | | - atomic_long_add(set_blocks(i, block_bytes(b->c)) * b->c->sb.block_size, |
---|
| 428 | + atomic_long_add(set_blocks(i, block_bytes(b->c->cache)) * b->c->cache->sb.block_size, |
---|
479 | 429 | &PTR_CACHE(b->c, &b->key, 0)->btree_sectors_written); |
---|
480 | 430 | |
---|
481 | | - b->written += set_blocks(i, block_bytes(b->c)); |
---|
| 431 | + b->written += set_blocks(i, block_bytes(b->c->cache)); |
---|
482 | 432 | } |
---|
483 | 433 | |
---|
484 | 434 | void bch_btree_node_write(struct btree *b, struct closure *parent) |
---|
.. | .. |
---|
533 | 483 | BUG_ON(!i->keys); |
---|
534 | 484 | |
---|
535 | 485 | if (!btree_node_dirty(b)) |
---|
536 | | - schedule_delayed_work(&b->work, 30 * HZ); |
---|
| 486 | + queue_delayed_work(btree_io_wq, &b->work, 30 * HZ); |
---|
537 | 487 | |
---|
538 | 488 | set_btree_node_dirty(b); |
---|
539 | 489 | |
---|
| 490 | + /* |
---|
| 491 | + * w->journal is always the oldest journal pin of all bkeys |
---|
| 492 | + * in the leaf node, to make sure the oldest jset seq won't |
---|
| 493 | + * be increased before this btree node is flushed. |
---|
| 494 | + */ |
---|
540 | 495 | if (journal_ref) { |
---|
541 | 496 | if (w->journal && |
---|
542 | 497 | journal_pin_cmp(b->c, w->journal, journal_ref)) { |
---|
.. | .. |
---|
561 | 516 | * mca -> memory cache |
---|
562 | 517 | */ |
---|
563 | 518 | |
---|
564 | | -#define mca_reserve(c) (((c->root && c->root->level) \ |
---|
| 519 | +#define mca_reserve(c) (((!IS_ERR_OR_NULL(c->root) && c->root->level) \ |
---|
565 | 520 | ? c->root->level : 1) * 8 + 16) |
---|
566 | 521 | #define mca_can_free(c) \ |
---|
567 | 522 | max_t(int, 0, c->btree_cache_used - mca_reserve(c)) |
---|
.. | .. |
---|
607 | 562 | static struct btree *mca_bucket_alloc(struct cache_set *c, |
---|
608 | 563 | struct bkey *k, gfp_t gfp) |
---|
609 | 564 | { |
---|
| 565 | + /* |
---|
| 566 | + * kzalloc() is necessary here for initialization, |
---|
| 567 | + * see code comments in bch_btree_keys_init(). |
---|
| 568 | + */ |
---|
610 | 569 | struct btree *b = kzalloc(sizeof(struct btree), gfp); |
---|
611 | 570 | |
---|
612 | 571 | if (!b) |
---|
.. | .. |
---|
662 | 621 | * and BTREE_NODE_journal_flush bit cleared by btree_flush_write(). |
---|
663 | 622 | */ |
---|
664 | 623 | if (btree_node_journal_flush(b)) { |
---|
665 | | - pr_debug("bnode %p is flushing by journal, retry", b); |
---|
| 624 | + pr_debug("bnode %p is flushing by journal, retry\n", b); |
---|
666 | 625 | mutex_unlock(&b->write_lock); |
---|
667 | 626 | udelay(1); |
---|
668 | 627 | goto retry; |
---|
.. | .. |
---|
719 | 678 | |
---|
720 | 679 | i = 0; |
---|
721 | 680 | btree_cache_used = c->btree_cache_used; |
---|
722 | | - list_for_each_entry_safe(b, t, &c->btree_cache_freeable, list) { |
---|
| 681 | + list_for_each_entry_safe_reverse(b, t, &c->btree_cache_freeable, list) { |
---|
723 | 682 | if (nr <= 0) |
---|
724 | 683 | goto out; |
---|
725 | 684 | |
---|
726 | | - if (++i > 3 && |
---|
727 | | - !mca_reap(b, 0, false)) { |
---|
| 685 | + if (!mca_reap(b, 0, false)) { |
---|
728 | 686 | mca_data_free(b); |
---|
729 | 687 | rw_unlock(true, b); |
---|
730 | 688 | freed++; |
---|
731 | 689 | } |
---|
732 | 690 | nr--; |
---|
| 691 | + i++; |
---|
733 | 692 | } |
---|
734 | 693 | |
---|
735 | | - for (; (nr--) && i < btree_cache_used; i++) { |
---|
736 | | - if (list_empty(&c->btree_cache)) |
---|
| 694 | + list_for_each_entry_safe_reverse(b, t, &c->btree_cache, list) { |
---|
| 695 | + if (nr <= 0 || i >= btree_cache_used) |
---|
737 | 696 | goto out; |
---|
738 | 697 | |
---|
739 | | - b = list_first_entry(&c->btree_cache, struct btree, list); |
---|
740 | | - list_rotate_left(&c->btree_cache); |
---|
741 | | - |
---|
742 | | - if (!b->accessed && |
---|
743 | | - !mca_reap(b, 0, false)) { |
---|
| 698 | + if (!mca_reap(b, 0, false)) { |
---|
744 | 699 | mca_bucket_free(b); |
---|
745 | 700 | mca_data_free(b); |
---|
746 | 701 | rw_unlock(true, b); |
---|
747 | 702 | freed++; |
---|
748 | | - } else |
---|
749 | | - b->accessed = 0; |
---|
| 703 | + } |
---|
| 704 | + |
---|
| 705 | + nr--; |
---|
| 706 | + i++; |
---|
750 | 707 | } |
---|
751 | 708 | out: |
---|
752 | 709 | mutex_unlock(&c->bucket_lock); |
---|
.. | .. |
---|
783 | 740 | if (c->verify_data) |
---|
784 | 741 | list_move(&c->verify_data->list, &c->btree_cache); |
---|
785 | 742 | |
---|
786 | | - free_pages((unsigned long) c->verify_ondisk, ilog2(bucket_pages(c))); |
---|
| 743 | + free_pages((unsigned long) c->verify_ondisk, ilog2(meta_bucket_pages(&c->cache->sb))); |
---|
787 | 744 | #endif |
---|
788 | 745 | |
---|
789 | 746 | list_splice(&c->btree_cache_freeable, |
---|
.. | .. |
---|
830 | 787 | mutex_init(&c->verify_lock); |
---|
831 | 788 | |
---|
832 | 789 | c->verify_ondisk = (void *) |
---|
833 | | - __get_free_pages(GFP_KERNEL|__GFP_COMP, ilog2(bucket_pages(c))); |
---|
| 790 | + __get_free_pages(GFP_KERNEL|__GFP_COMP, |
---|
| 791 | + ilog2(meta_bucket_pages(&c->cache->sb))); |
---|
| 792 | + if (!c->verify_ondisk) { |
---|
| 793 | + /* |
---|
| 794 | + * Don't worry about the mca_rereserve buckets |
---|
| 795 | + * allocated in previous for-loop, they will be |
---|
| 796 | + * handled properly in bch_cache_set_unregister(). |
---|
| 797 | + */ |
---|
| 798 | + return -ENOMEM; |
---|
| 799 | + } |
---|
834 | 800 | |
---|
835 | 801 | c->verify_data = mca_bucket_alloc(c, &ZERO_KEY, GFP_KERNEL); |
---|
836 | 802 | |
---|
.. | .. |
---|
847 | 813 | c->shrink.batch = c->btree_pages * 2; |
---|
848 | 814 | |
---|
849 | 815 | if (register_shrinker(&c->shrink)) |
---|
850 | | - pr_warn("bcache: %s: could not register shrinker", |
---|
| 816 | + pr_warn("bcache: %s: could not register shrinker\n", |
---|
851 | 817 | __func__); |
---|
852 | 818 | |
---|
853 | 819 | return 0; |
---|
.. | .. |
---|
919 | 885 | * cannibalize_bucket() will take. This means every time we unlock the root of |
---|
920 | 886 | * the btree, we need to release this lock if we have it held. |
---|
921 | 887 | */ |
---|
922 | | -static void bch_cannibalize_unlock(struct cache_set *c) |
---|
| 888 | +void bch_cannibalize_unlock(struct cache_set *c) |
---|
923 | 889 | { |
---|
924 | 890 | spin_lock(&c->btree_cannibalize_lock); |
---|
925 | 891 | if (c->btree_cache_alloc_lock == current) { |
---|
.. | .. |
---|
1004 | 970 | * bch_btree_node_get - find a btree node in the cache and lock it, reading it |
---|
1005 | 971 | * in from disk if necessary. |
---|
1006 | 972 | * |
---|
1007 | | - * If IO is necessary and running under generic_make_request, returns -EAGAIN. |
---|
| 973 | + * If IO is necessary and running under submit_bio_noacct, returns -EAGAIN. |
---|
1008 | 974 | * |
---|
1009 | 975 | * The btree node will have either a read or a write lock held, depending on |
---|
1010 | 976 | * level and op->lock. |
---|
.. | .. |
---|
1054 | 1020 | BUG_ON(!b->written); |
---|
1055 | 1021 | |
---|
1056 | 1022 | b->parent = parent; |
---|
1057 | | - b->accessed = 1; |
---|
1058 | 1023 | |
---|
1059 | 1024 | for (; i <= b->keys.nsets && b->keys.set[i].size; i++) { |
---|
1060 | 1025 | prefetch(b->keys.set[i].tree); |
---|
.. | .. |
---|
1100 | 1065 | */ |
---|
1101 | 1066 | if (btree_node_journal_flush(b)) { |
---|
1102 | 1067 | mutex_unlock(&b->write_lock); |
---|
1103 | | - pr_debug("bnode %p journal_flush set, retry", b); |
---|
| 1068 | + pr_debug("bnode %p journal_flush set, retry\n", b); |
---|
1104 | 1069 | udelay(1); |
---|
1105 | 1070 | goto retry; |
---|
1106 | 1071 | } |
---|
.. | .. |
---|
1125 | 1090 | struct btree *parent) |
---|
1126 | 1091 | { |
---|
1127 | 1092 | BKEY_PADDED(key) k; |
---|
1128 | | - struct btree *b = ERR_PTR(-EAGAIN); |
---|
| 1093 | + struct btree *b; |
---|
1129 | 1094 | |
---|
1130 | 1095 | mutex_lock(&c->bucket_lock); |
---|
1131 | 1096 | retry: |
---|
1132 | | - if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, wait)) |
---|
| 1097 | + /* return ERR_PTR(-EAGAIN) when it fails */ |
---|
| 1098 | + b = ERR_PTR(-EAGAIN); |
---|
| 1099 | + if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, wait)) |
---|
1133 | 1100 | goto err; |
---|
1134 | 1101 | |
---|
1135 | 1102 | bkey_put(c, &k.key); |
---|
.. | .. |
---|
1145 | 1112 | goto retry; |
---|
1146 | 1113 | } |
---|
1147 | 1114 | |
---|
1148 | | - b->accessed = 1; |
---|
1149 | 1115 | b->parent = parent; |
---|
1150 | | - bch_bset_init_next(&b->keys, b->keys.set->data, bset_magic(&b->c->sb)); |
---|
| 1116 | + bch_bset_init_next(&b->keys, b->keys.set->data, bset_magic(&b->c->cache->sb)); |
---|
1151 | 1117 | |
---|
1152 | 1118 | mutex_unlock(&c->bucket_lock); |
---|
1153 | 1119 | |
---|
.. | .. |
---|
1174 | 1140 | { |
---|
1175 | 1141 | struct btree *n = bch_btree_node_alloc(b->c, op, b->level, b->parent); |
---|
1176 | 1142 | |
---|
1177 | | - if (!IS_ERR_OR_NULL(n)) { |
---|
| 1143 | + if (!IS_ERR(n)) { |
---|
1178 | 1144 | mutex_lock(&n->write_lock); |
---|
1179 | 1145 | bch_btree_sort_into(&b->keys, &n->keys, &b->c->sort); |
---|
1180 | 1146 | bkey_copy_key(&n->key, &b->key); |
---|
.. | .. |
---|
1206 | 1172 | static int btree_check_reserve(struct btree *b, struct btree_op *op) |
---|
1207 | 1173 | { |
---|
1208 | 1174 | struct cache_set *c = b->c; |
---|
1209 | | - struct cache *ca; |
---|
1210 | | - unsigned int i, reserve = (c->root->level - b->level) * 2 + 1; |
---|
| 1175 | + struct cache *ca = c->cache; |
---|
| 1176 | + unsigned int reserve = (c->root->level - b->level) * 2 + 1; |
---|
1211 | 1177 | |
---|
1212 | 1178 | mutex_lock(&c->bucket_lock); |
---|
1213 | 1179 | |
---|
1214 | | - for_each_cache(ca, c, i) |
---|
1215 | | - if (fifo_used(&ca->free[RESERVE_BTREE]) < reserve) { |
---|
1216 | | - if (op) |
---|
1217 | | - prepare_to_wait(&c->btree_cache_wait, &op->wait, |
---|
1218 | | - TASK_UNINTERRUPTIBLE); |
---|
1219 | | - mutex_unlock(&c->bucket_lock); |
---|
1220 | | - return -EINTR; |
---|
1221 | | - } |
---|
| 1180 | + if (fifo_used(&ca->free[RESERVE_BTREE]) < reserve) { |
---|
| 1181 | + if (op) |
---|
| 1182 | + prepare_to_wait(&c->btree_cache_wait, &op->wait, |
---|
| 1183 | + TASK_UNINTERRUPTIBLE); |
---|
| 1184 | + mutex_unlock(&c->bucket_lock); |
---|
| 1185 | + return -EINTR; |
---|
| 1186 | + } |
---|
1222 | 1187 | |
---|
1223 | 1188 | mutex_unlock(&c->bucket_lock); |
---|
1224 | 1189 | |
---|
.. | .. |
---|
1377 | 1342 | memset(new_nodes, 0, sizeof(new_nodes)); |
---|
1378 | 1343 | closure_init_stack(&cl); |
---|
1379 | 1344 | |
---|
1380 | | - while (nodes < GC_MERGE_NODES && !IS_ERR_OR_NULL(r[nodes].b)) |
---|
| 1345 | + while (nodes < GC_MERGE_NODES && !IS_ERR(r[nodes].b)) |
---|
1381 | 1346 | keys += r[nodes++].keys; |
---|
1382 | 1347 | |
---|
1383 | 1348 | blocks = btree_default_blocks(b->c) * 2 / 3; |
---|
1384 | 1349 | |
---|
1385 | 1350 | if (nodes < 2 || |
---|
1386 | 1351 | __set_blocks(b->keys.set[0].data, keys, |
---|
1387 | | - block_bytes(b->c)) > blocks * (nodes - 1)) |
---|
| 1352 | + block_bytes(b->c->cache)) > blocks * (nodes - 1)) |
---|
1388 | 1353 | return 0; |
---|
1389 | 1354 | |
---|
1390 | 1355 | for (i = 0; i < nodes; i++) { |
---|
1391 | 1356 | new_nodes[i] = btree_node_alloc_replacement(r[i].b, NULL); |
---|
1392 | | - if (IS_ERR_OR_NULL(new_nodes[i])) |
---|
| 1357 | + if (IS_ERR(new_nodes[i])) |
---|
1393 | 1358 | goto out_nocoalesce; |
---|
1394 | 1359 | } |
---|
1395 | 1360 | |
---|
.. | .. |
---|
1418 | 1383 | k = bkey_next(k)) { |
---|
1419 | 1384 | if (__set_blocks(n1, n1->keys + keys + |
---|
1420 | 1385 | bkey_u64s(k), |
---|
1421 | | - block_bytes(b->c)) > blocks) |
---|
| 1386 | + block_bytes(b->c->cache)) > blocks) |
---|
1422 | 1387 | break; |
---|
1423 | 1388 | |
---|
1424 | 1389 | last = k; |
---|
.. | .. |
---|
1434 | 1399 | * though) |
---|
1435 | 1400 | */ |
---|
1436 | 1401 | if (__set_blocks(n1, n1->keys + n2->keys, |
---|
1437 | | - block_bytes(b->c)) > |
---|
| 1402 | + block_bytes(b->c->cache)) > |
---|
1438 | 1403 | btree_blocks(new_nodes[i])) |
---|
1439 | 1404 | goto out_unlock_nocoalesce; |
---|
1440 | 1405 | |
---|
.. | .. |
---|
1443 | 1408 | last = &r->b->key; |
---|
1444 | 1409 | } |
---|
1445 | 1410 | |
---|
1446 | | - BUG_ON(__set_blocks(n1, n1->keys + keys, block_bytes(b->c)) > |
---|
| 1411 | + BUG_ON(__set_blocks(n1, n1->keys + keys, block_bytes(b->c->cache)) > |
---|
1447 | 1412 | btree_blocks(new_nodes[i])); |
---|
1448 | 1413 | |
---|
1449 | 1414 | if (last) |
---|
.. | .. |
---|
1517 | 1482 | |
---|
1518 | 1483 | out_nocoalesce: |
---|
1519 | 1484 | closure_sync(&cl); |
---|
1520 | | - bch_keylist_free(&keylist); |
---|
1521 | 1485 | |
---|
1522 | 1486 | while ((k = bch_keylist_pop(&keylist))) |
---|
1523 | 1487 | if (!bkey_cmp(k, &ZERO_KEY)) |
---|
1524 | 1488 | atomic_dec(&b->c->prio_blocked); |
---|
| 1489 | + bch_keylist_free(&keylist); |
---|
1525 | 1490 | |
---|
1526 | 1491 | for (i = 0; i < nodes; i++) |
---|
1527 | | - if (!IS_ERR_OR_NULL(new_nodes[i])) { |
---|
| 1492 | + if (!IS_ERR(new_nodes[i])) { |
---|
1528 | 1493 | btree_node_free(new_nodes[i]); |
---|
1529 | 1494 | rw_unlock(true, new_nodes[i]); |
---|
1530 | 1495 | } |
---|
.. | .. |
---|
1706 | 1671 | if (should_rewrite) { |
---|
1707 | 1672 | n = btree_node_alloc_replacement(b, NULL); |
---|
1708 | 1673 | |
---|
1709 | | - if (!IS_ERR_OR_NULL(n)) { |
---|
| 1674 | + if (!IS_ERR(n)) { |
---|
1710 | 1675 | bch_btree_node_write_sync(n); |
---|
1711 | 1676 | |
---|
1712 | 1677 | bch_btree_set_root(n); |
---|
.. | .. |
---|
1734 | 1699 | { |
---|
1735 | 1700 | struct cache *ca; |
---|
1736 | 1701 | struct bucket *b; |
---|
1737 | | - unsigned int i; |
---|
1738 | 1702 | |
---|
1739 | 1703 | if (!c->gc_mark_valid) |
---|
1740 | 1704 | return; |
---|
.. | .. |
---|
1744 | 1708 | c->gc_mark_valid = 0; |
---|
1745 | 1709 | c->gc_done = ZERO_KEY; |
---|
1746 | 1710 | |
---|
1747 | | - for_each_cache(ca, c, i) |
---|
1748 | | - for_each_bucket(b, ca) { |
---|
1749 | | - b->last_gc = b->gen; |
---|
1750 | | - if (!atomic_read(&b->pin)) { |
---|
1751 | | - SET_GC_MARK(b, 0); |
---|
1752 | | - SET_GC_SECTORS_USED(b, 0); |
---|
1753 | | - } |
---|
| 1711 | + ca = c->cache; |
---|
| 1712 | + for_each_bucket(b, ca) { |
---|
| 1713 | + b->last_gc = b->gen; |
---|
| 1714 | + if (!atomic_read(&b->pin)) { |
---|
| 1715 | + SET_GC_MARK(b, 0); |
---|
| 1716 | + SET_GC_SECTORS_USED(b, 0); |
---|
1754 | 1717 | } |
---|
| 1718 | + } |
---|
1755 | 1719 | |
---|
1756 | 1720 | mutex_unlock(&c->bucket_lock); |
---|
1757 | 1721 | } |
---|
.. | .. |
---|
1760 | 1724 | { |
---|
1761 | 1725 | struct bucket *b; |
---|
1762 | 1726 | struct cache *ca; |
---|
1763 | | - unsigned int i; |
---|
| 1727 | + unsigned int i, j; |
---|
| 1728 | + uint64_t *k; |
---|
1764 | 1729 | |
---|
1765 | 1730 | mutex_lock(&c->bucket_lock); |
---|
1766 | 1731 | |
---|
.. | .. |
---|
1778 | 1743 | struct bcache_device *d = c->devices[i]; |
---|
1779 | 1744 | struct cached_dev *dc; |
---|
1780 | 1745 | struct keybuf_key *w, *n; |
---|
1781 | | - unsigned int j; |
---|
1782 | 1746 | |
---|
1783 | 1747 | if (!d || UUID_FLASH_ONLY(&c->uuids[i])) |
---|
1784 | 1748 | continue; |
---|
.. | .. |
---|
1795 | 1759 | rcu_read_unlock(); |
---|
1796 | 1760 | |
---|
1797 | 1761 | c->avail_nbuckets = 0; |
---|
1798 | | - for_each_cache(ca, c, i) { |
---|
1799 | | - uint64_t *i; |
---|
1800 | 1762 | |
---|
1801 | | - ca->invalidate_needs_gc = 0; |
---|
| 1763 | + ca = c->cache; |
---|
| 1764 | + ca->invalidate_needs_gc = 0; |
---|
1802 | 1765 | |
---|
1803 | | - for (i = ca->sb.d; i < ca->sb.d + ca->sb.keys; i++) |
---|
1804 | | - SET_GC_MARK(ca->buckets + *i, GC_MARK_METADATA); |
---|
| 1766 | + for (k = ca->sb.d; k < ca->sb.d + ca->sb.keys; k++) |
---|
| 1767 | + SET_GC_MARK(ca->buckets + *k, GC_MARK_METADATA); |
---|
1805 | 1768 | |
---|
1806 | | - for (i = ca->prio_buckets; |
---|
1807 | | - i < ca->prio_buckets + prio_buckets(ca) * 2; i++) |
---|
1808 | | - SET_GC_MARK(ca->buckets + *i, GC_MARK_METADATA); |
---|
| 1769 | + for (k = ca->prio_buckets; |
---|
| 1770 | + k < ca->prio_buckets + prio_buckets(ca) * 2; k++) |
---|
| 1771 | + SET_GC_MARK(ca->buckets + *k, GC_MARK_METADATA); |
---|
1809 | 1772 | |
---|
1810 | | - for_each_bucket(b, ca) { |
---|
1811 | | - c->need_gc = max(c->need_gc, bucket_gc_gen(b)); |
---|
| 1773 | + for_each_bucket(b, ca) { |
---|
| 1774 | + c->need_gc = max(c->need_gc, bucket_gc_gen(b)); |
---|
1812 | 1775 | |
---|
1813 | | - if (atomic_read(&b->pin)) |
---|
1814 | | - continue; |
---|
| 1776 | + if (atomic_read(&b->pin)) |
---|
| 1777 | + continue; |
---|
1815 | 1778 | |
---|
1816 | | - BUG_ON(!GC_MARK(b) && GC_SECTORS_USED(b)); |
---|
| 1779 | + BUG_ON(!GC_MARK(b) && GC_SECTORS_USED(b)); |
---|
1817 | 1780 | |
---|
1818 | | - if (!GC_MARK(b) || GC_MARK(b) == GC_MARK_RECLAIMABLE) |
---|
1819 | | - c->avail_nbuckets++; |
---|
1820 | | - } |
---|
| 1781 | + if (!GC_MARK(b) || GC_MARK(b) == GC_MARK_RECLAIMABLE) |
---|
| 1782 | + c->avail_nbuckets++; |
---|
1821 | 1783 | } |
---|
1822 | 1784 | |
---|
1823 | 1785 | mutex_unlock(&c->bucket_lock); |
---|
.. | .. |
---|
1841 | 1803 | |
---|
1842 | 1804 | /* if CACHE_SET_IO_DISABLE set, gc thread should stop too */ |
---|
1843 | 1805 | do { |
---|
1844 | | - ret = btree_root(gc_root, c, &op, &writes, &stats); |
---|
| 1806 | + ret = bcache_btree_root(gc_root, c, &op, &writes, &stats); |
---|
1845 | 1807 | closure_sync(&writes); |
---|
1846 | 1808 | cond_resched(); |
---|
1847 | 1809 | |
---|
.. | .. |
---|
1849 | 1811 | schedule_timeout_interruptible(msecs_to_jiffies |
---|
1850 | 1812 | (GC_SLEEP_MS)); |
---|
1851 | 1813 | else if (ret) |
---|
1852 | | - pr_warn("gc failed!"); |
---|
| 1814 | + pr_warn("gc failed!\n"); |
---|
1853 | 1815 | } while (ret && !test_bit(CACHE_SET_IO_DISABLE, &c->flags)); |
---|
1854 | 1816 | |
---|
1855 | 1817 | bch_btree_gc_finish(c); |
---|
.. | .. |
---|
1869 | 1831 | |
---|
1870 | 1832 | static bool gc_should_run(struct cache_set *c) |
---|
1871 | 1833 | { |
---|
1872 | | - struct cache *ca; |
---|
1873 | | - unsigned int i; |
---|
| 1834 | + struct cache *ca = c->cache; |
---|
1874 | 1835 | |
---|
1875 | | - for_each_cache(ca, c, i) |
---|
1876 | | - if (ca->invalidate_needs_gc) |
---|
1877 | | - return true; |
---|
| 1836 | + if (ca->invalidate_needs_gc) |
---|
| 1837 | + return true; |
---|
1878 | 1838 | |
---|
1879 | 1839 | if (atomic_read(&c->sectors_to_gc) < 0) |
---|
1880 | 1840 | return true; |
---|
.. | .. |
---|
1939 | 1899 | } |
---|
1940 | 1900 | |
---|
1941 | 1901 | if (p) |
---|
1942 | | - ret = btree(check_recurse, p, b, op); |
---|
| 1902 | + ret = bcache_btree(check_recurse, p, b, op); |
---|
1943 | 1903 | |
---|
1944 | 1904 | p = k; |
---|
1945 | 1905 | } while (p && !ret); |
---|
.. | .. |
---|
1948 | 1908 | return ret; |
---|
1949 | 1909 | } |
---|
1950 | 1910 | |
---|
| 1911 | + |
---|
| 1912 | +static int bch_btree_check_thread(void *arg) |
---|
| 1913 | +{ |
---|
| 1914 | + int ret; |
---|
| 1915 | + struct btree_check_info *info = arg; |
---|
| 1916 | + struct btree_check_state *check_state = info->state; |
---|
| 1917 | + struct cache_set *c = check_state->c; |
---|
| 1918 | + struct btree_iter iter; |
---|
| 1919 | + struct bkey *k, *p; |
---|
| 1920 | + int cur_idx, prev_idx, skip_nr; |
---|
| 1921 | + |
---|
| 1922 | + k = p = NULL; |
---|
| 1923 | + cur_idx = prev_idx = 0; |
---|
| 1924 | + ret = 0; |
---|
| 1925 | + |
---|
| 1926 | + /* root node keys are checked before thread created */ |
---|
| 1927 | + bch_btree_iter_init(&c->root->keys, &iter, NULL); |
---|
| 1928 | + k = bch_btree_iter_next_filter(&iter, &c->root->keys, bch_ptr_bad); |
---|
| 1929 | + BUG_ON(!k); |
---|
| 1930 | + |
---|
| 1931 | + p = k; |
---|
| 1932 | + while (k) { |
---|
| 1933 | + /* |
---|
| 1934 | + * Fetch a root node key index, skip the keys which |
---|
| 1935 | + * should be fetched by other threads, then check the |
---|
| 1936 | + * sub-tree indexed by the fetched key. |
---|
| 1937 | + */ |
---|
| 1938 | + spin_lock(&check_state->idx_lock); |
---|
| 1939 | + cur_idx = check_state->key_idx; |
---|
| 1940 | + check_state->key_idx++; |
---|
| 1941 | + spin_unlock(&check_state->idx_lock); |
---|
| 1942 | + |
---|
| 1943 | + skip_nr = cur_idx - prev_idx; |
---|
| 1944 | + |
---|
| 1945 | + while (skip_nr) { |
---|
| 1946 | + k = bch_btree_iter_next_filter(&iter, |
---|
| 1947 | + &c->root->keys, |
---|
| 1948 | + bch_ptr_bad); |
---|
| 1949 | + if (k) |
---|
| 1950 | + p = k; |
---|
| 1951 | + else { |
---|
| 1952 | + /* |
---|
| 1953 | + * No more keys to check in root node, |
---|
| 1954 | + * current checking threads are enough, |
---|
| 1955 | + * stop creating more. |
---|
| 1956 | + */ |
---|
| 1957 | + atomic_set(&check_state->enough, 1); |
---|
| 1958 | + /* Update check_state->enough earlier */ |
---|
| 1959 | + smp_mb__after_atomic(); |
---|
| 1960 | + goto out; |
---|
| 1961 | + } |
---|
| 1962 | + skip_nr--; |
---|
| 1963 | + cond_resched(); |
---|
| 1964 | + } |
---|
| 1965 | + |
---|
| 1966 | + if (p) { |
---|
| 1967 | + struct btree_op op; |
---|
| 1968 | + |
---|
| 1969 | + btree_node_prefetch(c->root, p); |
---|
| 1970 | + c->gc_stats.nodes++; |
---|
| 1971 | + bch_btree_op_init(&op, 0); |
---|
| 1972 | + ret = bcache_btree(check_recurse, p, c->root, &op); |
---|
| 1973 | + /* |
---|
| 1974 | + * The op may be added to cache_set's btree_cache_wait |
---|
| 1975 | + * in mca_cannibalize(), must ensure it is removed from |
---|
| 1976 | + * the list and release btree_cache_alloc_lock before |
---|
| 1977 | + * free op memory. |
---|
| 1978 | + * Otherwise, the btree_cache_wait will be damaged. |
---|
| 1979 | + */ |
---|
| 1980 | + bch_cannibalize_unlock(c); |
---|
| 1981 | + finish_wait(&c->btree_cache_wait, &(&op)->wait); |
---|
| 1982 | + if (ret) |
---|
| 1983 | + goto out; |
---|
| 1984 | + } |
---|
| 1985 | + p = NULL; |
---|
| 1986 | + prev_idx = cur_idx; |
---|
| 1987 | + cond_resched(); |
---|
| 1988 | + } |
---|
| 1989 | + |
---|
| 1990 | +out: |
---|
| 1991 | + info->result = ret; |
---|
| 1992 | + /* update check_state->started among all CPUs */ |
---|
| 1993 | + smp_mb__before_atomic(); |
---|
| 1994 | + if (atomic_dec_and_test(&check_state->started)) |
---|
| 1995 | + wake_up(&check_state->wait); |
---|
| 1996 | + |
---|
| 1997 | + return ret; |
---|
| 1998 | +} |
---|
| 1999 | + |
---|
| 2000 | + |
---|
| 2001 | + |
---|
| 2002 | +static int bch_btree_chkthread_nr(void) |
---|
| 2003 | +{ |
---|
| 2004 | + int n = num_online_cpus()/2; |
---|
| 2005 | + |
---|
| 2006 | + if (n == 0) |
---|
| 2007 | + n = 1; |
---|
| 2008 | + else if (n > BCH_BTR_CHKTHREAD_MAX) |
---|
| 2009 | + n = BCH_BTR_CHKTHREAD_MAX; |
---|
| 2010 | + |
---|
| 2011 | + return n; |
---|
| 2012 | +} |
---|
| 2013 | + |
---|
1951 | 2014 | int bch_btree_check(struct cache_set *c) |
---|
1952 | 2015 | { |
---|
1953 | | - struct btree_op op; |
---|
| 2016 | + int ret = 0; |
---|
| 2017 | + int i; |
---|
| 2018 | + struct bkey *k = NULL; |
---|
| 2019 | + struct btree_iter iter; |
---|
| 2020 | + struct btree_check_state check_state; |
---|
1954 | 2021 | |
---|
1955 | | - bch_btree_op_init(&op, SHRT_MAX); |
---|
| 2022 | + /* check and mark root node keys */ |
---|
| 2023 | + for_each_key_filter(&c->root->keys, k, &iter, bch_ptr_invalid) |
---|
| 2024 | + bch_initial_mark_key(c, c->root->level, k); |
---|
1956 | 2025 | |
---|
1957 | | - return btree_root(check_recurse, c, &op); |
---|
| 2026 | + bch_initial_mark_key(c, c->root->level + 1, &c->root->key); |
---|
| 2027 | + |
---|
| 2028 | + if (c->root->level == 0) |
---|
| 2029 | + return 0; |
---|
| 2030 | + |
---|
| 2031 | + memset(&check_state, 0, sizeof(struct btree_check_state)); |
---|
| 2032 | + check_state.c = c; |
---|
| 2033 | + check_state.total_threads = bch_btree_chkthread_nr(); |
---|
| 2034 | + check_state.key_idx = 0; |
---|
| 2035 | + spin_lock_init(&check_state.idx_lock); |
---|
| 2036 | + atomic_set(&check_state.started, 0); |
---|
| 2037 | + atomic_set(&check_state.enough, 0); |
---|
| 2038 | + init_waitqueue_head(&check_state.wait); |
---|
| 2039 | + |
---|
| 2040 | + rw_lock(0, c->root, c->root->level); |
---|
| 2041 | + /* |
---|
| 2042 | + * Run multiple threads to check btree nodes in parallel, |
---|
| 2043 | + * if check_state.enough is non-zero, it means current |
---|
| 2044 | + * running check threads are enough, unncessary to create |
---|
| 2045 | + * more. |
---|
| 2046 | + */ |
---|
| 2047 | + for (i = 0; i < check_state.total_threads; i++) { |
---|
| 2048 | + /* fetch latest check_state.enough earlier */ |
---|
| 2049 | + smp_mb__before_atomic(); |
---|
| 2050 | + if (atomic_read(&check_state.enough)) |
---|
| 2051 | + break; |
---|
| 2052 | + |
---|
| 2053 | + check_state.infos[i].result = 0; |
---|
| 2054 | + check_state.infos[i].state = &check_state; |
---|
| 2055 | + |
---|
| 2056 | + check_state.infos[i].thread = |
---|
| 2057 | + kthread_run(bch_btree_check_thread, |
---|
| 2058 | + &check_state.infos[i], |
---|
| 2059 | + "bch_btrchk[%d]", i); |
---|
| 2060 | + if (IS_ERR(check_state.infos[i].thread)) { |
---|
| 2061 | + pr_err("fails to run thread bch_btrchk[%d]\n", i); |
---|
| 2062 | + for (--i; i >= 0; i--) |
---|
| 2063 | + kthread_stop(check_state.infos[i].thread); |
---|
| 2064 | + ret = -ENOMEM; |
---|
| 2065 | + goto out; |
---|
| 2066 | + } |
---|
| 2067 | + atomic_inc(&check_state.started); |
---|
| 2068 | + } |
---|
| 2069 | + |
---|
| 2070 | + /* |
---|
| 2071 | + * Must wait for all threads to stop. |
---|
| 2072 | + */ |
---|
| 2073 | + wait_event(check_state.wait, atomic_read(&check_state.started) == 0); |
---|
| 2074 | + |
---|
| 2075 | + for (i = 0; i < check_state.total_threads; i++) { |
---|
| 2076 | + if (check_state.infos[i].result) { |
---|
| 2077 | + ret = check_state.infos[i].result; |
---|
| 2078 | + goto out; |
---|
| 2079 | + } |
---|
| 2080 | + } |
---|
| 2081 | + |
---|
| 2082 | +out: |
---|
| 2083 | + rw_unlock(0, c->root); |
---|
| 2084 | + return ret; |
---|
1958 | 2085 | } |
---|
1959 | 2086 | |
---|
1960 | 2087 | void bch_initial_gc_finish(struct cache_set *c) |
---|
1961 | 2088 | { |
---|
1962 | | - struct cache *ca; |
---|
| 2089 | + struct cache *ca = c->cache; |
---|
1963 | 2090 | struct bucket *b; |
---|
1964 | | - unsigned int i; |
---|
1965 | 2091 | |
---|
1966 | 2092 | bch_btree_gc_finish(c); |
---|
1967 | 2093 | |
---|
.. | .. |
---|
1976 | 2102 | * This is only safe for buckets that have no live data in them, which |
---|
1977 | 2103 | * there should always be some of. |
---|
1978 | 2104 | */ |
---|
1979 | | - for_each_cache(ca, c, i) { |
---|
1980 | | - for_each_bucket(b, ca) { |
---|
1981 | | - if (fifo_full(&ca->free[RESERVE_PRIO]) && |
---|
1982 | | - fifo_full(&ca->free[RESERVE_BTREE])) |
---|
1983 | | - break; |
---|
| 2105 | + for_each_bucket(b, ca) { |
---|
| 2106 | + if (fifo_full(&ca->free[RESERVE_PRIO]) && |
---|
| 2107 | + fifo_full(&ca->free[RESERVE_BTREE])) |
---|
| 2108 | + break; |
---|
1984 | 2109 | |
---|
1985 | | - if (bch_can_invalidate_bucket(ca, b) && |
---|
1986 | | - !GC_MARK(b)) { |
---|
1987 | | - __bch_invalidate_one_bucket(ca, b); |
---|
1988 | | - if (!fifo_push(&ca->free[RESERVE_PRIO], |
---|
1989 | | - b - ca->buckets)) |
---|
1990 | | - fifo_push(&ca->free[RESERVE_BTREE], |
---|
1991 | | - b - ca->buckets); |
---|
1992 | | - } |
---|
| 2110 | + if (bch_can_invalidate_bucket(ca, b) && |
---|
| 2111 | + !GC_MARK(b)) { |
---|
| 2112 | + __bch_invalidate_one_bucket(ca, b); |
---|
| 2113 | + if (!fifo_push(&ca->free[RESERVE_PRIO], |
---|
| 2114 | + b - ca->buckets)) |
---|
| 2115 | + fifo_push(&ca->free[RESERVE_BTREE], |
---|
| 2116 | + b - ca->buckets); |
---|
1993 | 2117 | } |
---|
1994 | 2118 | } |
---|
1995 | 2119 | |
---|
.. | .. |
---|
2097 | 2221 | goto err; |
---|
2098 | 2222 | |
---|
2099 | 2223 | split = set_blocks(btree_bset_first(n1), |
---|
2100 | | - block_bytes(n1->c)) > (btree_blocks(b) * 4) / 5; |
---|
| 2224 | + block_bytes(n1->c->cache)) > (btree_blocks(b) * 4) / 5; |
---|
2101 | 2225 | |
---|
2102 | 2226 | if (split) { |
---|
2103 | 2227 | unsigned int keys = 0; |
---|
.. | .. |
---|
2344 | 2468 | if (ret) { |
---|
2345 | 2469 | struct bkey *k; |
---|
2346 | 2470 | |
---|
2347 | | - pr_err("error %i", ret); |
---|
| 2471 | + pr_err("error %i\n", ret); |
---|
2348 | 2472 | |
---|
2349 | 2473 | while ((k = bch_keylist_pop(keys))) |
---|
2350 | 2474 | bkey_put(c, k); |
---|
.. | .. |
---|
2394 | 2518 | |
---|
2395 | 2519 | while ((k = bch_btree_iter_next_filter(&iter, &b->keys, |
---|
2396 | 2520 | bch_ptr_bad))) { |
---|
2397 | | - ret = btree(map_nodes_recurse, k, b, |
---|
| 2521 | + ret = bcache_btree(map_nodes_recurse, k, b, |
---|
2398 | 2522 | op, from, fn, flags); |
---|
2399 | 2523 | from = NULL; |
---|
2400 | 2524 | |
---|
.. | .. |
---|
2412 | 2536 | int __bch_btree_map_nodes(struct btree_op *op, struct cache_set *c, |
---|
2413 | 2537 | struct bkey *from, btree_map_nodes_fn *fn, int flags) |
---|
2414 | 2538 | { |
---|
2415 | | - return btree_root(map_nodes_recurse, c, op, from, fn, flags); |
---|
| 2539 | + return bcache_btree_root(map_nodes_recurse, c, op, from, fn, flags); |
---|
2416 | 2540 | } |
---|
2417 | 2541 | |
---|
2418 | | -static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op, |
---|
| 2542 | +int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op, |
---|
2419 | 2543 | struct bkey *from, btree_map_keys_fn *fn, |
---|
2420 | 2544 | int flags) |
---|
2421 | 2545 | { |
---|
.. | .. |
---|
2428 | 2552 | while ((k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad))) { |
---|
2429 | 2553 | ret = !b->level |
---|
2430 | 2554 | ? fn(op, b, k) |
---|
2431 | | - : btree(map_keys_recurse, k, b, op, from, fn, flags); |
---|
| 2555 | + : bcache_btree(map_keys_recurse, k, |
---|
| 2556 | + b, op, from, fn, flags); |
---|
2432 | 2557 | from = NULL; |
---|
2433 | 2558 | |
---|
2434 | 2559 | if (ret != MAP_CONTINUE) |
---|
.. | .. |
---|
2445 | 2570 | int bch_btree_map_keys(struct btree_op *op, struct cache_set *c, |
---|
2446 | 2571 | struct bkey *from, btree_map_keys_fn *fn, int flags) |
---|
2447 | 2572 | { |
---|
2448 | | - return btree_root(map_keys_recurse, c, op, from, fn, flags); |
---|
| 2573 | + return bcache_btree_root(map_keys_recurse, c, op, from, fn, flags); |
---|
2449 | 2574 | } |
---|
2450 | 2575 | |
---|
2451 | 2576 | /* Keybuf code */ |
---|
.. | .. |
---|
2631 | 2756 | break; |
---|
2632 | 2757 | |
---|
2633 | 2758 | if (bkey_cmp(&buf->last_scanned, end) >= 0) { |
---|
2634 | | - pr_debug("scan finished"); |
---|
| 2759 | + pr_debug("scan finished\n"); |
---|
2635 | 2760 | break; |
---|
2636 | 2761 | } |
---|
2637 | 2762 | |
---|
.. | .. |
---|
2649 | 2774 | spin_lock_init(&buf->lock); |
---|
2650 | 2775 | array_allocator_init(&buf->freelist); |
---|
2651 | 2776 | } |
---|
| 2777 | + |
---|
| 2778 | +void bch_btree_exit(void) |
---|
| 2779 | +{ |
---|
| 2780 | + if (btree_io_wq) |
---|
| 2781 | + destroy_workqueue(btree_io_wq); |
---|
| 2782 | +} |
---|
| 2783 | + |
---|
| 2784 | +int __init bch_btree_init(void) |
---|
| 2785 | +{ |
---|
| 2786 | + btree_io_wq = alloc_workqueue("bch_btree_io", WQ_MEM_RECLAIM, 0); |
---|
| 2787 | + if (!btree_io_wq) |
---|
| 2788 | + return -ENOMEM; |
---|
| 2789 | + |
---|
| 2790 | + return 0; |
---|
| 2791 | +} |
---|