mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 00:04:15 +08:00
bcachefs: Ensure buckets have io_time[READ] set
It's an error if a bucket is in state BCH_DATA_cached but not on the LRU btree - i.e io_time[READ] == 0 - so, make sure it's set before adding it. Also, make some of the LRU code a bit clearer and more direct. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
parent
84befe8ef9
commit
7003589dab
@ -583,6 +583,11 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (new_a->data_type == BCH_DATA_cached &&
|
||||
!new_a->io_time[READ])
|
||||
new_a->io_time[READ] = max_t(u64, 1, atomic64_read(&c->io_clock[READ].now));
|
||||
|
||||
|
||||
old_lru = alloc_lru_idx(old_a);
|
||||
new_lru = alloc_lru_idx(*new_a);
|
||||
|
||||
@ -592,7 +597,7 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (new_lru && new_a->io_time[READ] != new_lru)
|
||||
if (new_a->data_type == BCH_DATA_cached)
|
||||
new_a->io_time[READ] = new_lru;
|
||||
}
|
||||
|
||||
@ -869,10 +874,10 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
|
||||
if (!a.io_time[READ])
|
||||
a.io_time[READ] = atomic64_read(&c->io_clock[READ].now);
|
||||
|
||||
ret = bch2_lru_change(trans,
|
||||
alloc_k.k->p.inode,
|
||||
alloc_k.k->p.offset,
|
||||
0, &a.io_time[READ]);
|
||||
ret = bch2_lru_set(trans,
|
||||
alloc_k.k->p.inode,
|
||||
alloc_k.k->p.offset,
|
||||
&a.io_time[READ]);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
|
@ -1405,6 +1405,13 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
|
||||
|
||||
a->v = new;
|
||||
|
||||
/*
|
||||
* The trigger normally makes sure this is set, but we're not running
|
||||
* triggers:
|
||||
*/
|
||||
if (a->v.data_type == BCH_DATA_cached && !a->v.io_time[READ])
|
||||
a->v.io_time[READ] = max_t(u64, 1, atomic64_read(&c->io_clock[READ].now));
|
||||
|
||||
ret = bch2_trans_update(trans, iter, &a->k_i, BTREE_TRIGGER_NORUN);
|
||||
fsck_err:
|
||||
return ret;
|
||||
|
@ -30,7 +30,7 @@ void bch2_lru_to_text(struct printbuf *out, struct bch_fs *c,
|
||||
pr_buf(out, "idx %llu", le64_to_cpu(lru->idx));
|
||||
}
|
||||
|
||||
static int lru_delete(struct btree_trans *trans, u64 id, u64 idx, u64 time)
|
||||
int bch2_lru_delete(struct btree_trans *trans, u64 id, u64 idx, u64 time)
|
||||
{
|
||||
struct btree_iter iter;
|
||||
struct bkey_s_c k;
|
||||
@ -72,7 +72,7 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int lru_set(struct btree_trans *trans, u64 lru_id, u64 idx, u64 *time)
|
||||
int bch2_lru_set(struct btree_trans *trans, u64 lru_id, u64 idx, u64 *time)
|
||||
{
|
||||
struct btree_iter iter;
|
||||
struct bkey_s_c k;
|
||||
@ -119,8 +119,8 @@ int bch2_lru_change(struct btree_trans *trans, u64 id, u64 idx,
|
||||
if (old_time == *new_time)
|
||||
return 0;
|
||||
|
||||
return lru_delete(trans, id, idx, old_time) ?:
|
||||
lru_set(trans, id, idx, new_time);
|
||||
return bch2_lru_delete(trans, id, idx, old_time) ?:
|
||||
bch2_lru_set(trans, id, idx, new_time);
|
||||
}
|
||||
|
||||
static int bch2_check_lru_key(struct btree_trans *trans,
|
||||
|
@ -10,6 +10,8 @@ void bch2_lru_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
|
||||
.val_to_text = bch2_lru_to_text, \
|
||||
}
|
||||
|
||||
int bch2_lru_delete(struct btree_trans *, u64, u64, u64);
|
||||
int bch2_lru_set(struct btree_trans *, u64, u64, u64 *);
|
||||
int bch2_lru_change(struct btree_trans *, u64, u64, u64, u64 *);
|
||||
|
||||
int bch2_check_lrus(struct bch_fs *, bool);
|
||||
|
Loading…
Reference in New Issue
Block a user