From 49a67206e4e481a097a3586fbd88ce0deb646307 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 18 Mar 2019 13:42:10 -0400 Subject: [PATCH] bcachefs: Add more time stats for being blocked on allocator Signed-off-by: Kent Overstreet --- fs/bcachefs/alloc_foreground.c | 21 +++++++++++++++++++++ fs/bcachefs/bcachefs.h | 8 ++++++-- fs/bcachefs/super.c | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/fs/bcachefs/alloc_foreground.c b/fs/bcachefs/alloc_foreground.c index ba0640e3f981..334bc6576b3a 100644 --- a/fs/bcachefs/alloc_foreground.c +++ b/fs/bcachefs/alloc_foreground.c @@ -246,6 +246,10 @@ struct open_bucket *bch2_bucket_alloc(struct bch_fs *c, struct bch_dev *ca, if (unlikely(c->open_buckets_nr_free <= open_buckets_reserved(reserve))) { if (cl) closure_wait(&c->open_buckets_wait, cl); + + if (!c->blocked_allocate_open_bucket) + c->blocked_allocate_open_bucket = local_clock(); + spin_unlock(&c->freelist_lock); trace_open_bucket_alloc_fail(ca, reserve); return ERR_PTR(-OPEN_BUCKETS_EMPTY); @@ -276,6 +280,9 @@ struct open_bucket *bch2_bucket_alloc(struct bch_fs *c, struct bch_dev *ca, if (cl) closure_wait(&c->freelist_wait, cl); + if (!c->blocked_allocate) + c->blocked_allocate = local_clock(); + spin_unlock(&c->freelist_lock); trace_bucket_alloc_fail(ca, reserve); @@ -301,6 +308,20 @@ out: bucket_io_clock_reset(c, ca, bucket, WRITE); spin_unlock(&ob->lock); + if (c->blocked_allocate_open_bucket) { + bch2_time_stats_update( + &c->times[BCH_TIME_blocked_allocate_open_bucket], + c->blocked_allocate_open_bucket); + c->blocked_allocate_open_bucket = 0; + } + + if (c->blocked_allocate) { + bch2_time_stats_update( + &c->times[BCH_TIME_blocked_allocate], + c->blocked_allocate); + c->blocked_allocate = 0; + } + spin_unlock(&c->freelist_lock); bch2_wake_allocator(ca); diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 27ffecb912a3..8bf1bfb7ec39 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -302,8 +302,10 @@ do { \ x(data_promote) \ x(journal_write) \ x(journal_delay) \ - x(journal_blocked) \ - x(journal_flush_seq) + x(journal_flush_seq) \ + x(blocked_journal) \ + x(blocked_allocate) \ + x(blocked_allocate_open_bucket) enum bch_time_stats { #define x(name) BCH_TIME_##name, @@ -653,6 +655,8 @@ struct bch_fs { /* ALLOCATOR */ spinlock_t freelist_lock; struct closure_waitlist freelist_wait; + u64 blocked_allocate; + u64 blocked_allocate_open_bucket; u8 open_buckets_freelist; u8 open_buckets_nr_free; struct closure_waitlist open_buckets_wait; diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index b1eb70556f75..e8242bb70b93 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -596,7 +596,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) c->journal.write_time = &c->times[BCH_TIME_journal_write]; c->journal.delay_time = &c->times[BCH_TIME_journal_delay]; - c->journal.blocked_time = &c->times[BCH_TIME_journal_blocked]; + c->journal.blocked_time = &c->times[BCH_TIME_blocked_journal]; c->journal.flush_seq_time = &c->times[BCH_TIME_journal_flush_seq]; bch2_fs_btree_cache_init_early(&c->btree_cache);