aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/bcache/bset.c
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-11-11 21:38:51 -0500
committerKent Overstreet <kmo@daterainc.com>2014-01-08 16:05:13 -0500
commit89ebb4a28ba9efb5c9b18ba552e784021957b14a (patch)
tree7f649258fe76af99c63cb81c421c704a418abfe9 /drivers/md/bcache/bset.c
parentdc9d98d621bdce0552997200ce855659875a5c9f (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/bcache/bset.c')
-rw-r--r--drivers/md/bcache/bset.c50
1 files changed, 23 insertions, 27 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
1153void bch_btree_sort_partial(struct btree *b, unsigned start, 1155void 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}
1179EXPORT_SYMBOL(bch_btree_sort_partial); 1177EXPORT_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
1188void bch_btree_sort_into(struct btree *b, struct btree *new, 1186void 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
1205void bch_btree_sort_lazy(struct btree *b, struct bset_sort_state *state) 1203void 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
1231out: 1227out:
1232 bch_bset_build_written_tree(&b->keys); 1228 bch_bset_build_written_tree(b);
1233} 1229}
1234EXPORT_SYMBOL(bch_btree_sort_lazy); 1230EXPORT_SYMBOL(bch_btree_sort_lazy);
1235 1231