summaryrefslogtreecommitdiff
path: root/libbcachefs/alloc_background.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-02-17 17:51:22 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-02-17 17:51:22 -0500
commit46a6b9210c927ab46fd1227cb6f641be0b4a7505 (patch)
treec7aea129fe8213eaefe90ac34090835d59598c7e /libbcachefs/alloc_background.c
parentc1677df62edb8be05caf7a6862b599f8e74c404f (diff)
Update bcachefs sources to 1b14994029 bcachefs: Fragmentation LRU
Diffstat (limited to 'libbcachefs/alloc_background.c')
-rw-r--r--libbcachefs/alloc_background.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/libbcachefs/alloc_background.c b/libbcachefs/alloc_background.c
index 2db4436..755faa3 100644
--- a/libbcachefs/alloc_background.c
+++ b/libbcachefs/alloc_background.c
@@ -9,6 +9,7 @@
#include "btree_update.h"
#include "btree_update_interior.h"
#include "btree_gc.h"
+#include "btree_write_buffer.h"
#include "buckets.h"
#include "buckets_waiting_for_journal.h"
#include "clock.h"
@@ -414,6 +415,8 @@ void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c
prt_newline(out);
prt_printf(out, "io_time[WRITE] %llu", a->io_time[WRITE]);
prt_newline(out);
+ prt_printf(out, "fragmentation %llu", a->fragmentation_lru);
+ prt_newline(out);
prt_printf(out, "bp_start %llu", BCH_ALLOC_V4_BACKPOINTERS_START(a));
prt_newline(out);
@@ -909,8 +912,8 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
!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);
+ old_lru = alloc_lru_idx_read(*old_a);
+ new_lru = alloc_lru_idx_read(*new_a);
if (old_lru != new_lru) {
ret = bch2_lru_change(trans, new->k.p.inode,
@@ -920,6 +923,18 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
return ret;
}
+ new_a->fragmentation_lru = alloc_lru_idx_fragmentation(*new_a,
+ bch_dev_bkey_exists(c, new->k.p.inode));
+
+ if (old_a->fragmentation_lru != new_a->fragmentation_lru) {
+ ret = bch2_lru_change(trans,
+ BCH_LRU_FRAGMENTATION_START,
+ bucket_to_u64(new->k.p),
+ old_a->fragmentation_lru, new_a->fragmentation_lru);
+ if (ret)
+ return ret;
+ }
+
if (old_a->gen != new_a->gen) {
ret = bch2_bucket_gen_update(trans, new->k.p, new_a->gen);
if (ret)
@@ -1775,15 +1790,11 @@ static int invalidate_one_bucket(struct btree_trans *trans,
if (ret)
goto out;
- if (lru_pos_time(lru_iter->pos) != alloc_lru_idx(a->v)) {
- prt_str(&buf, "alloc key does not point back to lru entry when invalidating bucket:");
- goto err;
- }
+ /* We expect harmless races here due to the btree write buffer: */
+ if (lru_pos_time(lru_iter->pos) != alloc_lru_idx_read(a->v))
+ goto out;
- if (a->v.data_type != BCH_DATA_cached) {
- prt_str(&buf, "lru entry points to non cached bucket:");
- goto err;
- }
+ BUG_ON(a->v.data_type != BCH_DATA_cached);
if (!a->v.cached_sectors)
bch_err(c, "invalidating empty bucket, confused");
@@ -1845,6 +1856,10 @@ static void bch2_do_invalidates_work(struct work_struct *work)
bch2_trans_init(&trans, c, 0, 0);
+ ret = bch2_btree_write_buffer_flush(&trans);
+ if (ret)
+ goto err;
+
for_each_member_device(ca, c, i) {
s64 nr_to_invalidate =
should_invalidate_buckets(ca, bch2_dev_usage_read(ca));
@@ -1860,7 +1875,7 @@ static void bch2_do_invalidates_work(struct work_struct *work)
break;
}
}
-
+err:
bch2_trans_exit(&trans);
bch2_write_ref_put(c, BCH_WRITE_REF_invalidate);
}