From: Kent Overstreet Date: Wed, 2 Apr 2025 21:23:22 +0000 (-0400) Subject: bcachefs: reduce new_stripe_alloc_buckets() stack usage X-Git-Tag: v6.16-rc1~211^2~198 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a81bd454c45c89b167b6c2bd3ba7b5a489b0830;p=thirdparty%2Fkernel%2Flinux.git bcachefs: reduce new_stripe_alloc_buckets() stack usage Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/alloc_foreground.c b/fs/bcachefs/alloc_foreground.c index f68e5f6849b05..31d2207a071b6 100644 --- a/fs/bcachefs/alloc_foreground.c +++ b/fs/bcachefs/alloc_foreground.c @@ -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; } /* diff --git a/fs/bcachefs/alloc_foreground.h b/fs/bcachefs/alloc_foreground.h index ae8ca3b7786bb..192203410d4ec 100644 --- a/fs/bcachefs/alloc_foreground.h +++ b/fs/bcachefs/alloc_foreground.h @@ -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 *, diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c index 11f46dccc14f4..37e63137041c9 100644 --- a/fs/bcachefs/ec.c +++ b/fs/bcachefs/ec.c @@ -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; }