Lines Matching refs:k
93 #define PTR_HASH(c, k) \ argument
94 (((k)->ptr[0] >> c->bucket_bits) | PTR_GEN(k, 0))
178 void bkey_put(struct cache_set *c, struct bkey *k) in bkey_put() argument
182 for (i = 0; i < KEY_PTRS(k); i++) in bkey_put()
183 if (ptr_available(c, k, i)) in bkey_put()
184 atomic_dec_bug(&PTR_BUCKET(c, k, i)->pin); in bkey_put()
390 BKEY_PADDED(key) k; in do_btree_node_write()
419 bkey_copy(&k.key, &b->key); in do_btree_node_write()
420 SET_PTR_OFFSET(&k.key, 0, PTR_OFFSET(&k.key, 0) + in do_btree_node_write()
432 bch_submit_bbio(b->bio, b->c, &k.key, 0); in do_btree_node_write()
439 bch_submit_bbio(b->bio, b->c, &k.key, 0); in do_btree_node_write()
581 static unsigned btree_order(struct bkey *k) in btree_order() argument
583 return ilog2(KEY_SIZE(k) / PAGE_SECTORS ?: 1); in btree_order()
586 static void mca_data_alloc(struct btree *b, struct bkey *k, gfp_t gfp) in mca_data_alloc() argument
591 btree_order(k)), in mca_data_alloc()
601 struct bkey *k, gfp_t gfp) in mca_bucket_alloc() argument
616 mca_data_alloc(b, k, gfp); in mca_bucket_alloc()
821 static struct hlist_head *mca_hash(struct cache_set *c, struct bkey *k) in mca_hash() argument
823 return &c->bucket_hash[hash_32(PTR_HASH(c, k), BUCKET_HASH_BITS)]; in mca_hash()
826 static struct btree *mca_find(struct cache_set *c, struct bkey *k) in mca_find() argument
831 hlist_for_each_entry_rcu(b, mca_hash(c, k), hash) in mca_find()
832 if (PTR_HASH(c, &b->key) == PTR_HASH(c, k)) in mca_find()
856 struct bkey *k) in mca_cannibalize() argument
866 if (!mca_reap(b, btree_order(k), false)) in mca_cannibalize()
870 if (!mca_reap(b, btree_order(k), true)) in mca_cannibalize()
892 struct bkey *k, int level) in mca_alloc() argument
900 if (mca_find(c, k)) in mca_alloc()
907 if (!mca_reap(b, btree_order(k), false)) in mca_alloc()
915 mca_data_alloc(b, k, __GFP_NOWARN|GFP_NOIO); in mca_alloc()
922 b = mca_bucket_alloc(c, k, __GFP_NOWARN|GFP_NOIO); in mca_alloc()
932 bkey_copy(&b->key, k); in mca_alloc()
935 hlist_add_head_rcu(&b->hash, mca_hash(c, k)); in mca_alloc()
955 b = mca_cannibalize(c, op, k); in mca_alloc()
972 struct bkey *k, int level, bool write, in bch_btree_node_get() argument
980 b = mca_find(c, k); in bch_btree_node_get()
987 b = mca_alloc(c, op, k, level); in bch_btree_node_get()
1001 if (PTR_HASH(c, &b->key) != PTR_HASH(c, k)) { in bch_btree_node_get()
1029 static void btree_node_prefetch(struct btree *parent, struct bkey *k) in btree_node_prefetch() argument
1034 b = mca_alloc(parent->c, NULL, k, parent->level - 1); in btree_node_prefetch()
1072 BKEY_PADDED(key) k; in __bch_btree_node_alloc()
1077 if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, wait)) in __bch_btree_node_alloc()
1080 bkey_put(c, &k.key); in __bch_btree_node_alloc()
1081 SET_KEY_SIZE(&k.key, c->btree_pages * PAGE_SECTORS); in __bch_btree_node_alloc()
1083 b = mca_alloc(c, op, &k.key, level); in __bch_btree_node_alloc()
1102 bch_bucket_free(c, &k.key); in __bch_btree_node_alloc()
1131 static void make_btree_freeing_key(struct btree *b, struct bkey *k) in make_btree_freeing_key() argument
1139 bkey_copy(k, &b->key); in make_btree_freeing_key()
1140 bkey_copy_key(k, &ZERO_KEY); in make_btree_freeing_key()
1142 for (i = 0; i < KEY_PTRS(k); i++) in make_btree_freeing_key()
1143 SET_PTR_GEN(k, i, in make_btree_freeing_key()
1175 struct bkey *k) in __bch_btree_mark_key() argument
1186 if (!bkey_cmp(k, &ZERO_KEY)) in __bch_btree_mark_key()
1189 for (i = 0; i < KEY_PTRS(k); i++) { in __bch_btree_mark_key()
1190 if (!ptr_available(c, k, i)) in __bch_btree_mark_key()
1193 g = PTR_BUCKET(c, k, i); in __bch_btree_mark_key()
1195 if (gen_after(g->last_gc, PTR_GEN(k, i))) in __bch_btree_mark_key()
1196 g->last_gc = PTR_GEN(k, i); in __bch_btree_mark_key()
1198 if (ptr_stale(c, k, i)) { in __bch_btree_mark_key()
1199 stale = max(stale, ptr_stale(c, k, i)); in __bch_btree_mark_key()
1210 else if (KEY_DIRTY(k)) in __bch_btree_mark_key()
1217 GC_SECTORS_USED(g) + KEY_SIZE(k), in __bch_btree_mark_key()
1226 #define btree_mark_key(b, k) __bch_btree_mark_key(b->c, b->level, k) argument
1228 void bch_initial_mark_key(struct cache_set *c, int level, struct bkey *k) in bch_initial_mark_key() argument
1232 for (i = 0; i < KEY_PTRS(k); i++) in bch_initial_mark_key()
1233 if (ptr_available(c, k, i) && in bch_initial_mark_key()
1234 !ptr_stale(c, k, i)) { in bch_initial_mark_key()
1235 struct bucket *b = PTR_BUCKET(c, k, i); in bch_initial_mark_key()
1237 b->gen = PTR_GEN(k, i); in bch_initial_mark_key()
1239 if (level && bkey_cmp(k, &ZERO_KEY)) in bch_initial_mark_key()
1245 __bch_btree_mark_key(c, level, k); in bch_initial_mark_key()
1252 struct bkey *k; in btree_gc_mark_node() local
1258 for_each_key_filter(&b->keys, k, &iter, bch_ptr_invalid) { in btree_gc_mark_node()
1259 stale = max(stale, btree_mark_key(b, k)); in btree_gc_mark_node()
1262 if (bch_ptr_bad(&b->keys, k)) in btree_gc_mark_node()
1265 gc->key_bytes += bkey_u64s(k); in btree_gc_mark_node()
1269 gc->data += KEY_SIZE(k); in btree_gc_mark_node()
1307 struct bkey *k; in btree_gc_coalesce() local
1348 struct bkey *k, *last = NULL; in btree_gc_coalesce() local
1353 for (k = n2->start; in btree_gc_coalesce()
1354 k < bset_bkey_last(n2); in btree_gc_coalesce()
1355 k = bkey_next(k)) { in btree_gc_coalesce()
1357 bkey_u64s(k), in btree_gc_coalesce()
1361 last = k; in btree_gc_coalesce()
1362 keys += bkey_u64s(k); in btree_gc_coalesce()
1455 while ((k = bch_keylist_pop(&keylist))) in btree_gc_coalesce()
1456 if (!bkey_cmp(k, &ZERO_KEY)) in btree_gc_coalesce()
1505 struct bkey *k; in btree_gc_count_keys() local
1509 for_each_key_filter(&b->keys, k, &iter, bch_ptr_bad) in btree_gc_count_keys()
1510 ret += bkey_u64s(k); in btree_gc_count_keys()
1520 struct bkey *k; in btree_gc_recurse() local
1531 k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad); in btree_gc_recurse()
1532 if (k) { in btree_gc_recurse()
1533 r->b = bch_btree_node_get(b->c, op, k, b->level - 1, in btree_gc_recurse()
1815 struct bkey *k, *p = NULL; in bch_btree_check_recurse() local
1818 for_each_key_filter(&b->keys, k, &iter, bch_ptr_invalid) in bch_btree_check_recurse()
1819 bch_initial_mark_key(b->c, b->level, k); in bch_btree_check_recurse()
1827 k = bch_btree_iter_next_filter(&iter, &b->keys, in bch_btree_check_recurse()
1829 if (k) in bch_btree_check_recurse()
1830 btree_node_prefetch(b, k); in bch_btree_check_recurse()
1835 p = k; in bch_btree_check_recurse()
1889 static bool btree_insert_key(struct btree *b, struct bkey *k, in btree_insert_key() argument
1894 BUG_ON(bkey_cmp(k, &b->key) > 0); in btree_insert_key()
1896 status = bch_btree_insert_key(&b->keys, k, replace_key); in btree_insert_key()
1901 trace_bcache_btree_insert_key(b, k, replace_key != NULL, in btree_insert_key()
1929 struct bkey *k = insert_keys->keys; in bch_btree_insert_keys() local
1931 if (bkey_u64s(k) > insert_u64s_remaining(b)) in bch_btree_insert_keys()
1934 if (bkey_cmp(k, &b->key) <= 0) { in bch_btree_insert_keys()
1936 bkey_put(b->c, k); in bch_btree_insert_keys()
1938 ret |= btree_insert_key(b, k, replace_key); in bch_btree_insert_keys()
1940 } else if (bkey_cmp(&START_KEY(k), &b->key) < 0) { in bch_btree_insert_keys()
2233 struct bkey *k; in bch_btree_insert() local
2237 while ((k = bch_keylist_pop(keys))) in bch_btree_insert()
2238 bkey_put(c, k); in bch_btree_insert()
2278 struct bkey *k; in bch_btree_map_nodes_recurse() local
2283 while ((k = bch_btree_iter_next_filter(&iter, &b->keys, in bch_btree_map_nodes_recurse()
2285 ret = btree(map_nodes_recurse, k, b, in bch_btree_map_nodes_recurse()
2311 struct bkey *k; in bch_btree_map_keys_recurse() local
2316 while ((k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad))) { in bch_btree_map_keys_recurse()
2318 ? fn(op, b, k) in bch_btree_map_keys_recurse()
2319 : btree(map_keys_recurse, k, b, op, from, fn, flags); in bch_btree_map_keys_recurse()
2366 struct bkey *k) in refill_keybuf_fn() argument
2372 if (bkey_cmp(k, refill->end) >= 0) { in refill_keybuf_fn()
2377 if (!KEY_SIZE(k)) /* end key */ in refill_keybuf_fn()
2380 if (refill->pred(buf, k)) { in refill_keybuf_fn()
2392 bkey_copy(&w->key, k); in refill_keybuf_fn()
2405 buf->last_scanned = *k; in refill_keybuf_fn()