summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/md/bcache/bset.c39
-rw-r--r--drivers/md/bcache/bset.h11
-rw-r--r--drivers/md/bcache/gc.c2
3 files changed, 22 insertions, 30 deletions
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index a3fc6973cf8a..709de4ccf148 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -78,6 +78,18 @@ s64 bch_count_data(struct btree_keys *b)
return ret;
}
+void bch_verify_nr_live_u64s(struct btree_keys *b)
+{
+ struct bkey *k;
+ struct btree_node_iter iter;
+ size_t u64s = 0;
+
+ for_each_btree_node_key(b, k, &iter)
+ u64s += k->u64s;
+
+ BUG_ON(b->nr_live_u64s != u64s);
+}
+
#endif
/* Auxiliary search trees */
@@ -1155,21 +1167,6 @@ EXPORT_SYMBOL(bch_btree_node_iter_next_all);
/* Mergesort */
-/**
- * btree_count_keys - count live keys in a btree node
- */
-size_t bch_btree_count_u64s(struct btree_keys *b)
-{
- struct bkey *k;
- struct btree_node_iter iter;
- size_t ret = 0;
-
- for_each_btree_node_key(b, k, &iter)
- ret += k->u64s;
-
- return ret;
-}
-
void bch_bset_sort_state_free(struct bset_sort_state *state)
{
if (state->pool)
@@ -1279,12 +1276,14 @@ static void __btree_sort(struct btree_keys *b, struct btree_node_iter *iter,
bch_bset_build_written_tree(b);
- /* sort can merge keys - need to recalculate */
- b->nr_live_u64s = start
- ? bch_btree_count_u64s(b)
- : b->set->data->u64s;
+ /*
+ * sort can merge keys, but we only merge only if it was a full sort -
+ * and if it was a full sort we dropped all the deleted keys
+ */
+ if (!start)
+ b->nr_live_u64s = b->set->data->u64s;
- verify_nr_live_u64s(b);
+ bch_verify_nr_live_u64s(b);
if (!start)
bch_time_stats_update(&state->time, start_time);
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h
index 74112cb57959..9bf7fa4a311c 100644
--- a/drivers/md/bcache/bset.h
+++ b/drivers/md/bcache/bset.h
@@ -503,15 +503,6 @@ struct bset_stats {
void bch_btree_keys_stats(struct btree_keys *, struct bset_stats *);
-size_t bch_btree_count_u64s(struct btree_keys *);
-
-static inline void verify_nr_live_u64s(struct btree_keys *b)
-{
-#ifdef CONFIG_BCACHE_DEBUG
- BUG_ON(b->nr_live_u64s != bch_btree_count_u64s(b));
-#endif
-}
-
/* Debug stuff */
#ifdef CONFIG_BCACHE_DEBUG
@@ -519,6 +510,7 @@ static inline void verify_nr_live_u64s(struct btree_keys *b)
s64 bch_count_data(struct btree_keys *);
void bch_dump_bucket(struct btree_keys *);
void bch_btree_node_iter_verify(struct btree_keys *, struct btree_node_iter *);
+void bch_verify_nr_live_u64s(struct btree_keys *);
#else
@@ -526,6 +518,7 @@ static inline s64 bch_count_data(struct btree_keys *b) { return -1; }
static inline void bch_dump_bucket(struct btree_keys *b) {}
static inline void bch_btree_node_iter_verify(struct btree_keys *b,
struct btree_node_iter *iter) {}
+static inline void bch_verify_nr_live_u64s(struct btree_keys *b) {}
#endif
diff --git a/drivers/md/bcache/gc.c b/drivers/md/bcache/gc.c
index eecac85bfe47..9b418371d31d 100644
--- a/drivers/md/bcache/gc.c
+++ b/drivers/md/bcache/gc.c
@@ -343,7 +343,7 @@ static int bch_gc_btree(struct cache_set *c, enum btree_id btree_id,
for (b = bch_btree_iter_peek_node(&iter);
b;
b = bch_btree_iter_next_node(&iter)) {
- verify_nr_live_u64s(&b->keys);
+ bch_verify_nr_live_u64s(&b->keys);
should_rewrite = btree_gc_mark_node(c, b, stat);