]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: buckets_in_flight on stack
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 9 May 2025 03:21:28 +0000 (23:21 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:50 +0000 (20:14 -0400)
copygc runs with a full stack available, there's no reason to
dynamically allocate this.

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

index 6e5680a3a97ccfac03a51249dc9311f8cccb4693..66f4920552c557255b71b50e151e8a7e72b73854 100644 (file)
@@ -354,19 +354,13 @@ static int bch2_copygc_thread(void *arg)
        struct moving_context ctxt;
        struct bch_move_stats move_stats;
        struct io_clock *clock = &c->io_clock[WRITE];
-       struct buckets_in_flight *buckets;
+       struct buckets_in_flight buckets = {};
        u64 last, wait;
-       int ret = 0;
 
-       buckets = kzalloc(sizeof(struct buckets_in_flight), GFP_KERNEL);
-       if (!buckets)
-               return -ENOMEM;
-       ret = rhashtable_init(&buckets->table, &bch_move_bucket_params);
+       int ret = rhashtable_init(&buckets.table, &bch_move_bucket_params);
        bch_err_msg(c, ret, "allocating copygc buckets in flight");
-       if (ret) {
-               kfree(buckets);
+       if (ret)
                return ret;
-       }
 
        set_freezable();
 
@@ -389,13 +383,13 @@ static int bch2_copygc_thread(void *arg)
                cond_resched();
 
                if (!c->opts.copygc_enabled) {
-                       move_buckets_wait(&ctxt, buckets, true);
+                       move_buckets_wait(&ctxt, &buckets, true);
                        kthread_wait_freezable(c->opts.copygc_enabled ||
                                               kthread_should_stop());
                }
 
                if (unlikely(freezing(current))) {
-                       move_buckets_wait(&ctxt, buckets, true);
+                       move_buckets_wait(&ctxt, &buckets, true);
                        __refrigerator(false);
                        continue;
                }
@@ -406,7 +400,7 @@ static int bch2_copygc_thread(void *arg)
                if (wait > clock->max_slop) {
                        c->copygc_wait_at = last;
                        c->copygc_wait = last + wait;
-                       move_buckets_wait(&ctxt, buckets, true);
+                       move_buckets_wait(&ctxt, &buckets, true);
                        trace_and_count(c, copygc_wait, c, wait, last + wait);
                        bch2_kthread_io_clock_wait(clock, last + wait,
                                        MAX_SCHEDULE_TIMEOUT);
@@ -416,7 +410,7 @@ static int bch2_copygc_thread(void *arg)
                c->copygc_wait = 0;
 
                c->copygc_running = true;
-               ret = bch2_copygc(&ctxt, buckets, &did_work);
+               ret = bch2_copygc(&ctxt, &buckets, &did_work);
                c->copygc_running = false;
 
                wake_up(&c->copygc_running_wq);
@@ -427,16 +421,14 @@ static int bch2_copygc_thread(void *arg)
                        if (min_member_capacity == U64_MAX)
                                min_member_capacity = 128 * 2048;
 
-                       move_buckets_wait(&ctxt, buckets, true);
+                       move_buckets_wait(&ctxt, &buckets, true);
                        bch2_kthread_io_clock_wait(clock, last + (min_member_capacity >> 6),
                                        MAX_SCHEDULE_TIMEOUT);
                }
        }
 
-       move_buckets_wait(&ctxt, buckets, true);
-
-       rhashtable_destroy(&buckets->table);
-       kfree(buckets);
+       move_buckets_wait(&ctxt, &buckets, true);
+       rhashtable_destroy(&buckets.table);
        bch2_moving_ctxt_exit(&ctxt);
        bch2_move_stats_exit(&move_stats, c);