X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libbcachefs%2Falloc_types.h;h=b91b7a46105608d089828db3bd65d1cc359475af;hb=46d51608693bddac162232133516e975f3b1e835;hp=66457fc722fd5ec2cbb1ec9312e515661ae5f7b8;hpb=35fca2f044d375b1590f499cfd34bef38ca0f8f1;p=bcachefs-tools-debian diff --git a/libbcachefs/alloc_types.h b/libbcachefs/alloc_types.h index 66457fc..b91b7a4 100644 --- a/libbcachefs/alloc_types.h +++ b/libbcachefs/alloc_types.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _BCACHEFS_ALLOC_TYPES_H #define _BCACHEFS_ALLOC_TYPES_H @@ -7,99 +8,119 @@ #include "clock_types.h" #include "fifo.h" -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. - * - * Goes with the bucket read/write prios: when we read or write to a - * bucket we reset the bucket's prio to the current hand; thus hand - - * prio = time since bucket was last read/written. - * - * The units are some amount (bytes/sectors) of data read/written, and - * the units can change on the fly if we need to rescale to fit - * everything in a u16 - your only guarantee is that the units are - * consistent. - */ - u16 hand; - u16 max_last_io; - - int rw; - - struct io_timer rescale; - struct mutex lock; +struct bucket_alloc_state { + u64 buckets_seen; + u64 skipped_open; + u64 skipped_need_journal_commit; + u64 skipped_nocow; + u64 skipped_nouse; }; -/* There is one reserve for each type of btree, one for prios and gens - * and one for moving GC */ -enum alloc_reserve { - RESERVE_ALLOC = -1, - RESERVE_BTREE = 0, - RESERVE_MOVINGGC = 1, - RESERVE_NONE = 2, - RESERVE_NR = 3, +#define BCH_WATERMARKS() \ + x(stripe) \ + x(normal) \ + x(copygc) \ + x(btree) \ + x(btree_copygc) \ + x(reclaim) + +enum bch_watermark { +#define x(name) BCH_WATERMARK_##name, + BCH_WATERMARKS() +#undef x + BCH_WATERMARK_NR, }; -typedef FIFO(long) alloc_fifo; +#define BCH_WATERMARK_BITS 3 +#define BCH_WATERMARK_MASK ~(~0U << BCH_WATERMARK_BITS) -/* Enough for 16 cache devices, 2 tiers and some left over for pipelining */ -#define OPEN_BUCKETS_COUNT 256 +#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; - u8 freelist; + 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:6; unsigned valid:1; unsigned on_partial_list:1; - unsigned sectors_free; - struct bch_extent_ptr ptr; + + u8 dev; + u8 gen; + u32 sectors_free; + u64 bucket; struct ec_stripe_new *ec; }; #define OPEN_BUCKET_LIST_MAX 15 struct open_buckets { - u8 nr; - u8 v[OPEN_BUCKET_LIST_MAX]; + 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]; }; +#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; - bool is_ec; - - /* 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 { + 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; + + struct open_buckets ptrs; + struct dev_stripe_state stripe; + + u64 sectors_allocated; + } __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]; + } __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 */