bcachefs: Add open_buckets to sysfs
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 13 Jul 2021 03:52:49 +0000 (23:52 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:08 +0000 (17:09 -0400)
This is to help debug a rare shutdown deadlock in the allocator code -
the btree code is leaking open_buckets.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/alloc_background.c
fs/bcachefs/alloc_background.h
fs/bcachefs/sysfs.c

index 15f9adf0876a9fac3871b6541cd80c9a491461ee..fc20649b19cf49c5f940259eb7010a47b36d0d4c 100644 (file)
@@ -1232,3 +1232,22 @@ void bch2_fs_allocator_background_init(struct bch_fs *c)
 {
        spin_lock_init(&c->freelist_lock);
 }
+
+void bch2_open_buckets_to_text(struct printbuf *out, struct bch_fs *c)
+{
+       struct open_bucket *ob;
+
+       for (ob = c->open_buckets;
+            ob < c->open_buckets + ARRAY_SIZE(c->open_buckets);
+            ob++) {
+               spin_lock(&ob->lock);
+               if (ob->valid && !ob->on_partial_list) {
+                       pr_buf(out, "%zu ref %u type %s\n",
+                              ob - c->open_buckets,
+                              atomic_read(&ob->pin),
+                              bch2_data_types[ob->type]);
+               }
+               spin_unlock(&ob->lock);
+       }
+
+}
index 9cadfdb5b83df30211082a06851131c25d5b197b..a4f6bf56b18f6eee5266852e994f28f6d5b5f738 100644 (file)
@@ -132,4 +132,6 @@ int bch2_dev_allocator_start(struct bch_dev *);
 int bch2_alloc_write(struct bch_fs *, unsigned);
 void bch2_fs_allocator_background_init(struct bch_fs *);
 
+void bch2_open_buckets_to_text(struct printbuf *, struct bch_fs *);
+
 #endif /* _BCACHEFS_ALLOC_BACKGROUND_H */
index 84a7acb04d01b1915f673164ef98dc93011de5de..9b1ffbf96e14784a63527ff6128ee925564eee8a 100644 (file)
@@ -171,6 +171,7 @@ read_attribute(btree_cache);
 read_attribute(btree_key_cache);
 read_attribute(btree_transactions);
 read_attribute(stripes_heap);
+read_attribute(open_buckets);
 
 read_attribute(internal_uuid);
 
@@ -409,6 +410,11 @@ SHOW(bch2_fs)
                return out.pos - buf;
        }
 
+       if (attr == &sysfs_open_buckets) {
+               bch2_open_buckets_to_text(&out, c);
+               return out.pos - buf;
+       }
+
        if (attr == &sysfs_compression_stats) {
                bch2_compression_stats_to_text(&out, c);
                return out.pos - buf;
@@ -567,6 +573,7 @@ struct attribute *bch2_fs_internal_files[] = {
        &sysfs_btree_key_cache,
        &sysfs_btree_transactions,
        &sysfs_stripes_heap,
+       &sysfs_open_buckets,
 
        &sysfs_read_realloc_races,
        &sysfs_extent_migrate_done,