btree.c (c052dd9a26f60bcf70c0c3fcc08e07abb60295cd) btree.c (dc9d98d621bdce0552997200ce855659875a5c9f)
1/*
2 * Copyright (C) 2010 Kent Overstreet <kent.overstreet@gmail.com>
3 *
4 * Uses a block device as cache for other block devices; optimized for SSDs.
5 * All allocation is done in buckets, which should match the erase block size
6 * of the device.
7 *
8 * Buckets containing cached data are kept on a heap sorted by priority;

--- 446 unchanged lines hidden (view full) ---

455 struct bset *i = btree_bset_last(b);
456
457 trace_bcache_btree_write(b);
458
459 BUG_ON(current->bio_list);
460 BUG_ON(b->written >= btree_blocks(b));
461 BUG_ON(b->written && !i->keys);
462 BUG_ON(btree_bset_first(b)->seq != i->seq);
1/*
2 * Copyright (C) 2010 Kent Overstreet <kent.overstreet@gmail.com>
3 *
4 * Uses a block device as cache for other block devices; optimized for SSDs.
5 * All allocation is done in buckets, which should match the erase block size
6 * of the device.
7 *
8 * Buckets containing cached data are kept on a heap sorted by priority;

--- 446 unchanged lines hidden (view full) ---

455 struct bset *i = btree_bset_last(b);
456
457 trace_bcache_btree_write(b);
458
459 BUG_ON(current->bio_list);
460 BUG_ON(b->written >= btree_blocks(b));
461 BUG_ON(b->written && !i->keys);
462 BUG_ON(btree_bset_first(b)->seq != i->seq);
463 bch_check_keys(b, "writing");
463 bch_check_keys(&b->keys, "writing");
464
465 cancel_delayed_work(&b->work);
466
467 /* If caller isn't waiting for write, parent refcount is cache set */
468 down(&b->io_mutex);
469 closure_init(&b->io, parent ?: &b->c->cl);
470
471 clear_bit(BTREE_NODE_dirty, &b->flags);

--- 1530 unchanged lines hidden (view full) ---

2002 } else {
2003 BUG_ON(replace_key);
2004 m = bch_bset_search(&b->keys, bset_tree_last(&b->keys), k);
2005 }
2006
2007insert: bch_bset_insert(&b->keys, m, k);
2008copy: bkey_copy(m, k);
2009merged:
464
465 cancel_delayed_work(&b->work);
466
467 /* If caller isn't waiting for write, parent refcount is cache set */
468 down(&b->io_mutex);
469 closure_init(&b->io, parent ?: &b->c->cl);
470
471 clear_bit(BTREE_NODE_dirty, &b->flags);

--- 1530 unchanged lines hidden (view full) ---

2002 } else {
2003 BUG_ON(replace_key);
2004 m = bch_bset_search(&b->keys, bset_tree_last(&b->keys), k);
2005 }
2006
2007insert: bch_bset_insert(&b->keys, m, k);
2008copy: bkey_copy(m, k);
2009merged:
2010 bch_check_keys(b, "%u for %s", status,
2010 bch_check_keys(&b->keys, "%u for %s", status,
2011 replace_key ? "replace" : "insert");
2012
2013 if (b->level && !KEY_OFFSET(k))
2014 btree_current_write(b)->prio_blocked++;
2015
2016 trace_bcache_btree_insert_key(b, k, replace_key != NULL, status);
2017
2018 return true;

--- 12 unchanged lines hidden (view full) ---

2031 return max(ret, 0L);
2032}
2033
2034static bool bch_btree_insert_keys(struct btree *b, struct btree_op *op,
2035 struct keylist *insert_keys,
2036 struct bkey *replace_key)
2037{
2038 bool ret = false;
2011 replace_key ? "replace" : "insert");
2012
2013 if (b->level && !KEY_OFFSET(k))
2014 btree_current_write(b)->prio_blocked++;
2015
2016 trace_bcache_btree_insert_key(b, k, replace_key != NULL, status);
2017
2018 return true;

--- 12 unchanged lines hidden (view full) ---

2031 return max(ret, 0L);
2032}
2033
2034static bool bch_btree_insert_keys(struct btree *b, struct btree_op *op,
2035 struct keylist *insert_keys,
2036 struct bkey *replace_key)
2037{
2038 bool ret = false;
2039 int oldsize = bch_count_data(b);
2039 int oldsize = bch_count_data(&b->keys);
2040
2041 while (!bch_keylist_empty(insert_keys)) {
2042 struct bkey *k = insert_keys->keys;
2043
2044 if (bkey_u64s(k) > insert_u64s_remaining(b))
2045 break;
2046
2047 if (bkey_cmp(k, &b->key) <= 0) {

--- 13 unchanged lines hidden (view full) ---

2061 break;
2062 } else {
2063 break;
2064 }
2065 }
2066
2067 BUG_ON(!bch_keylist_empty(insert_keys) && b->level);
2068
2040
2041 while (!bch_keylist_empty(insert_keys)) {
2042 struct bkey *k = insert_keys->keys;
2043
2044 if (bkey_u64s(k) > insert_u64s_remaining(b))
2045 break;
2046
2047 if (bkey_cmp(k, &b->key) <= 0) {

--- 13 unchanged lines hidden (view full) ---

2061 break;
2062 } else {
2063 break;
2064 }
2065 }
2066
2067 BUG_ON(!bch_keylist_empty(insert_keys) && b->level);
2068
2069 BUG_ON(bch_count_data(b) < oldsize);
2069 BUG_ON(bch_count_data(&b->keys) < oldsize);
2070 return ret;
2071}
2072
2073static int btree_split(struct btree *b, struct btree_op *op,
2074 struct keylist *insert_keys,
2075 struct bkey *replace_key)
2076{
2077 bool split;

--- 553 unchanged lines hidden ---
2070 return ret;
2071}
2072
2073static int btree_split(struct btree *b, struct btree_op *op,
2074 struct keylist *insert_keys,
2075 struct bkey *replace_key)
2076{
2077 bool split;

--- 553 unchanged lines hidden ---