bcachefs: alloc_data_type_set()
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 30 Apr 2024 06:47:30 +0000 (02:47 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 8 May 2024 21:29:21 +0000 (17:29 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/alloc_background.h
fs/bcachefs/btree_gc.c
fs/bcachefs/ec.c

index 37e8446b30395961eb997a6a4a8fd0424d67f41f..bbd85f1e59735327fd6babb0fc0be8dc43bebb15 100644 (file)
@@ -741,7 +741,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
        if (flags & BTREE_TRIGGER_transactional) {
                struct bch_alloc_v4 *new_a = bkey_s_to_alloc_v4(new).v;
 
-               new_a->data_type = alloc_data_type(*new_a, new_a->data_type);
+               alloc_data_type_set(new_a, new_a->data_type);
 
                if (bch2_bucket_sectors(*new_a) > bch2_bucket_sectors(*old_a)) {
                        new_a->io_time[READ] = max_t(u64, 1, atomic64_read(&c->io_clock[READ].now));
@@ -1761,7 +1761,7 @@ static int bch2_discard_one_bucket(struct btree_trans *trans,
        }
 
        SET_BCH_ALLOC_V4_NEED_DISCARD(&a->v, false);
-       a->v.data_type = alloc_data_type(a->v, a->v.data_type);
+       alloc_data_type_set(&a->v, a->v.data_type);
 write:
        ret =   bch2_trans_update(trans, &iter, &a->k_i, 0) ?:
                bch2_trans_commit(trans, NULL, NULL,
@@ -1830,7 +1830,7 @@ static int bch2_clear_bucket_needs_discard(struct btree_trans *trans, struct bpo
 
        BUG_ON(a->v.dirty_sectors);
        SET_BCH_ALLOC_V4_NEED_DISCARD(&a->v, false);
-       a->v.data_type = alloc_data_type(a->v, a->v.data_type);
+       alloc_data_type_set(&a->v, a->v.data_type);
 
        ret = bch2_trans_update(trans, &iter, &a->k_i, 0);
 err:
index e0e0d72db03bcbb2046f453ba65e8d0d9934d4cd..98ba934c352f7cfe3dda8498bbba6b59bed61dbc 100644 (file)
@@ -39,32 +39,6 @@ static inline u8 alloc_gc_gen(struct bch_alloc_v4 a)
        return a.gen - a.oldest_gen;
 }
 
-static inline enum bch_data_type __alloc_data_type(u32 dirty_sectors,
-                                                  u32 cached_sectors,
-                                                  u32 stripe,
-                                                  struct bch_alloc_v4 a,
-                                                  enum bch_data_type data_type)
-{
-       if (stripe)
-               return data_type == BCH_DATA_parity ? data_type : BCH_DATA_stripe;
-       if (dirty_sectors)
-               return data_type;
-       if (cached_sectors)
-               return BCH_DATA_cached;
-       if (BCH_ALLOC_V4_NEED_DISCARD(&a))
-               return BCH_DATA_need_discard;
-       if (alloc_gc_gen(a) >= BUCKET_GC_GEN_MAX)
-               return BCH_DATA_need_gc_gens;
-       return BCH_DATA_free;
-}
-
-static inline enum bch_data_type alloc_data_type(struct bch_alloc_v4 a,
-                                                enum bch_data_type data_type)
-{
-       return __alloc_data_type(a.dirty_sectors, a.cached_sectors,
-                                a.stripe, a, data_type);
-}
-
 static inline enum bch_data_type bucket_data_type(enum bch_data_type data_type)
 {
        switch (data_type) {
@@ -101,6 +75,37 @@ static inline unsigned bch2_bucket_sectors_fragmented(struct bch_dev *ca,
        return d ? max(0, ca->mi.bucket_size - d) : 0;
 }
 
+static inline enum bch_data_type __alloc_data_type(u32 dirty_sectors,
+                                                  u32 cached_sectors,
+                                                  u32 stripe,
+                                                  struct bch_alloc_v4 a,
+                                                  enum bch_data_type data_type)
+{
+       if (stripe)
+               return data_type == BCH_DATA_parity ? data_type : BCH_DATA_stripe;
+       if (dirty_sectors)
+               return data_type;
+       if (cached_sectors)
+               return BCH_DATA_cached;
+       if (BCH_ALLOC_V4_NEED_DISCARD(&a))
+               return BCH_DATA_need_discard;
+       if (alloc_gc_gen(a) >= BUCKET_GC_GEN_MAX)
+               return BCH_DATA_need_gc_gens;
+       return BCH_DATA_free;
+}
+
+static inline enum bch_data_type alloc_data_type(struct bch_alloc_v4 a,
+                                                enum bch_data_type data_type)
+{
+       return __alloc_data_type(a.dirty_sectors, a.cached_sectors,
+                                a.stripe, a, data_type);
+}
+
+static inline void alloc_data_type_set(struct bch_alloc_v4 *a, enum bch_data_type data_type)
+{
+       a->data_type = alloc_data_type(*a, data_type);
+}
+
 static inline u64 alloc_lru_idx_read(struct bch_alloc_v4 a)
 {
        return a.data_type == BCH_DATA_cached ? a.io_time[READ] : 0;
index c9dfcf3cd199f9ceff4dd792a3d8b5aaef0faf16..ef325ff71f89c279c0eaf6d840f73f46c5457bd3 100644 (file)
@@ -1307,7 +1307,7 @@ static int bch2_alloc_write_oldest_gen(struct btree_trans *trans, struct btree_i
                return ret;
 
        a_mut->v.oldest_gen = ca->oldest_gen[iter->pos.offset];
-       a_mut->v.data_type = alloc_data_type(a_mut->v, a_mut->v.data_type);
+       alloc_data_type_set(&a_mut->v, a_mut->v.data_type);
 
        return bch2_trans_update(trans, iter, &a_mut->k_i, 0);
 }
index d6fa7e0bb2666eedb5ba93b9c01deafcb1d7b0c7..a4ae39b10e98ee37c7758913edf0bb5cf9d750f9 100644 (file)
@@ -290,7 +290,7 @@ static int mark_stripe_bucket(struct btree_trans *trans,
                        goto err;
 
                if (deleting)
-                       a->v.data_type = alloc_data_type(a->v, BCH_DATA_user);
+                       alloc_data_type_set(&a->v, BCH_DATA_user);
 
                ret = bch2_trans_update(trans, &iter, &a->k_i, 0);
                if (ret)