]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/alloc_types.h
Update bcachefs sources to 4837f82ee1 bcachefs: Use cached iterators for alloc btree
[bcachefs-tools-debian] / libbcachefs / alloc_types.h
index bee6d28daea9e93a4b5d94adc87d905d7a4fc126..4f14650779947f8c854a5bf16782aaa1d277ee5b 100644 (file)
@@ -1,16 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _BCACHEFS_ALLOC_TYPES_H
 #define _BCACHEFS_ALLOC_TYPES_H
 
 #include <linux/mutex.h>
+#include <linux/spinlock.h>
 
 #include "clock_types.h"
+#include "fifo.h"
 
-/*
- * There's two of these clocks, one for reads and one for writes:
- *
- * All fields protected by bucket_lock
- */
-struct prio_clock {
+struct ec_bucket_buf;
+
+/* There's two of these clocks, one for reads and one for writes: */
+struct bucket_clock {
        /*
         * "now" in (read/write) IO time - incremented whenever we do X amount
         * of reads or writes.
@@ -25,11 +26,12 @@ struct prio_clock {
         * consistent.
         */
        u16                     hand;
-       u16                     min_prio;
+       u16                     max_last_io;
 
        int                     rw;
 
        struct io_timer         rescale;
+       struct mutex            lock;
 };
 
 /* There is one reserve for each type of btree, one for prios and gens
@@ -42,46 +44,66 @@ enum alloc_reserve {
        RESERVE_NR              = 3,
 };
 
-/* Enough for 16 cache devices, 2 tiers and some left over for pipelining */
-#define OPEN_BUCKETS_COUNT     256
+typedef FIFO(long)     alloc_fifo;
+
+#define OPEN_BUCKETS_COUNT     1024
 
-#define WRITE_POINT_COUNT      16
+#define WRITE_POINT_HASH_NR    32
+#define WRITE_POINT_MAX                32
+
+typedef u16                    open_bucket_idx_t;
 
 struct open_bucket {
-       struct list_head        list;
-       struct mutex            lock;
+       spinlock_t              lock;
        atomic_t                pin;
-       bool                    has_full_ptrs;
-       u8                      new_ob;
+       open_bucket_idx_t       freelist;
 
        /*
-        * recalculated every time we allocate from this open_bucket based on
-        * how many pointers we're actually going to use:
+        * 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;
+       unsigned                valid:1;
+       unsigned                on_partial_list:1;
        unsigned                sectors_free;
-       unsigned                nr_ptrs;
-       struct bch_extent_ptr   ptrs[BCH_REPLICAS_MAX];
-       unsigned                ptr_offset[BCH_REPLICAS_MAX];
+       struct bch_extent_ptr   ptr;
+       struct ec_stripe_new    *ec;
+};
+
+#define OPEN_BUCKET_LIST_MAX   15
+
+struct open_buckets {
+       open_bucket_idx_t       nr;
+       open_bucket_idx_t       v[OPEN_BUCKET_LIST_MAX];
+};
+
+struct dev_stripe_state {
+       u64                     next_alloc[BCH_SB_MEMBERS_MAX];
 };
 
 struct write_point {
-       struct open_bucket      *b;
+       struct hlist_node       node;
+       struct mutex            lock;
+       u64                     last_used;
+       unsigned long           write_point;
        enum bch_data_type      type;
+       bool                    is_ec;
 
-       /*
-        * If not NULL, cache group for tiering, promotion and moving GC -
-        * always allocates a single replica
-        *
-        * Otherwise do a normal replicated bucket allocation that could come
-        * from any device in tier 0 (foreground write)
-        */
-       struct bch_devs_mask    *group;
+       /* calculated based on how many pointers we're actually going to use: */
+       unsigned                sectors_free;
 
-       u64                     next_alloc[BCH_SB_MEMBERS_MAX];
+       struct open_buckets     ptrs;
+       struct dev_stripe_state stripe;
+};
+
+struct write_point_specifier {
+       unsigned long           v;
 };
 
 struct alloc_heap_entry {
        size_t                  bucket;
+       size_t                  nr;
        unsigned long           key;
 };