diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-04-11 02:59:26 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:09:31 +0300 |
commit | 7003589dabcdfd10345ede31044ce5e13ee65e7f (patch) | |
tree | c34b49a991b90bea0cdfab392e20063e40d2c4a8 /fs/bcachefs | |
parent | 84befe8ef9a07be1cd9bac4e1a1c66c667f71499 (diff) | |
download | linux-7003589dabcdfd10345ede31044ce5e13ee65e7f.tar.xz |
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>
Diffstat (limited to 'fs/bcachefs')
-rw-r--r-- | fs/bcachefs/alloc_background.c | 15 | ||||
-rw-r--r-- | fs/bcachefs/btree_gc.c | 7 | ||||
-rw-r--r-- | fs/bcachefs/lru.c | 8 | ||||
-rw-r--r-- | fs/bcachefs/lru.h | 2 |
4 files changed, 23 insertions, 9 deletions
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c index 3be6f0fa89de..17b147d15320 100644 --- a/fs/bcachefs/alloc_background.c +++ b/fs/bcachefs/alloc_background.c @@ -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; diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c index 0b1717120cc3..5199f0240fcd 100644 --- a/fs/bcachefs/btree_gc.c +++ b/fs/bcachefs/btree_gc.c @@ -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; diff --git a/fs/bcachefs/lru.c b/fs/bcachefs/lru.c index d8180bc1c6b1..49a0f0d69664 100644 --- a/fs/bcachefs/lru.c +++ b/fs/bcachefs/lru.c @@ -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, diff --git a/fs/bcachefs/lru.h b/fs/bcachefs/lru.h index e8f508174b0a..0a01836c07c1 100644 --- a/fs/bcachefs/lru.h +++ b/fs/bcachefs/lru.h @@ -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); |