summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-03-02 23:34:26 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2022-04-17 15:44:27 -0400
commit07208ecad68bcc73695d4673533460ae40d1a7a1 (patch)
tree48bac28c8b73620acd6cc0483c9bde4d2106c895
parent2d6ed1708c11c9aadb34a5d6f7935b6c7d04852c (diff)
bcachefs: Improve bucket_alloc_fail tracepoint
Also include the number of buckets available, and the number of buckets awaiting journal commit - and add a sysfs counter, too. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/alloc_foreground.c16
-rw-r--r--fs/bcachefs/bcachefs.h1
-rw-r--r--fs/bcachefs/sysfs.c4
-rw-r--r--include/trace/events/bcachefs.h27
4 files changed, 41 insertions, 7 deletions
diff --git a/fs/bcachefs/alloc_foreground.c b/fs/bcachefs/alloc_foreground.c
index e0dc585b50da..178d7c058597 100644
--- a/fs/bcachefs/alloc_foreground.c
+++ b/fs/bcachefs/alloc_foreground.c
@@ -432,7 +432,7 @@ static struct open_bucket *bch2_bucket_alloc_trans(struct btree_trans *trans,
}
bch2_trans_iter_exit(trans, &iter);
- return ob ?: ERR_PTR(ret ?: -FREELIST_EMPTY);
+ return ob ?: ERR_PTR(ret);
}
/**
@@ -471,8 +471,8 @@ again:
if (!c->blocked_allocate)
c->blocked_allocate = local_clock();
- trace_bucket_alloc_fail(ca, reserve);
- return ERR_PTR(-FREELIST_EMPTY);
+ ob = ERR_PTR(-FREELIST_EMPTY);
+ goto err;
}
ret = bch2_trans_do(c, NULL, NULL, 0,
@@ -482,8 +482,16 @@ again:
if (need_journal_commit * 2 > avail)
bch2_journal_flush_async(&c->journal, NULL);
+err:
+ if (!ob)
+ ob = ERR_PTR(ret ?: -FREELIST_EMPTY);
- return ob ?: ERR_PTR(ret ?: -FREELIST_EMPTY);
+ if (ob == ERR_PTR(-FREELIST_EMPTY)) {
+ trace_bucket_alloc_fail(ca, reserve, avail, need_journal_commit);
+ atomic_long_inc(&c->bucket_alloc_fail);
+ }
+
+ return ob;
}
static int __dev_stripe_cmp(struct dev_stripe_state *stripe,
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h
index 2d185d22d78e..a4ef9aabf274 100644
--- a/fs/bcachefs/bcachefs.h
+++ b/fs/bcachefs/bcachefs.h
@@ -897,6 +897,7 @@ struct bch_fs {
atomic_long_t read_realloc_races;
atomic_long_t extent_migrate_done;
atomic_long_t extent_migrate_raced;
+ atomic_long_t bucket_alloc_fail;
unsigned btree_gc_periodic:1;
unsigned copy_gc_enabled:1;
diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c
index 4cc6ad4a5649..dc43f2f14b7e 100644
--- a/fs/bcachefs/sysfs.c
+++ b/fs/bcachefs/sysfs.c
@@ -188,6 +188,7 @@ read_attribute(alloc_debug);
read_attribute(read_realloc_races);
read_attribute(extent_migrate_done);
read_attribute(extent_migrate_raced);
+read_attribute(bucket_alloc_fail);
rw_attribute(discard);
rw_attribute(label);
@@ -374,6 +375,8 @@ SHOW(bch2_fs)
atomic_long_read(&c->extent_migrate_done));
sysfs_print(extent_migrate_raced,
atomic_long_read(&c->extent_migrate_raced));
+ sysfs_print(bucket_alloc_fail,
+ atomic_long_read(&c->bucket_alloc_fail));
sysfs_printf(btree_gc_periodic, "%u", (int) c->btree_gc_periodic);
@@ -570,6 +573,7 @@ struct attribute *bch2_fs_internal_files[] = {
&sysfs_read_realloc_races,
&sysfs_extent_migrate_done,
&sysfs_extent_migrate_raced,
+ &sysfs_bucket_alloc_fail,
&sysfs_gc_gens_pos,
diff --git a/include/trace/events/bcachefs.h b/include/trace/events/bcachefs.h
index 0596887959d3..832e9f191409 100644
--- a/include/trace/events/bcachefs.h
+++ b/include/trace/events/bcachefs.h
@@ -491,9 +491,30 @@ DEFINE_EVENT(bucket_alloc, bucket_alloc,
TP_ARGS(ca, reserve)
);
-DEFINE_EVENT(bucket_alloc, bucket_alloc_fail,
- TP_PROTO(struct bch_dev *ca, enum alloc_reserve reserve),
- TP_ARGS(ca, reserve)
+TRACE_EVENT(bucket_alloc_fail,
+ TP_PROTO(struct bch_dev *ca, enum alloc_reserve reserve,
+ u64 avail, u64 need_journal_commit),
+ TP_ARGS(ca, reserve, avail, need_journal_commit),
+
+ TP_STRUCT__entry(
+ __field(dev_t, dev )
+ __field(enum alloc_reserve, reserve )
+ __field(u64, avail )
+ __field(u64, need_journal_commit )
+ ),
+
+ TP_fast_assign(
+ __entry->dev = ca->dev;
+ __entry->reserve = reserve;
+ __entry->avail = avail;
+ __entry->need_journal_commit = need_journal_commit;
+ ),
+
+ TP_printk("%d,%d reserve %d avail %llu need_journal_commit %llu",
+ MAJOR(__entry->dev), MINOR(__entry->dev),
+ __entry->reserve,
+ __entry->avail,
+ __entry->need_journal_commit)
);
DEFINE_EVENT(bucket_alloc, open_bucket_alloc_fail,