]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/alloc_background.h
rust: Fix ptr casting in Fs::open()
[bcachefs-tools-debian] / libbcachefs / alloc_background.h
index a0c3c47b49b5970a26ededf4269ecba87e30ddea..1aa7c7a023b3d5f7839adc2759bc6d649adb028f 100644 (file)
@@ -44,10 +44,10 @@ static inline enum bch_data_type __alloc_data_type(u32 dirty_sectors,
                                                   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 (stripe)
-               return BCH_DATA_stripe;
        if (cached_sectors)
                return BCH_DATA_cached;
        if (BCH_ALLOC_V4_NEED_DISCARD(&a))
@@ -64,11 +64,29 @@ static inline enum bch_data_type alloc_data_type(struct bch_alloc_v4 a,
                                 a.stripe, a, data_type);
 }
 
-static inline u64 alloc_lru_idx(struct bch_alloc_v4 a)
+static inline enum bch_data_type bucket_data_type(enum bch_data_type data_type)
+{
+       return data_type == BCH_DATA_stripe ? BCH_DATA_user : 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;
 }
 
+static inline u64 alloc_lru_idx_fragmentation(struct bch_alloc_v4 a,
+                                             struct bch_dev *ca)
+{
+       if (a.data_type != BCH_DATA_btree &&
+           a.data_type != BCH_DATA_user)
+               return 0;
+
+       if (a.dirty_sectors >= ca->mi.bucket_size)
+               return 0;
+
+       return div_u64((u64) a.dirty_sectors * (1ULL << 31), ca->mi.bucket_size);
+}
+
 static inline u64 alloc_freespace_genbits(struct bch_alloc_v4 a)
 {
        return ((u64) alloc_gc_gen(a) >> 4) << 56;
@@ -122,10 +140,10 @@ struct bkey_i_alloc_v4 *bch2_alloc_to_v4_mut(struct btree_trans *, struct bkey_s
 
 int bch2_bucket_io_time_reset(struct btree_trans *, unsigned, size_t, int);
 
-int bch2_alloc_v1_invalid(const struct bch_fs *, struct bkey_s_c, int, struct printbuf *);
-int bch2_alloc_v2_invalid(const struct bch_fs *, struct bkey_s_c, int, struct printbuf *);
-int bch2_alloc_v3_invalid(const struct bch_fs *, struct bkey_s_c, int, struct printbuf *);
-int bch2_alloc_v4_invalid(const struct bch_fs *, struct bkey_s_c, int, struct printbuf *);
+int bch2_alloc_v1_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
+int bch2_alloc_v2_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
+int bch2_alloc_v3_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
+int bch2_alloc_v4_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
 void bch2_alloc_v4_swab(struct bkey_s);
 void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 
@@ -158,7 +176,7 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
        .atomic_trigger = bch2_mark_alloc,              \
 })
 
-int bch2_bucket_gens_invalid(const struct bch_fs *, struct bkey_s_c, int, struct printbuf *);
+int bch2_bucket_gens_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
 void bch2_bucket_gens_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 
 #define bch2_bkey_ops_bucket_gens ((struct bkey_ops) { \