2017-03-17 06:18:50 +00:00
|
|
|
/* 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"
|
|
|
|
|
2022-11-04 20:06:55 +00:00
|
|
|
struct bucket_alloc_state {
|
2024-04-20 20:25:34 +00:00
|
|
|
enum {
|
|
|
|
BTREE_BITMAP_NO,
|
|
|
|
BTREE_BITMAP_YES,
|
|
|
|
BTREE_BITMAP_ANY,
|
|
|
|
} btree_bitmap;
|
|
|
|
|
2022-11-04 20:06:55 +00:00
|
|
|
u64 buckets_seen;
|
|
|
|
u64 skipped_open;
|
|
|
|
u64 skipped_need_journal_commit;
|
bcachefs: Nocow support
This adds support for nocow mode, where we do writes in-place when
possible. Patch components:
- New boolean filesystem and inode option, nocow: note that when nocow
is enabled, data checksumming and compression are implicitly disabled
- To prevent in-place writes from racing with data moves
(data_update.c) or bucket reuse (i.e. a bucket being reused and
re-allocated while a nocow write is in flight, we have a new locking
mechanism.
Buckets can be locked for either data update or data move, using a
fixed size hash table of two_state_shared locks. We don't have any
chaining, meaning updates and moves to different buckets that hash to
the same lock will wait unnecessarily - we'll want to watch for this
becoming an issue.
- The allocator path also needs to check for in-place writes in flight
to a given bucket before giving it out: thus we add another counter
to bucket_alloc_state so we can track this.
- Fsync now may need to issue cache flushes to block devices instead of
flushing the journal. We add a device bitmask to bch_inode_info,
ei_devs_need_flush, which tracks devices that need to have flushes
issued - note that this will lead to unnecessary flushes when other
codepaths have already issued flushes, we may want to replace this with
a sequence number.
- New nocow write path: look up extents, and if they're writable write
to them - otherwise fall back to the normal COW write path.
XXX: switch to sequence numbers instead of bitmask for devs needing
journal flush
XXX: ei_quota_lock being a mutex means bch2_nocow_write_done() needs to
run in process context - see if we can improve this
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2022-11-02 21:12:00 +00:00
|
|
|
u64 skipped_nocow;
|
2022-11-04 20:06:55 +00:00
|
|
|
u64 skipped_nouse;
|
2024-04-20 20:25:34 +00:00
|
|
|
u64 skipped_mi_btree_bitmap;
|
2022-11-04 20:06:55 +00:00
|
|
|
};
|
|
|
|
|
2023-06-24 23:30:10 +00:00
|
|
|
#define BCH_WATERMARKS() \
|
2023-06-27 21:32:38 +00:00
|
|
|
x(stripe) \
|
2023-06-24 23:30:10 +00:00
|
|
|
x(normal) \
|
2023-06-27 21:32:38 +00:00
|
|
|
x(copygc) \
|
|
|
|
x(btree) \
|
|
|
|
x(btree_copygc) \
|
2024-04-01 23:20:36 +00:00
|
|
|
x(reclaim) \
|
|
|
|
x(interior_updates)
|
2022-03-13 23:27:55 +00:00
|
|
|
|
2023-06-24 23:30:10 +00:00
|
|
|
enum bch_watermark {
|
|
|
|
#define x(name) BCH_WATERMARK_##name,
|
|
|
|
BCH_WATERMARKS()
|
2022-03-13 23:27:55 +00:00
|
|
|
#undef x
|
2023-06-24 23:30:10 +00:00
|
|
|
BCH_WATERMARK_NR,
|
2017-03-17 06:18:50 +00:00
|
|
|
};
|
|
|
|
|
2023-06-27 21:32:38 +00:00
|
|
|
#define BCH_WATERMARK_BITS 3
|
2023-08-02 00:06:45 +00:00
|
|
|
#define BCH_WATERMARK_MASK ~(~0U << BCH_WATERMARK_BITS)
|
2023-06-27 21:32:38 +00:00
|
|
|
|
2020-06-09 19:44:03 +00:00
|
|
|
#define OPEN_BUCKETS_COUNT 1024
|
2018-11-05 02:55:35 +00:00
|
|
|
|
|
|
|
#define WRITE_POINT_HASH_NR 32
|
|
|
|
#define WRITE_POINT_MAX 32
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2021-12-26 02:43:29 +00:00
|
|
|
/*
|
|
|
|
* 0 is never a valid open_bucket_idx_t:
|
|
|
|
*/
|
2020-06-09 19:44:03 +00:00
|
|
|
typedef u16 open_bucket_idx_t;
|
|
|
|
|
2017-03-17 06:18:50 +00:00
|
|
|
struct open_bucket {
|
|
|
|
spinlock_t lock;
|
|
|
|
atomic_t pin;
|
2020-06-09 19:44:03 +00:00
|
|
|
open_bucket_idx_t freelist;
|
2021-12-26 02:43:29 +00:00
|
|
|
open_bucket_idx_t hash;
|
2020-06-09 19:44:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-01 19:13:19 +00:00
|
|
|
u8 ec_idx;
|
2023-02-25 07:22:49 +00:00
|
|
|
enum bch_data_type data_type:6;
|
2019-01-19 18:13:29 +00:00
|
|
|
unsigned valid:1;
|
|
|
|
unsigned on_partial_list:1;
|
2021-12-26 02:21:46 +00:00
|
|
|
|
|
|
|
u8 dev;
|
|
|
|
u8 gen;
|
2022-04-01 05:29:59 +00:00
|
|
|
u32 sectors_free;
|
2021-12-26 02:21:46 +00:00
|
|
|
u64 bucket;
|
2018-11-01 19:13:19 +00:00
|
|
|
struct ec_stripe_new *ec;
|
2017-03-17 06:18:50 +00:00
|
|
|
};
|
|
|
|
|
2018-10-06 08:12:42 +00:00
|
|
|
#define OPEN_BUCKET_LIST_MAX 15
|
|
|
|
|
|
|
|
struct open_buckets {
|
2020-06-09 19:44:03 +00:00
|
|
|
open_bucket_idx_t nr;
|
|
|
|
open_bucket_idx_t v[OPEN_BUCKET_LIST_MAX];
|
2018-10-06 08:12:42 +00:00
|
|
|
};
|
|
|
|
|
2018-11-01 19:13:19 +00:00
|
|
|
struct dev_stripe_state {
|
|
|
|
u64 next_alloc[BCH_SB_MEMBERS_MAX];
|
|
|
|
};
|
|
|
|
|
2022-10-31 20:13:05 +00:00
|
|
|
#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
|
|
|
|
};
|
|
|
|
|
2017-03-17 06:18:50 +00:00
|
|
|
struct write_point {
|
2022-10-31 20:13:05 +00:00
|
|
|
struct {
|
|
|
|
struct hlist_node node;
|
|
|
|
struct mutex lock;
|
|
|
|
u64 last_used;
|
|
|
|
unsigned long write_point;
|
|
|
|
enum bch_data_type data_type;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2022-10-31 20:13:05 +00:00
|
|
|
/* 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;
|
2023-08-07 16:04:05 +00:00
|
|
|
} __aligned(SMP_CACHE_BYTES);
|
2022-10-31 20:13:05 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct work_struct index_update_work;
|
|
|
|
|
|
|
|
struct list_head writes;
|
|
|
|
spinlock_t writes_lock;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2022-10-31 20:13:05 +00:00
|
|
|
enum write_point_state state;
|
|
|
|
u64 last_state_change;
|
|
|
|
u64 time[WRITE_POINT_STATE_NR];
|
2023-08-07 16:04:05 +00:00
|
|
|
} __aligned(SMP_CACHE_BYTES);
|
2017-03-17 06:18:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct write_point_specifier {
|
|
|
|
unsigned long v;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _BCACHEFS_ALLOC_TYPES_H */
|