diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-11-11 21:38:51 -0500 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2014-01-08 16:05:13 -0500 |
commit | 89ebb4a28ba9efb5c9b18ba552e784021957b14a (patch) | |
tree | 7f649258fe76af99c63cb81c421c704a418abfe9 /drivers/md | |
parent | dc9d98d621bdce0552997200ce855659875a5c9f (diff) |
bcache: Convert sorting to btree_keys
More work to disentangle various code from struct btree
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/bcache/bset.c | 50 | ||||
-rw-r--r-- | drivers/md/bcache/bset.h | 13 | ||||
-rw-r--r-- | drivers/md/bcache/btree.c | 6 |
3 files changed, 33 insertions, 36 deletions
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c index 448cff8cc052..2ff75f3199fa 100644 --- a/drivers/md/bcache/bset.c +++ b/drivers/md/bcache/bset.c | |||
@@ -5,8 +5,10 @@ | |||
5 | * Copyright 2012 Google, Inc. | 5 | * Copyright 2012 Google, Inc. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include "bcache.h" | 8 | #define pr_fmt(fmt) "bcache: %s() " fmt "\n", __func__ |
9 | #include "btree.h" | 9 | |
10 | #include "util.h" | ||
11 | #include "bset.h" | ||
10 | 12 | ||
11 | #include <linux/console.h> | 13 | #include <linux/console.h> |
12 | #include <linux/random.h> | 14 | #include <linux/random.h> |
@@ -1150,31 +1152,27 @@ static void __btree_sort(struct btree_keys *b, struct btree_iter *iter, | |||
1150 | bch_time_stats_update(&state->time, start_time); | 1152 | bch_time_stats_update(&state->time, start_time); |
1151 | } | 1153 | } |
1152 | 1154 | ||
1153 | void bch_btree_sort_partial(struct btree *b, unsigned start, | 1155 | void bch_btree_sort_partial(struct btree_keys *b, unsigned start, |
1154 | struct bset_sort_state *state) | 1156 | struct bset_sort_state *state) |
1155 | { | 1157 | { |
1156 | size_t order = b->keys.page_order, keys = 0; | 1158 | size_t order = b->page_order, keys = 0; |
1157 | struct btree_iter iter; | 1159 | struct btree_iter iter; |
1158 | int oldsize = bch_count_data(&b->keys); | 1160 | int oldsize = bch_count_data(b); |
1159 | 1161 | ||
1160 | __bch_btree_iter_init(&b->keys, &iter, NULL, &b->keys.set[start]); | 1162 | __bch_btree_iter_init(b, &iter, NULL, &b->set[start]); |
1161 | 1163 | ||
1162 | if (start) { | 1164 | if (start) { |
1163 | unsigned i; | 1165 | unsigned i; |
1164 | 1166 | ||
1165 | for (i = start; i <= b->keys.nsets; i++) | 1167 | for (i = start; i <= b->nsets; i++) |
1166 | keys += b->keys.set[i].data->keys; | 1168 | keys += b->set[i].data->keys; |
1167 | 1169 | ||
1168 | order = roundup_pow_of_two(__set_bytes(b->keys.set->data, | 1170 | order = get_order(__set_bytes(b->set->data, keys)); |
1169 | keys)) / PAGE_SIZE; | ||
1170 | if (order) | ||
1171 | order = ilog2(order); | ||
1172 | } | 1171 | } |
1173 | 1172 | ||
1174 | __btree_sort(&b->keys, &iter, start, order, false, state); | 1173 | __btree_sort(b, &iter, start, order, false, state); |
1175 | 1174 | ||
1176 | EBUG_ON(b->written && oldsize >= 0 && | 1175 | EBUG_ON(oldsize >= 0 && bch_count_data(b) != oldsize); |
1177 | bch_count_data(&b->keys) != oldsize); | ||
1178 | } | 1176 | } |
1179 | EXPORT_SYMBOL(bch_btree_sort_partial); | 1177 | EXPORT_SYMBOL(bch_btree_sort_partial); |
1180 | 1178 | ||
@@ -1185,51 +1183,49 @@ void bch_btree_sort_and_fix_extents(struct btree_keys *b, | |||
1185 | __btree_sort(b, iter, 0, b->page_order, true, state); | 1183 | __btree_sort(b, iter, 0, b->page_order, true, state); |
1186 | } | 1184 | } |
1187 | 1185 | ||
1188 | void bch_btree_sort_into(struct btree *b, struct btree *new, | 1186 | void bch_btree_sort_into(struct btree_keys *b, struct btree_keys *new, |
1189 | struct bset_sort_state *state) | 1187 | struct bset_sort_state *state) |
1190 | { | 1188 | { |
1191 | uint64_t start_time = local_clock(); | 1189 | uint64_t start_time = local_clock(); |
1192 | 1190 | ||
1193 | struct btree_iter iter; | 1191 | struct btree_iter iter; |
1194 | bch_btree_iter_init(&b->keys, &iter, NULL); | 1192 | bch_btree_iter_init(b, &iter, NULL); |
1195 | 1193 | ||
1196 | btree_mergesort(&b->keys, new->keys.set->data, &iter, false, true); | 1194 | btree_mergesort(b, new->set->data, &iter, false, true); |
1197 | 1195 | ||
1198 | bch_time_stats_update(&state->time, start_time); | 1196 | bch_time_stats_update(&state->time, start_time); |
1199 | 1197 | ||
1200 | new->keys.set->size = 0; // XXX: why? | 1198 | new->set->size = 0; // XXX: why? |
1201 | } | 1199 | } |
1202 | 1200 | ||
1203 | #define SORT_CRIT (4096 / sizeof(uint64_t)) | 1201 | #define SORT_CRIT (4096 / sizeof(uint64_t)) |
1204 | 1202 | ||
1205 | void bch_btree_sort_lazy(struct btree *b, struct bset_sort_state *state) | 1203 | void bch_btree_sort_lazy(struct btree_keys *b, struct bset_sort_state *state) |
1206 | { | 1204 | { |
1207 | unsigned crit = SORT_CRIT; | 1205 | unsigned crit = SORT_CRIT; |
1208 | int i; | 1206 | int i; |
1209 | 1207 | ||
1210 | b->keys.last_set_unwritten = 0; | ||
1211 | |||
1212 | /* Don't sort if nothing to do */ | 1208 | /* Don't sort if nothing to do */ |
1213 | if (!b->keys.nsets) | 1209 | if (!b->nsets) |
1214 | goto out; | 1210 | goto out; |
1215 | 1211 | ||
1216 | for (i = b->keys.nsets - 1; i >= 0; --i) { | 1212 | for (i = b->nsets - 1; i >= 0; --i) { |
1217 | crit *= state->crit_factor; | 1213 | crit *= state->crit_factor; |
1218 | 1214 | ||
1219 | if (b->keys.set[i].data->keys < crit) { | 1215 | if (b->set[i].data->keys < crit) { |
1220 | bch_btree_sort_partial(b, i, state); | 1216 | bch_btree_sort_partial(b, i, state); |
1221 | return; | 1217 | return; |
1222 | } | 1218 | } |
1223 | } | 1219 | } |
1224 | 1220 | ||
1225 | /* Sort if we'd overflow */ | 1221 | /* Sort if we'd overflow */ |
1226 | if (b->keys.nsets + 1 == MAX_BSETS) { | 1222 | if (b->nsets + 1 == MAX_BSETS) { |
1227 | bch_btree_sort(b, state); | 1223 | bch_btree_sort(b, state); |
1228 | return; | 1224 | return; |
1229 | } | 1225 | } |
1230 | 1226 | ||
1231 | out: | 1227 | out: |
1232 | bch_bset_build_written_tree(&b->keys); | 1228 | bch_bset_build_written_tree(b); |
1233 | } | 1229 | } |
1234 | EXPORT_SYMBOL(bch_btree_sort_lazy); | 1230 | EXPORT_SYMBOL(bch_btree_sort_lazy); |
1235 | 1231 | ||
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h index e01e69e00654..4aa199d03344 100644 --- a/drivers/md/bcache/bset.h +++ b/drivers/md/bcache/bset.h | |||
@@ -1,7 +1,9 @@ | |||
1 | #ifndef _BCACHE_BSET_H | 1 | #ifndef _BCACHE_BSET_H |
2 | #define _BCACHE_BSET_H | 2 | #define _BCACHE_BSET_H |
3 | 3 | ||
4 | #include <linux/slab.h> | 4 | #include <linux/bcache.h> |
5 | #include <linux/kernel.h> | ||
6 | #include <linux/types.h> | ||
5 | 7 | ||
6 | #include "util.h" /* for time_stats */ | 8 | #include "util.h" /* for time_stats */ |
7 | 9 | ||
@@ -144,7 +146,6 @@ | |||
144 | * first key in that range of bytes again. | 146 | * first key in that range of bytes again. |
145 | */ | 147 | */ |
146 | 148 | ||
147 | struct btree; | ||
148 | struct btree_keys; | 149 | struct btree_keys; |
149 | struct btree_iter; | 150 | struct btree_iter; |
150 | struct btree_iter_set; | 151 | struct btree_iter_set; |
@@ -353,15 +354,15 @@ struct bset_sort_state { | |||
353 | 354 | ||
354 | void bch_bset_sort_state_free(struct bset_sort_state *); | 355 | void bch_bset_sort_state_free(struct bset_sort_state *); |
355 | int bch_bset_sort_state_init(struct bset_sort_state *, unsigned); | 356 | int bch_bset_sort_state_init(struct bset_sort_state *, unsigned); |
356 | void bch_btree_sort_lazy(struct btree *, struct bset_sort_state *); | 357 | void bch_btree_sort_lazy(struct btree_keys *, struct bset_sort_state *); |
357 | void bch_btree_sort_into(struct btree *, struct btree *, | 358 | void bch_btree_sort_into(struct btree_keys *, struct btree_keys *, |
358 | struct bset_sort_state *); | 359 | struct bset_sort_state *); |
359 | void bch_btree_sort_and_fix_extents(struct btree_keys *, struct btree_iter *, | 360 | void bch_btree_sort_and_fix_extents(struct btree_keys *, struct btree_iter *, |
360 | struct bset_sort_state *); | 361 | struct bset_sort_state *); |
361 | void bch_btree_sort_partial(struct btree *, unsigned, | 362 | void bch_btree_sort_partial(struct btree_keys *, unsigned, |
362 | struct bset_sort_state *); | 363 | struct bset_sort_state *); |
363 | 364 | ||
364 | static inline void bch_btree_sort(struct btree *b, | 365 | static inline void bch_btree_sort(struct btree_keys *b, |
365 | struct bset_sort_state *state) | 366 | struct bset_sort_state *state) |
366 | { | 367 | { |
367 | bch_btree_sort_partial(b, 0, state); | 368 | bch_btree_sort_partial(b, 0, state); |
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 2128ee1e6916..b14f34aa927d 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c | |||
@@ -480,9 +480,9 @@ void bch_btree_node_write(struct btree *b, struct closure *parent) | |||
480 | 480 | ||
481 | /* If not a leaf node, always sort */ | 481 | /* If not a leaf node, always sort */ |
482 | if (b->level && b->keys.nsets) | 482 | if (b->level && b->keys.nsets) |
483 | bch_btree_sort(b, &b->c->sort); | 483 | bch_btree_sort(&b->keys, &b->c->sort); |
484 | else | 484 | else |
485 | bch_btree_sort_lazy(b, &b->c->sort); | 485 | bch_btree_sort_lazy(&b->keys, &b->c->sort); |
486 | 486 | ||
487 | /* | 487 | /* |
488 | * do verify if there was more than one set initially (i.e. we did a | 488 | * do verify if there was more than one set initially (i.e. we did a |
@@ -1087,7 +1087,7 @@ static struct btree *btree_node_alloc_replacement(struct btree *b, bool wait) | |||
1087 | { | 1087 | { |
1088 | struct btree *n = bch_btree_node_alloc(b->c, b->level, wait); | 1088 | struct btree *n = bch_btree_node_alloc(b->c, b->level, wait); |
1089 | if (!IS_ERR_OR_NULL(n)) { | 1089 | if (!IS_ERR_OR_NULL(n)) { |
1090 | bch_btree_sort_into(b, n, &b->c->sort); | 1090 | bch_btree_sort_into(&b->keys, &n->keys, &b->c->sort); |
1091 | bkey_copy_key(&n->key, &b->key); | 1091 | bkey_copy_key(&n->key, &b->key); |
1092 | } | 1092 | } |
1093 | 1093 | ||