aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTang Junhui <tang.junhui@zte.com.cn>2018-02-07 14:41:39 -0500
committerJens Axboe <axboe@kernel.dk>2018-02-07 14:50:01 -0500
commita728eacbbdd229d1d903e46261c57d5206f87a4a (patch)
tree16b0773daa7c4b7d222b221cf75470ad34c39dc8
parent30abb3a67f4b2aa160feeb3c0b771f730cbcca67 (diff)
bcache: add journal statistic
Sometimes, Journal takes up a lot of CPU, we need statistics to know what's the journal is doing. So this patch provide some journal statistics: 1) reclaim: how many times the journal try to reclaim resource, usually the journal bucket or/and the pin are exhausted. 2) flush_write: how many times the journal try to flush btree node to cache device, usually the journal bucket are exhausted. 3) retry_flush_write: how many times the journal retry to flush the next btree node, usually the previous tree node have been flushed by other thread. we show these statistic by sysfs interface. Through these statistics We can totally see the status of journal module when the CPU is too high. Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn> Reviewed-by: Michael Lyle <mlyle@lyle.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--drivers/md/bcache/bcache.h4
-rw-r--r--drivers/md/bcache/journal.c5
-rw-r--r--drivers/md/bcache/sysfs.c15
3 files changed, 24 insertions, 0 deletions
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 5e2d4e80198e..b98d7705acb6 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -658,6 +658,10 @@ struct cache_set {
658 atomic_long_t writeback_keys_done; 658 atomic_long_t writeback_keys_done;
659 atomic_long_t writeback_keys_failed; 659 atomic_long_t writeback_keys_failed;
660 660
661 atomic_long_t reclaim;
662 atomic_long_t flush_write;
663 atomic_long_t retry_flush_write;
664
661 enum { 665 enum {
662 ON_ERROR_UNREGISTER, 666 ON_ERROR_UNREGISTER,
663 ON_ERROR_PANIC, 667 ON_ERROR_PANIC,
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index a87165c1d8e5..f5296007a9d5 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -377,6 +377,8 @@ static void btree_flush_write(struct cache_set *c)
377 */ 377 */
378 struct btree *b, *best; 378 struct btree *b, *best;
379 unsigned i; 379 unsigned i;
380
381 atomic_long_inc(&c->flush_write);
380retry: 382retry:
381 best = NULL; 383 best = NULL;
382 384
@@ -397,6 +399,7 @@ retry:
397 if (!btree_current_write(b)->journal) { 399 if (!btree_current_write(b)->journal) {
398 mutex_unlock(&b->write_lock); 400 mutex_unlock(&b->write_lock);
399 /* We raced */ 401 /* We raced */
402 atomic_long_inc(&c->retry_flush_write);
400 goto retry; 403 goto retry;
401 } 404 }
402 405
@@ -476,6 +479,8 @@ static void journal_reclaim(struct cache_set *c)
476 unsigned iter, n = 0; 479 unsigned iter, n = 0;
477 atomic_t p; 480 atomic_t p;
478 481
482 atomic_long_inc(&c->reclaim);
483
479 while (!atomic_read(&fifo_front(&c->journal.pin))) 484 while (!atomic_read(&fifo_front(&c->journal.pin)))
480 fifo_pop(&c->journal.pin, p); 485 fifo_pop(&c->journal.pin, p);
481 486
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index b4184092c727..46e7a6b3e7c7 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -65,6 +65,9 @@ read_attribute(bset_tree_stats);
65 65
66read_attribute(state); 66read_attribute(state);
67read_attribute(cache_read_races); 67read_attribute(cache_read_races);
68read_attribute(reclaim);
69read_attribute(flush_write);
70read_attribute(retry_flush_write);
68read_attribute(writeback_keys_done); 71read_attribute(writeback_keys_done);
69read_attribute(writeback_keys_failed); 72read_attribute(writeback_keys_failed);
70read_attribute(io_errors); 73read_attribute(io_errors);
@@ -545,6 +548,15 @@ SHOW(__bch_cache_set)
545 sysfs_print(cache_read_races, 548 sysfs_print(cache_read_races,
546 atomic_long_read(&c->cache_read_races)); 549 atomic_long_read(&c->cache_read_races));
547 550
551 sysfs_print(reclaim,
552 atomic_long_read(&c->reclaim));
553
554 sysfs_print(flush_write,
555 atomic_long_read(&c->flush_write));
556
557 sysfs_print(retry_flush_write,
558 atomic_long_read(&c->retry_flush_write));
559
548 sysfs_print(writeback_keys_done, 560 sysfs_print(writeback_keys_done,
549 atomic_long_read(&c->writeback_keys_done)); 561 atomic_long_read(&c->writeback_keys_done));
550 sysfs_print(writeback_keys_failed, 562 sysfs_print(writeback_keys_failed,
@@ -731,6 +743,9 @@ static struct attribute *bch_cache_set_internal_files[] = {
731 743
732 &sysfs_bset_tree_stats, 744 &sysfs_bset_tree_stats,
733 &sysfs_cache_read_races, 745 &sysfs_cache_read_races,
746 &sysfs_reclaim,
747 &sysfs_flush_write,
748 &sysfs_retry_flush_write,
734 &sysfs_writeback_keys_done, 749 &sysfs_writeback_keys_done,
735 &sysfs_writeback_keys_failed, 750 &sysfs_writeback_keys_failed,
736 751