2019-07-10 23:12:15 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2017-10-06 01:41:44 +03:00
|
|
|
#ifndef _BCACHEFS_ALLOC_TYPES_H
|
|
|
|
#define _BCACHEFS_ALLOC_TYPES_H
|
2017-01-08 12:13:18 +03:00
|
|
|
|
|
|
|
#include <linux/mutex.h>
|
2017-11-22 08:42:55 +03:00
|
|
|
#include <linux/spinlock.h>
|
2017-01-08 12:13:18 +03:00
|
|
|
|
|
|
|
#include "clock_types.h"
|
2017-12-28 04:32:40 +03:00
|
|
|
#include "fifo.h"
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2018-11-23 11:04:34 +03:00
|
|
|
struct ec_bucket_buf;
|
|
|
|
|
2021-04-15 20:05:38 +03:00
|
|
|
#define ALLOC_THREAD_STATES() \
|
|
|
|
x(stopped) \
|
|
|
|
x(running) \
|
|
|
|
x(blocked) \
|
|
|
|
x(blocked_full)
|
|
|
|
|
|
|
|
enum allocator_states {
|
|
|
|
#define x(n) ALLOCATOR_##n,
|
|
|
|
ALLOC_THREAD_STATES()
|
|
|
|
#undef x
|
|
|
|
};
|
|
|
|
|
2017-01-08 12:13:18 +03:00
|
|
|
enum alloc_reserve {
|
2021-01-08 03:49:15 +03:00
|
|
|
RESERVE_BTREE_MOVINGGC = -2,
|
|
|
|
RESERVE_BTREE = -1,
|
|
|
|
RESERVE_MOVINGGC = 0,
|
|
|
|
RESERVE_NONE = 1,
|
|
|
|
RESERVE_NR = 2,
|
2017-01-08 12:13:18 +03:00
|
|
|
};
|
|
|
|
|
2017-12-28 04:32:40 +03:00
|
|
|
typedef FIFO(long) alloc_fifo;
|
|
|
|
|
2020-06-14 02:31:45 +03:00
|
|
|
#define OPEN_BUCKETS_COUNT 1024
|
2018-11-05 06:18:23 +03:00
|
|
|
|
|
|
|
#define WRITE_POINT_HASH_NR 32
|
|
|
|
#define WRITE_POINT_MAX 32
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2020-06-14 02:31:45 +03:00
|
|
|
typedef u16 open_bucket_idx_t;
|
|
|
|
|
2017-01-08 12:13:18 +03:00
|
|
|
struct open_bucket {
|
2017-11-22 08:42:55 +03:00
|
|
|
spinlock_t lock;
|
2017-01-08 12:13:18 +03:00
|
|
|
atomic_t pin;
|
2020-06-14 02:31:45 +03:00
|
|
|
open_bucket_idx_t freelist;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When an open bucket has an ec_stripe attached, this is the index of
|
|
|
|
* the block in the stripe this open_bucket corresponds to:
|
|
|
|
*/
|
2018-11-23 11:04:34 +03:00
|
|
|
u8 ec_idx;
|
2019-01-23 23:49:44 +03:00
|
|
|
u8 type;
|
|
|
|
unsigned valid:1;
|
|
|
|
unsigned on_partial_list:1;
|
2020-08-24 23:05:04 +03:00
|
|
|
int alloc_reserve:3;
|
2017-12-14 00:01:18 +03:00
|
|
|
unsigned sectors_free;
|
|
|
|
struct bch_extent_ptr ptr;
|
2018-11-23 11:04:34 +03:00
|
|
|
struct ec_stripe_new *ec;
|
2017-01-08 12:13:18 +03:00
|
|
|
};
|
|
|
|
|
2018-10-12 21:55:27 +03:00
|
|
|
#define OPEN_BUCKET_LIST_MAX 15
|
|
|
|
|
|
|
|
struct open_buckets {
|
2020-06-14 02:31:45 +03:00
|
|
|
open_bucket_idx_t nr;
|
|
|
|
open_bucket_idx_t v[OPEN_BUCKET_LIST_MAX];
|
2018-10-12 21:55:27 +03:00
|
|
|
};
|
|
|
|
|
2018-11-23 11:04:34 +03:00
|
|
|
struct dev_stripe_state {
|
|
|
|
u64 next_alloc[BCH_SB_MEMBERS_MAX];
|
|
|
|
};
|
|
|
|
|
2017-01-08 12:13:18 +03:00
|
|
|
struct write_point {
|
2017-11-22 08:42:55 +03:00
|
|
|
struct hlist_node node;
|
|
|
|
struct mutex lock;
|
|
|
|
u64 last_used;
|
|
|
|
unsigned long write_point;
|
2017-10-06 01:41:44 +03:00
|
|
|
enum bch_data_type type;
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2017-11-22 08:42:55 +03:00
|
|
|
/* calculated based on how many pointers we're actually going to use: */
|
|
|
|
unsigned sectors_free;
|
2017-10-06 01:41:44 +03:00
|
|
|
|
2018-10-12 21:55:27 +03:00
|
|
|
struct open_buckets ptrs;
|
2018-11-23 11:04:34 +03:00
|
|
|
struct dev_stripe_state stripe;
|
2017-01-08 12:13:18 +03:00
|
|
|
};
|
|
|
|
|
2017-12-14 00:01:18 +03:00
|
|
|
struct write_point_specifier {
|
|
|
|
unsigned long v;
|
|
|
|
};
|
|
|
|
|
2017-05-05 12:49:48 +03:00
|
|
|
struct alloc_heap_entry {
|
|
|
|
size_t bucket;
|
2018-04-11 02:19:09 +03:00
|
|
|
size_t nr;
|
2017-05-05 12:49:48 +03:00
|
|
|
unsigned long key;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef HEAP(struct alloc_heap_entry) alloc_heap;
|
|
|
|
|
2017-10-06 01:41:44 +03:00
|
|
|
#endif /* _BCACHEFS_ALLOC_TYPES_H */
|