bcachefs: reduce new_stripe_alloc_buckets() stack usage
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 2 Apr 2025 21:23:22 +0000 (17:23 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:13:44 +0000 (20:13 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_foreground.c
fs/bcachefs/alloc_foreground.h
fs/bcachefs/ec.c

index f68e5f6849b0551196d2adb4a3c50765dc679da1..31d2207a071b69e3da9fd716df159da9ab44a680 100644 (file)
@@ -829,15 +829,15 @@ static int bucket_alloc_set_writepoint(struct bch_fs *c,
        unsigned i;
        int ret = 0;
 
-       req->ptrs2.nr = 0;
+       req->scratch_ptrs.nr = 0;
 
        open_bucket_for_each(c, &req->wp->ptrs, ob, i) {
                if (!ret && want_bucket(c, req, ob))
                        ret = add_new_bucket(c, req, ob);
                else
-                       ob_push(c, &req->ptrs2, ob);
+                       ob_push(c, &req->scratch_ptrs, ob);
        }
-       req->wp->ptrs = req->ptrs2;
+       req->wp->ptrs = req->scratch_ptrs;
 
        return ret;
 }
@@ -1214,7 +1214,7 @@ deallocate_extra_replicas(struct bch_fs *c,
        unsigned extra_replicas = req->nr_effective - req->nr_replicas;
        unsigned i;
 
-       req->ptrs2.nr = 0;
+       req->scratch_ptrs.nr = 0;
 
        open_bucket_for_each(c, &req->ptrs, ob, i) {
                unsigned d = ob_dev(c, ob)->mi.durability;
@@ -1223,11 +1223,11 @@ deallocate_extra_replicas(struct bch_fs *c,
                        extra_replicas -= d;
                        ob_push(c, &req->wp->ptrs, ob);
                } else {
-                       ob_push(c, &req->ptrs2, ob);
+                       ob_push(c, &req->scratch_ptrs, ob);
                }
        }
 
-       req->ptrs = req->ptrs2;
+       req->ptrs = req->scratch_ptrs;
 }
 
 /*
index ae8ca3b7786bbcf8464d862e02d76500d4c3f30f..192203410d4ec3ae7936479a25ec628164e6ca77 100644 (file)
@@ -36,7 +36,6 @@ struct alloc_request {
 
        /* These fields are used primarily by open_bucket_add_buckets */
        struct open_buckets     ptrs;
-       struct open_buckets     ptrs2;
        unsigned                nr_effective;   /* sum of @ptrs durability */
        bool                    have_cache;     /* have we allocated from a 0 durability dev */
        struct bch_devs_mask    devs_may_alloc;
@@ -62,6 +61,13 @@ struct alloc_request {
                u64             skipped_nouse;
                u64             skipped_mi_btree_bitmap;
        } counters;
+
+       unsigned                scratch_nr_replicas;
+       unsigned                scratch_nr_effective;
+       bool                    scratch_have_cache;
+       enum bch_data_type      scratch_data_type;
+       struct open_buckets     scratch_ptrs;
+       struct bch_devs_mask    scratch_devs_may_alloc;
 };
 
 struct dev_alloc_list bch2_dev_alloc_list(struct bch_fs *,
index 11f46dccc14f40e32b565779660f0a6d8b5dc3d8..37e63137041c9491e20f02fd4f4220ccc333500f 100644 (file)
@@ -1720,12 +1720,12 @@ static int new_stripe_alloc_buckets(struct btree_trans *trans,
        unsigned i, j, nr_have_parity = 0, nr_have_data = 0;
        int ret = 0;
 
-       enum bch_data_type      saved_data_type         = req->data_type;
-       struct open_buckets     saved_ptrs              = req->ptrs;
-       unsigned                saved_nr_replicas       = req->nr_replicas;
-       unsigned                saved_nr_effective      = req->nr_effective;
-       bool                    saved_have_cache        = req->have_cache;
-       struct bch_devs_mask    saved_devs_may_alloc    = req->devs_may_alloc;
+       req->scratch_data_type          = req->data_type;
+       req->scratch_ptrs               = req->ptrs;
+       req->scratch_nr_replicas        = req->nr_replicas;
+       req->scratch_nr_effective       = req->nr_effective;
+       req->scratch_have_cache         = req->have_cache;
+       req->scratch_devs_may_alloc     = req->devs_may_alloc;
 
        req->devs_may_alloc     = h->devs;
        req->have_cache         = true;
@@ -1801,12 +1801,12 @@ static int new_stripe_alloc_buckets(struct btree_trans *trans,
                        goto err;
        }
 err:
-       req->data_type          = saved_data_type;
-       req->ptrs               = saved_ptrs;
-       req->nr_replicas        = saved_nr_replicas;
-       req->nr_effective       = saved_nr_effective;
-       req->have_cache         = saved_have_cache;
-       req->devs_may_alloc     = saved_devs_may_alloc;
+       req->data_type          = req->scratch_data_type;
+       req->ptrs               = req->scratch_ptrs;
+       req->nr_replicas        = req->scratch_nr_replicas;
+       req->nr_effective       = req->scratch_nr_effective;
+       req->have_cache         = req->scratch_have_cache;
+       req->devs_may_alloc     = req->scratch_devs_may_alloc;
        return ret;
 }