diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-11-11 22:25:55 -0500 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2014-01-08 16:05:13 -0500 |
commit | f67342dd342d5917d94a7c0ffbde5f78e0d7a57a (patch) | |
tree | 64472797ad91ae8e9b9e100863b98a69c34bd9a2 /drivers/md | |
parent | 59158fde429fb5d18064e2734b3dd5e6048affbd (diff) |
bcache: Refactor bset_tree sysfs stats
We're in the process of turning bset.c into library code, so none of the code in
that file should know about struct cache_set or struct btree - so, move the
btree traversal part of the stats code to sysfs.c.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/bcache/bset.c | 49 | ||||
-rw-r--r-- | drivers/md/bcache/bset.h | 10 | ||||
-rw-r--r-- | drivers/md/bcache/sysfs.c | 42 |
3 files changed, 54 insertions, 47 deletions
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c index f34ef56560ed..a3ffc3711b75 100644 --- a/drivers/md/bcache/bset.c +++ b/drivers/md/bcache/bset.c | |||
@@ -1122,29 +1122,16 @@ out: | |||
1122 | } | 1122 | } |
1123 | EXPORT_SYMBOL(bch_btree_sort_lazy); | 1123 | EXPORT_SYMBOL(bch_btree_sort_lazy); |
1124 | 1124 | ||
1125 | /* Sysfs stuff */ | 1125 | void bch_btree_keys_stats(struct btree_keys *b, struct bset_stats *stats) |
1126 | |||
1127 | struct bset_stats { | ||
1128 | struct btree_op op; | ||
1129 | size_t nodes; | ||
1130 | size_t sets_written, sets_unwritten; | ||
1131 | size_t bytes_written, bytes_unwritten; | ||
1132 | size_t floats, failed; | ||
1133 | }; | ||
1134 | |||
1135 | static int btree_bset_stats(struct btree_op *op, struct btree *b) | ||
1136 | { | 1126 | { |
1137 | struct bset_stats *stats = container_of(op, struct bset_stats, op); | ||
1138 | unsigned i; | 1127 | unsigned i; |
1139 | 1128 | ||
1140 | stats->nodes++; | 1129 | for (i = 0; i <= b->nsets; i++) { |
1141 | 1130 | struct bset_tree *t = &b->set[i]; | |
1142 | for (i = 0; i <= b->keys.nsets; i++) { | ||
1143 | struct bset_tree *t = &b->keys.set[i]; | ||
1144 | size_t bytes = t->data->keys * sizeof(uint64_t); | 1131 | size_t bytes = t->data->keys * sizeof(uint64_t); |
1145 | size_t j; | 1132 | size_t j; |
1146 | 1133 | ||
1147 | if (bset_written(&b->keys, t)) { | 1134 | if (bset_written(b, t)) { |
1148 | stats->sets_written++; | 1135 | stats->sets_written++; |
1149 | stats->bytes_written += bytes; | 1136 | stats->bytes_written += bytes; |
1150 | 1137 | ||
@@ -1158,32 +1145,4 @@ static int btree_bset_stats(struct btree_op *op, struct btree *b) | |||
1158 | stats->bytes_unwritten += bytes; | 1145 | stats->bytes_unwritten += bytes; |
1159 | } | 1146 | } |
1160 | } | 1147 | } |
1161 | |||
1162 | return MAP_CONTINUE; | ||
1163 | } | ||
1164 | |||
1165 | int bch_bset_print_stats(struct cache_set *c, char *buf) | ||
1166 | { | ||
1167 | struct bset_stats t; | ||
1168 | int ret; | ||
1169 | |||
1170 | memset(&t, 0, sizeof(struct bset_stats)); | ||
1171 | bch_btree_op_init(&t.op, -1); | ||
1172 | |||
1173 | ret = bch_btree_map_nodes(&t.op, c, &ZERO_KEY, btree_bset_stats); | ||
1174 | if (ret < 0) | ||
1175 | return ret; | ||
1176 | |||
1177 | return snprintf(buf, PAGE_SIZE, | ||
1178 | "btree nodes: %zu\n" | ||
1179 | "written sets: %zu\n" | ||
1180 | "unwritten sets: %zu\n" | ||
1181 | "written key bytes: %zu\n" | ||
1182 | "unwritten key bytes: %zu\n" | ||
1183 | "floats: %zu\n" | ||
1184 | "failed: %zu\n", | ||
1185 | t.nodes, | ||
1186 | t.sets_written, t.sets_unwritten, | ||
1187 | t.bytes_written, t.bytes_unwritten, | ||
1188 | t.floats, t.failed); | ||
1189 | } | 1148 | } |
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h index 4fc40fd719de..49135695342e 100644 --- a/drivers/md/bcache/bset.h +++ b/drivers/md/bcache/bset.h | |||
@@ -365,6 +365,14 @@ static inline void bch_btree_sort(struct btree *b, | |||
365 | bch_btree_sort_partial(b, 0, state); | 365 | bch_btree_sort_partial(b, 0, state); |
366 | } | 366 | } |
367 | 367 | ||
368 | struct bset_stats { | ||
369 | size_t sets_written, sets_unwritten; | ||
370 | size_t bytes_written, bytes_unwritten; | ||
371 | size_t floats, failed; | ||
372 | }; | ||
373 | |||
374 | void bch_btree_keys_stats(struct btree_keys *, struct bset_stats *); | ||
375 | |||
368 | /* Bkey utility code */ | 376 | /* Bkey utility code */ |
369 | 377 | ||
370 | #define bset_bkey_last(i) bkey_idx((struct bkey *) (i)->d, (i)->keys) | 378 | #define bset_bkey_last(i) bkey_idx((struct bkey *) (i)->d, (i)->keys) |
@@ -495,6 +503,4 @@ int __bch_keylist_realloc(struct keylist *, unsigned); | |||
495 | struct cache_set; | 503 | struct cache_set; |
496 | const char *bch_ptr_status(struct cache_set *, const struct bkey *); | 504 | const char *bch_ptr_status(struct cache_set *, const struct bkey *); |
497 | 505 | ||
498 | int bch_bset_print_stats(struct cache_set *, char *); | ||
499 | |||
500 | #endif | 506 | #endif |
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 7e175dbc76b0..db2111b88e20 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c | |||
@@ -400,6 +400,48 @@ static struct attribute *bch_flash_dev_files[] = { | |||
400 | }; | 400 | }; |
401 | KTYPE(bch_flash_dev); | 401 | KTYPE(bch_flash_dev); |
402 | 402 | ||
403 | struct bset_stats_op { | ||
404 | struct btree_op op; | ||
405 | size_t nodes; | ||
406 | struct bset_stats stats; | ||
407 | }; | ||
408 | |||
409 | static int btree_bset_stats(struct btree_op *b_op, struct btree *b) | ||
410 | { | ||
411 | struct bset_stats_op *op = container_of(b_op, struct bset_stats_op, op); | ||
412 | |||
413 | op->nodes++; | ||
414 | bch_btree_keys_stats(&b->keys, &op->stats); | ||
415 | |||
416 | return MAP_CONTINUE; | ||
417 | } | ||
418 | |||
419 | int bch_bset_print_stats(struct cache_set *c, char *buf) | ||
420 | { | ||
421 | struct bset_stats_op op; | ||
422 | int ret; | ||
423 | |||
424 | memset(&op, 0, sizeof(op)); | ||
425 | bch_btree_op_init(&op.op, -1); | ||
426 | |||
427 | ret = bch_btree_map_nodes(&op.op, c, &ZERO_KEY, btree_bset_stats); | ||
428 | if (ret < 0) | ||
429 | return ret; | ||
430 | |||
431 | return snprintf(buf, PAGE_SIZE, | ||
432 | "btree nodes: %zu\n" | ||
433 | "written sets: %zu\n" | ||
434 | "unwritten sets: %zu\n" | ||
435 | "written key bytes: %zu\n" | ||
436 | "unwritten key bytes: %zu\n" | ||
437 | "floats: %zu\n" | ||
438 | "failed: %zu\n", | ||
439 | op.nodes, | ||
440 | op.stats.sets_written, op.stats.sets_unwritten, | ||
441 | op.stats.bytes_written, op.stats.bytes_unwritten, | ||
442 | op.stats.floats, op.stats.failed); | ||
443 | } | ||
444 | |||
403 | SHOW(__bch_cache_set) | 445 | SHOW(__bch_cache_set) |
404 | { | 446 | { |
405 | unsigned root_usage(struct cache_set *c) | 447 | unsigned root_usage(struct cache_set *c) |