mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-01 06:33:07 +00:00
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>
This commit is contained in:
parent
fb0e480872
commit
20572300dc
3 changed files with 25 additions and 40 deletions
|
@ -393,9 +393,6 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
|
|||
{
|
||||
struct bch_fs *c = trans->c;
|
||||
struct bkey_s_c k;
|
||||
struct bch_dev *ca;
|
||||
struct bucket *g;
|
||||
struct bucket_mark m;
|
||||
struct bkey_alloc_unpacked old_u, new_u;
|
||||
int ret;
|
||||
retry:
|
||||
|
@ -412,13 +409,7 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
|
|||
goto err;
|
||||
|
||||
old_u = bch2_alloc_unpack(k);
|
||||
|
||||
percpu_down_read(&c->mark_lock);
|
||||
ca = bch_dev_bkey_exists(c, iter->pos.inode);
|
||||
g = bucket(ca, iter->pos.offset);
|
||||
m = READ_ONCE(g->mark);
|
||||
new_u = alloc_mem_to_key(iter, g, m);
|
||||
percpu_up_read(&c->mark_lock);
|
||||
new_u = alloc_mem_to_key(c, iter);
|
||||
|
||||
if (!bkey_alloc_unpacked_cmp(old_u, new_u))
|
||||
return 0;
|
||||
|
@ -470,9 +461,7 @@ int bch2_bucket_io_time_reset(struct btree_trans *trans, unsigned dev,
|
|||
size_t bucket_nr, int rw)
|
||||
{
|
||||
struct bch_fs *c = trans->c;
|
||||
struct bch_dev *ca = bch_dev_bkey_exists(c, dev);
|
||||
struct btree_iter iter;
|
||||
struct bucket *g;
|
||||
struct bkey_alloc_unpacked u;
|
||||
u64 *time, now;
|
||||
int ret = 0;
|
||||
|
@ -485,10 +474,7 @@ int bch2_bucket_io_time_reset(struct btree_trans *trans, unsigned dev,
|
|||
if (ret)
|
||||
goto out;
|
||||
|
||||
percpu_down_read(&c->mark_lock);
|
||||
g = bucket(ca, bucket_nr);
|
||||
u = alloc_mem_to_key(&iter, g, READ_ONCE(g->mark));
|
||||
percpu_up_read(&c->mark_lock);
|
||||
u = alloc_mem_to_key(c, &iter);
|
||||
|
||||
time = rw == READ ? &u.read_time : &u.write_time;
|
||||
now = atomic64_read(&c->io_clock[rw].now);
|
||||
|
@ -766,8 +752,6 @@ static int bucket_invalidate_btree(struct btree_trans *trans,
|
|||
{
|
||||
struct bch_fs *c = trans->c;
|
||||
struct bkey_alloc_unpacked u;
|
||||
struct bucket *g;
|
||||
struct bucket_mark m;
|
||||
struct btree_iter iter;
|
||||
int ret;
|
||||
|
||||
|
@ -781,11 +765,7 @@ static int bucket_invalidate_btree(struct btree_trans *trans,
|
|||
if (ret)
|
||||
goto err;
|
||||
|
||||
percpu_down_read(&c->mark_lock);
|
||||
g = bucket(ca, b);
|
||||
m = READ_ONCE(g->mark);
|
||||
u = alloc_mem_to_key(&iter, g, m);
|
||||
percpu_up_read(&c->mark_lock);
|
||||
u = alloc_mem_to_key(c, &iter);
|
||||
|
||||
u.gen++;
|
||||
u.data_type = 0;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1492,7 +1492,6 @@ static int bch2_trans_start_alloc_update(struct btree_trans *trans, struct btree
|
|||
struct bch_fs *c = trans->c;
|
||||
struct bch_dev *ca = bch_dev_bkey_exists(c, ptr->dev);
|
||||
struct bpos pos = POS(ptr->dev, PTR_BUCKET_NR(ca, ptr));
|
||||
struct bucket *g;
|
||||
struct bkey_i *update;
|
||||
int ret;
|
||||
|
||||
|
@ -1507,14 +1506,9 @@ static int bch2_trans_start_alloc_update(struct btree_trans *trans, struct btree
|
|||
}
|
||||
|
||||
update = __bch2_btree_trans_peek_updates(iter);
|
||||
if (update && !bpos_cmp(update->k.p, pos)) {
|
||||
*u = bch2_alloc_unpack(bkey_i_to_s_c(update));
|
||||
} else {
|
||||
percpu_down_read(&c->mark_lock);
|
||||
g = bucket(ca, pos.offset);
|
||||
*u = alloc_mem_to_key(iter, g, READ_ONCE(g->mark));
|
||||
percpu_up_read(&c->mark_lock);
|
||||
}
|
||||
*u = update && !bpos_cmp(update->k.p, pos)
|
||||
? bch2_alloc_unpack(bkey_i_to_s_c(update))
|
||||
: alloc_mem_to_key(c, iter);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue