diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-10-06 04:12:42 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:10 -0400 |
commit | ef337c54c6d18d4c6ce0aef8f4f327d4cf42ae08 (patch) | |
tree | d27014f83c04d4b29a57b721b3451deea8b546ca /fs/bcachefs/alloc_types.h | |
parent | 7b3f84ea7d3f9bcbb7f0f1264a4c228a27a32703 (diff) |
bcachefs: Allocation code refactoring
bch2_alloc_sectors_start() was a nightmare to work with - it's got some
tricky stuff to do, since it wants to use the buckets the writepoint
already has, unless they're not in the target it wants to write to,
unless it can't allocate from any other devices in which case it will
use those buckets if it has to - et cetera.
This restructures the code to start with a new empty list of open
buckets we're going to use for the new allocation, pulling buckets from
the write point's list as we decide that we really are going to use
them - making the code somewhat more functional and drastically easier
to understand.
Also fixes a bug where we could end up waiting on c->freelist_wait
(because allocating from one device failed) but return success from
bch2_bucket_alloc(), because allocating from a different device
succeeded.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/alloc_types.h')
-rw-r--r-- | fs/bcachefs/alloc_types.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/bcachefs/alloc_types.h b/fs/bcachefs/alloc_types.h index 035c50052167..e0306d68ae9f 100644 --- a/fs/bcachefs/alloc_types.h +++ b/fs/bcachefs/alloc_types.h @@ -58,6 +58,13 @@ struct open_bucket { struct bch_extent_ptr ptr; }; +#define OPEN_BUCKET_LIST_MAX 15 + +struct open_buckets { + u8 nr; + u8 v[OPEN_BUCKET_LIST_MAX]; +}; + struct write_point { struct hlist_node node; struct mutex lock; @@ -65,13 +72,10 @@ struct write_point { unsigned long write_point; enum bch_data_type type; - u8 nr_ptrs; - u8 first_ptr; - /* calculated based on how many pointers we're actually going to use: */ unsigned sectors_free; - struct open_bucket *ptrs[BCH_REPLICAS_MAX * 2]; + struct open_buckets ptrs; u64 next_alloc[BCH_SB_MEMBERS_MAX]; }; |