diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-12-11 05:24:36 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:09:18 +0300 |
commit | 20572300dcc537c22b435a1f01b810a9d7c140c9 (patch) | |
tree | 64d4859c40c84524fd33d878d1460f5f7a5cdef4 /fs/bcachefs/alloc_background.h | |
parent | fb0e480872ac858d836d5d6d713d0f31ae08c64d (diff) | |
download | linux-20572300dcc537c22b435a1f01b810a9d7c140c9.tar.xz |
bcachefs: Improve alloc_mem_to_key()
This moves some common code into alloc_mem_to_key(), which translates
from the in-memory format for a bucket to the btree key format.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/alloc_background.h')
-rw-r--r-- | fs/bcachefs/alloc_background.h | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h index 6698d9c75d07..e3cdb8bc1dd8 100644 --- a/fs/bcachefs/alloc_background.h +++ b/fs/bcachefs/alloc_background.h @@ -4,7 +4,9 @@ #include "bcachefs.h" #include "alloc_types.h" +#include "buckets.h" #include "debug.h" +#include "super.h" extern const char * const bch2_allocator_states[]; @@ -43,22 +45,31 @@ int bch2_alloc_write(struct btree_trans *, struct btree_iter *, int bch2_bucket_io_time_reset(struct btree_trans *, unsigned, size_t, int); static inline struct bkey_alloc_unpacked -alloc_mem_to_key(struct btree_iter *iter, - struct bucket *g, struct bucket_mark m) +alloc_mem_to_key(struct bch_fs *c, struct btree_iter *iter) { - return (struct bkey_alloc_unpacked) { + struct bch_dev *ca; + struct bucket *g; + struct bkey_alloc_unpacked ret; + + percpu_down_read(&c->mark_lock); + ca = bch_dev_bkey_exists(c, iter->pos.inode); + g = bucket(ca, iter->pos.offset); + ret = (struct bkey_alloc_unpacked) { .dev = iter->pos.inode, .bucket = iter->pos.offset, - .gen = m.gen, + .gen = g->mark.gen, .oldest_gen = g->oldest_gen, - .data_type = m.data_type, - .dirty_sectors = m.dirty_sectors, - .cached_sectors = m.cached_sectors, + .data_type = g->mark.data_type, + .dirty_sectors = g->mark.dirty_sectors, + .cached_sectors = g->mark.cached_sectors, .read_time = g->io_time[READ], .write_time = g->io_time[WRITE], .stripe = g->stripe, .stripe_redundancy = g->stripe_redundancy, }; + percpu_up_read(&c->mark_lock); + + return ret; } #define ALLOC_SCAN_BATCH(ca) max_t(size_t, 1, (ca)->mi.nbuckets >> 9) |