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-02 16:02:54 -0400
commitc2070e4a85422938a291cfb43f7d5c4c85c1fdb3 (patch)
tree8d97c84abe600e56adb2573c58bc7c1b23430837
parentada96472a3e99e3da084b01877c4aaa554d5f744 (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 1b5ed7adc261..bed48afb4ac9 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,