]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/alloc_types.h
Update bcachefs sources to dab31ca168 bcachefs: Add some logging for btree node rewri...
[bcachefs-tools-debian] / libbcachefs / alloc_types.h
index be164d6108bbcdbb3f2ca48bf8e6dc0618d4b6a8..2e6f4806925871bf513f17235e6680e067e4471f 100644 (file)
@@ -8,41 +8,58 @@
 #include "clock_types.h"
 #include "fifo.h"
 
+struct bucket_alloc_state {
+       u64     buckets_seen;
+       u64     skipped_open;
+       u64     skipped_need_journal_commit;
+       u64     skipped_nocow;
+       u64     skipped_nouse;
+};
+
 struct ec_bucket_buf;
 
+#define BCH_ALLOC_RESERVES()           \
+       x(btree_movinggc)               \
+       x(btree)                        \
+       x(movinggc)                     \
+       x(none)
+
 enum alloc_reserve {
-       RESERVE_BTREE_MOVINGGC  = -2,
-       RESERVE_BTREE           = -1,
-       RESERVE_MOVINGGC        = 0,
-       RESERVE_NONE            = 1,
-       RESERVE_NR              = 2,
+#define x(name)        RESERVE_##name,
+       BCH_ALLOC_RESERVES()
+#undef x
 };
 
-typedef FIFO(long)     alloc_fifo;
-
 #define OPEN_BUCKETS_COUNT     1024
 
 #define WRITE_POINT_HASH_NR    32
 #define WRITE_POINT_MAX                32
 
+/*
+ * 0 is never a valid open_bucket_idx_t:
+ */
 typedef u16                    open_bucket_idx_t;
 
 struct open_bucket {
        spinlock_t              lock;
        atomic_t                pin;
        open_bucket_idx_t       freelist;
+       open_bucket_idx_t       hash;
 
        /*
         * When an open bucket has an ec_stripe attached, this is the index of
         * the block in the stripe this open_bucket corresponds to:
         */
        u8                      ec_idx;
-       u8                      type;
+       enum bch_data_type      data_type:8;
        unsigned                valid:1;
        unsigned                on_partial_list:1;
-       int                     alloc_reserve:3;
-       unsigned                sectors_free;
-       struct bch_extent_ptr   ptr;
+       unsigned                alloc_reserve:3;
+
+       u8                      dev;
+       u8                      gen;
+       u32                     sectors_free;
+       u64                     bucket;
        struct ec_stripe_new    *ec;
 };
 
@@ -57,30 +74,50 @@ struct dev_stripe_state {
        u64                     next_alloc[BCH_SB_MEMBERS_MAX];
 };
 
+#define WRITE_POINT_STATES()           \
+       x(stopped)                      \
+       x(waiting_io)                   \
+       x(waiting_work)                 \
+       x(running)
+
+enum write_point_state {
+#define x(n)   WRITE_POINT_##n,
+       WRITE_POINT_STATES()
+#undef x
+       WRITE_POINT_STATE_NR
+};
+
 struct write_point {
-       struct hlist_node       node;
-       struct mutex            lock;
-       u64                     last_used;
-       unsigned long           write_point;
-       enum bch_data_type      type;
+       struct {
+               struct hlist_node       node;
+               struct mutex            lock;
+               u64                     last_used;
+               unsigned long           write_point;
+               enum bch_data_type      data_type;
 
-       /* calculated based on how many pointers we're actually going to use: */
-       unsigned                sectors_free;
+               /* calculated based on how many pointers we're actually going to use: */
+               unsigned                sectors_free;
 
-       struct open_buckets     ptrs;
-       struct dev_stripe_state stripe;
+               struct open_buckets     ptrs;
+               struct dev_stripe_state stripe;
+
+               u64                     sectors_allocated;
+       } __attribute__((__aligned__(SMP_CACHE_BYTES)));
+
+       struct {
+               struct work_struct      index_update_work;
+
+               struct list_head        writes;
+               spinlock_t              writes_lock;
+
+               enum write_point_state  state;
+               u64                     last_state_change;
+               u64                     time[WRITE_POINT_STATE_NR];
+       } __attribute__((__aligned__(SMP_CACHE_BYTES)));
 };
 
 struct write_point_specifier {
        unsigned long           v;
 };
 
-struct alloc_heap_entry {
-       size_t                  bucket;
-       size_t                  nr;
-       unsigned long           key;
-};
-
-typedef HEAP(struct alloc_heap_entry) alloc_heap;
-
 #endif /* _BCACHEFS_ALLOC_TYPES_H */