]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/alloc_foreground.c
Move c_src dirs back to toplevel
[bcachefs-tools-debian] / libbcachefs / alloc_foreground.c
index 1ba0eeb7552a2795d033d2603cccce611c8f3381..b0ff47998a9440912f940dc09e27b34e6341cb9e 100644 (file)
@@ -69,11 +69,8 @@ const char * const bch2_watermarks[] = {
 
 void bch2_reset_alloc_cursors(struct bch_fs *c)
 {
-       struct bch_dev *ca;
-       unsigned i;
-
        rcu_read_lock();
-       for_each_member_device_rcu(ca, c, i, NULL)
+       for_each_member_device_rcu(c, ca, NULL)
                ca->alloc_cursor = 0;
        rcu_read_unlock();
 }
@@ -239,9 +236,8 @@ static struct open_bucket *__try_alloc_bucket(struct bch_fs *c, struct bch_dev *
                if (cl)
                        closure_wait(&c->open_buckets_wait, cl);
 
-               if (!c->blocked_allocate_open_bucket)
-                       c->blocked_allocate_open_bucket = local_clock();
-
+               track_event_change(&c->times[BCH_TIME_blocked_allocate_open_bucket],
+                                  &c->blocked_allocate_open_bucket, true);
                spin_unlock(&c->freelist_lock);
                return ERR_PTR(-BCH_ERR_open_buckets_empty);
        }
@@ -267,19 +263,11 @@ static struct open_bucket *__try_alloc_bucket(struct bch_fs *c, struct bch_dev *
        ca->nr_open_buckets++;
        bch2_open_bucket_hash_add(c, ob);
 
-       if (c->blocked_allocate_open_bucket) {
-               bch2_time_stats_update(
-                       &c->times[BCH_TIME_blocked_allocate_open_bucket],
-                       c->blocked_allocate_open_bucket);
-               c->blocked_allocate_open_bucket = 0;
-       }
+       track_event_change(&c->times[BCH_TIME_blocked_allocate_open_bucket],
+                          &c->blocked_allocate_open_bucket, false);
 
-       if (c->blocked_allocate) {
-               bch2_time_stats_update(
-                       &c->times[BCH_TIME_blocked_allocate],
-                       c->blocked_allocate);
-               c->blocked_allocate = 0;
-       }
+       track_event_change(&c->times[BCH_TIME_blocked_allocate],
+                          &c->blocked_allocate, false);
 
        spin_unlock(&c->freelist_lock);
        return ob;
@@ -377,9 +365,9 @@ static struct open_bucket *try_alloc_bucket(struct btree_trans *trans, struct bc
 
        ob = __try_alloc_bucket(c, ca, b, watermark, a, s, cl);
        if (!ob)
-               iter.path->preserve = false;
+               set_btree_iter_dontneed(&iter);
 err:
-       if (iter.trans && iter.path)
+       if (iter.path)
                set_btree_iter_dontneed(&iter);
        bch2_trans_iter_exit(trans, &iter);
        printbuf_exit(&buf);
@@ -447,7 +435,7 @@ again:
 
                ob = __try_alloc_bucket(trans->c, ca, k.k->p.offset, watermark, a, s, cl);
 next:
-               citer.path->preserve = false;
+               set_btree_iter_dontneed(&citer);
                bch2_trans_iter_exit(trans, &citer);
                if (ob)
                        break;
@@ -502,7 +490,7 @@ again:
                        ob = try_alloc_bucket(trans, ca, watermark,
                                              alloc_cursor, s, k, cl);
                        if (ob) {
-                               iter.path->preserve = false;
+                               set_btree_iter_dontneed(&iter);
                                break;
                        }
                }
@@ -567,8 +555,8 @@ again:
                        goto again;
                }
 
-               if (!c->blocked_allocate)
-                       c->blocked_allocate = local_clock();
+               track_event_change(&c->times[BCH_TIME_blocked_allocate],
+                                  &c->blocked_allocate, true);
 
                ob = ERR_PTR(-BCH_ERR_freelist_empty);
                goto err;
@@ -697,11 +685,9 @@ static int add_new_bucket(struct bch_fs *c,
                bch_dev_bkey_exists(c, ob->dev)->mi.durability;
 
        BUG_ON(*nr_effective >= nr_replicas);
-       BUG_ON(flags & BCH_WRITE_ONLY_SPECIFIED_DEVS);
 
        __clear_bit(ob->dev, devs_may_alloc->d);
-       *nr_effective   += (flags & BCH_WRITE_ONLY_SPECIFIED_DEVS)
-               ? durability : 1;
+       *nr_effective   += durability;
        *have_cache     |= !durability;
 
        ob_push(c, ptrs, ob);
@@ -972,8 +958,8 @@ static int __open_bucket_add_buckets(struct btree_trans *trans,
        devs = target_rw_devs(c, wp->data_type, target);
 
        /* Don't allocate from devices we already have pointers to: */
-       for (i = 0; i < devs_have->nr; i++)
-               __clear_bit(devs_have->devs[i], devs.d);
+       darray_for_each(*devs_have, i)
+               __clear_bit(*i, devs.d);
 
        open_bucket_for_each(c, ptrs, ob, i)
                __clear_bit(ob->dev, devs.d);
@@ -1374,8 +1360,17 @@ retry:
                        goto alloc_done;
 
                /* Don't retry from all devices if we're out of open buckets: */
-               if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty))
-                       goto allocate_blocking;
+               if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty)) {
+                       int ret = open_bucket_add_buckets(trans, &ptrs, wp, devs_have,
+                                             target, erasure_code,
+                                             nr_replicas, &nr_effective,
+                                             &have_cache, watermark,
+                                             flags, cl);
+                       if (!ret ||
+                           bch2_err_matches(ret, BCH_ERR_transaction_restart) ||
+                           bch2_err_matches(ret, BCH_ERR_open_buckets_empty))
+                               goto alloc_done;
+               }
 
                /*
                 * Only try to allocate cache (durability = 0 devices) from the
@@ -1389,7 +1384,6 @@ retry:
                                              &have_cache, watermark,
                                              flags, cl);
        } else {
-allocate_blocking:
                ret = open_bucket_add_buckets(trans, &ptrs, wp, devs_have,
                                              target, erasure_code,
                                              nr_replicas, &nr_effective,