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;
|
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);
|
old_lru = alloc_lru_idx(old_a);
|
||||||
new_lru = alloc_lru_idx(*new_a);
|
new_lru = alloc_lru_idx(*new_a);
|
||||||
|
|
||||||
@ -592,7 +597,7 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
|
|||||||
if (ret)
|
if (ret)
|
||||||
return 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;
|
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])
|
if (!a.io_time[READ])
|
||||||
a.io_time[READ] = atomic64_read(&c->io_clock[READ].now);
|
a.io_time[READ] = atomic64_read(&c->io_clock[READ].now);
|
||||||
|
|
||||||
ret = bch2_lru_change(trans,
|
ret = bch2_lru_set(trans,
|
||||||
alloc_k.k->p.inode,
|
alloc_k.k->p.inode,
|
||||||
alloc_k.k->p.offset,
|
alloc_k.k->p.offset,
|
||||||
0, &a.io_time[READ]);
|
&a.io_time[READ]);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -1405,6 +1405,13 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
|
|||||||
|
|
||||||
a->v = new;
|
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);
|
ret = bch2_trans_update(trans, iter, &a->k_i, BTREE_TRIGGER_NORUN);
|
||||||
fsck_err:
|
fsck_err:
|
||||||
return ret;
|
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));
|
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 btree_iter iter;
|
||||||
struct bkey_s_c k;
|
struct bkey_s_c k;
|
||||||
@ -72,7 +72,7 @@ err:
|
|||||||
return ret;
|
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 btree_iter iter;
|
||||||
struct bkey_s_c k;
|
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)
|
if (old_time == *new_time)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return lru_delete(trans, id, idx, old_time) ?:
|
return bch2_lru_delete(trans, id, idx, old_time) ?:
|
||||||
lru_set(trans, id, idx, new_time);
|
bch2_lru_set(trans, id, idx, new_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bch2_check_lru_key(struct btree_trans *trans,
|
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, \
|
.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_lru_change(struct btree_trans *, u64, u64, u64, u64 *);
|
||||||
|
|
||||||
int bch2_check_lrus(struct bch_fs *, bool);
|
int bch2_check_lrus(struct bch_fs *, bool);
|
||||||
|
Loading…
Reference in New Issue
Block a user