bcachefs: alloc_data_type_set() happens in alloc trigger
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 12 Dec 2024 07:32:32 +0000 (02:32 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:23 +0000 (01:36 -0500)
Originally, we ran insert triggers before overwrite so that if an extent
was being moved (by fallocate insert/collapse range), the bucket sector
count wouldn't hit 0 partway through, and so we don't trigger state
changes caused by that too soon.

But this is better solved by just moving the data type change to the
alloc trigger itself, where it's already called.

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

index e5ba7d1429b9c098a5c3903d21e3ca5f06be8747..5aa11ca08c9439681088b7491e756947b10718db 100644 (file)
@@ -1134,7 +1134,6 @@ static int bch2_alloc_write_oldest_gen(struct btree_trans *trans, struct bch_dev
                return ret;
 
        a_mut->v.oldest_gen = ca->oldest_gen[iter->pos.offset];
-       alloc_data_type_set(&a_mut->v, a_mut->v.data_type);
 
        return bch2_trans_update(trans, iter, &a_mut->k_i, 0);
 }
index eb2ed4edbbbc89f1ed6dcdc9deda01750d9c1aa3..bbd37b1ed5d227adc4333bd51f09ba2ebf6b9766 100644 (file)
@@ -541,7 +541,8 @@ static int __mark_pointer(struct btree_trans *trans, struct bch_dev *ca,
                          struct bkey_s_c k,
                          const struct extent_ptr_decoded *p,
                          s64 sectors, enum bch_data_type ptr_data_type,
-                         struct bch_alloc_v4 *a)
+                         struct bch_alloc_v4 *a,
+                         bool insert)
 {
        u32 *dst_sectors = p->has_ec    ? &a->stripe_sectors :
                !p->ptr.cached          ? &a->dirty_sectors :
@@ -551,8 +552,8 @@ static int __mark_pointer(struct btree_trans *trans, struct bch_dev *ca,
 
        if (ret)
                return ret;
-
-       alloc_data_type_set(a, ptr_data_type);
+       if (insert)
+               alloc_data_type_set(a, ptr_data_type);
        return 0;
 }
 
@@ -585,7 +586,7 @@ static int bch2_trigger_pointer(struct btree_trans *trans,
        if (flags & BTREE_TRIGGER_transactional) {
                struct bkey_i_alloc_v4 *a = bch2_trans_start_alloc_update(trans, bucket, 0);
                ret = PTR_ERR_OR_ZERO(a) ?:
-                       __mark_pointer(trans, ca, k, &p, *sectors, bp.v.data_type, &a->v);
+                       __mark_pointer(trans, ca, k, &p, *sectors, bp.v.data_type, &a->v, insert);
                if (ret)
                        goto err;
 
@@ -607,7 +608,7 @@ static int bch2_trigger_pointer(struct btree_trans *trans,
 
                bucket_lock(g);
                struct bch_alloc_v4 old = bucket_m_to_alloc(*g), new = old;
-               ret = __mark_pointer(trans, ca, k, &p, *sectors, bp.v.data_type, &new);
+               ret = __mark_pointer(trans, ca, k, &p, *sectors, bp.v.data_type, &new, insert);
                alloc_to_bucket(g, new);
                bucket_unlock(g);