bcachefs: Move devs_sorted to alloc_request
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 26 May 2025 21:03:48 +0000 (17:03 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 30 May 2025 05:21:13 +0000 (01:21 -0400)
More stack usage work.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_foreground.c
fs/bcachefs/alloc_foreground.h
fs/bcachefs/journal_io.c

index 4341201..0e7eeb8 100644 (file)
@@ -603,18 +603,18 @@ static int __dev_stripe_cmp(struct dev_stripe_state *stripe,
 
 #define dev_stripe_cmp(l, r) __dev_stripe_cmp(stripe, l, r)
 
-struct dev_alloc_list bch2_dev_alloc_list(struct bch_fs *c,
-                                         struct dev_stripe_state *stripe,
-                                         struct bch_devs_mask *devs)
+void bch2_dev_alloc_list(struct bch_fs *c,
+                        struct dev_stripe_state *stripe,
+                        struct bch_devs_mask *devs,
+                        struct dev_alloc_list *ret)
 {
-       struct dev_alloc_list ret = { .nr = 0 };
-       unsigned i;
+       ret->nr = 0;
 
+       unsigned i;
        for_each_set_bit(i, devs->d, BCH_SB_MEMBERS_MAX)
-               ret.data[ret.nr++] = i;
+               ret->data[ret->nr++] = i;
 
-       bubble_sort(ret.data, ret.nr, dev_stripe_cmp);
-       return ret;
+       bubble_sort(ret->data, ret->nr, dev_stripe_cmp);
 }
 
 static const u64 stripe_clock_hand_rescale     = 1ULL << 62; /* trigger rescale at */
@@ -705,18 +705,19 @@ static int add_new_bucket(struct bch_fs *c,
        return 0;
 }
 
-int bch2_bucket_alloc_set_trans(struct btree_trans *trans,
-                               struct alloc_request *req,
-                               struct dev_stripe_state *stripe,
-                               struct closure *cl)
+inline int bch2_bucket_alloc_set_trans(struct btree_trans *trans,
+                                      struct alloc_request *req,
+                                      struct dev_stripe_state *stripe,
+                                      struct closure *cl)
 {
        struct bch_fs *c = trans->c;
        int ret = -BCH_ERR_insufficient_devices;
 
        BUG_ON(req->nr_effective >= req->nr_replicas);
 
-       struct dev_alloc_list devs_sorted = bch2_dev_alloc_list(c, stripe, &req->devs_may_alloc);
-       darray_for_each(devs_sorted, i) {
+       bch2_dev_alloc_list(c, stripe, &req->devs_may_alloc, &req->devs_sorted);
+
+       darray_for_each(req->devs_sorted, i) {
                req->ca = bch2_dev_tryget_noerror(c, *i);
                if (!req->ca)
                        continue;
@@ -776,9 +777,9 @@ static int bucket_alloc_from_stripe(struct btree_trans *trans,
        if (!h)
                return 0;
 
-       struct dev_alloc_list devs_sorted =
-               bch2_dev_alloc_list(c, &req->wp->stripe, &req->devs_may_alloc);
-       darray_for_each(devs_sorted, i)
+       bch2_dev_alloc_list(c, &req->wp->stripe, &req->devs_may_alloc, &req->devs_sorted);
+
+       darray_for_each(req->devs_sorted, i)
                for (unsigned ec_idx = 0; ec_idx < h->s->nr_data; ec_idx++) {
                        if (!h->s->blocks[ec_idx])
                                continue;
index 2e01c7b..1b3fc84 100644 (file)
@@ -42,6 +42,7 @@ struct alloc_request {
        struct bch_devs_mask    devs_may_alloc;
 
        /* bch2_bucket_alloc_set_trans(): */
+       struct dev_alloc_list   devs_sorted;
        struct bch_dev_usage    usage;
 
        /* bch2_bucket_alloc_trans(): */
@@ -71,9 +72,10 @@ struct alloc_request {
        struct bch_devs_mask    scratch_devs_may_alloc;
 };
 
-struct dev_alloc_list bch2_dev_alloc_list(struct bch_fs *,
-                                         struct dev_stripe_state *,
-                                         struct bch_devs_mask *);
+void bch2_dev_alloc_list(struct bch_fs *,
+                        struct dev_stripe_state *,
+                        struct bch_devs_mask *,
+                        struct dev_alloc_list *);
 void bch2_dev_stripe_increment(struct bch_dev *, struct dev_stripe_state *);
 
 static inline struct bch_dev *ob_dev(struct bch_fs *c, struct open_bucket *ob)
index 527ce6f..5229705 100644 (file)
@@ -1613,7 +1613,7 @@ static int journal_write_alloc(struct journal *j, struct journal_buf *w,
 
 retry_target:
        devs = target_rw_devs(c, BCH_DATA_journal, target);
-       devs_sorted = bch2_dev_alloc_list(c, &j->wp.stripe, &devs);
+       bch2_dev_alloc_list(c, &j->wp.stripe, &devs, &devs_sorted);
 retry_alloc:
        __journal_write_alloc(j, w, &devs_sorted, sectors, replicas, replicas_want);