200 lines
7.7 KiB
Diff
200 lines
7.7 KiB
Diff
|
From 8aa17c262842fedae48ab6b38e63284664971560 Mon Sep 17 00:00:00 2001
|
||
|
From: Kent Overstreet <kent.overstreet@linux.dev>
|
||
|
Date: Sat, 19 Oct 2024 21:41:20 -0400
|
||
|
Subject: [PATCH 050/213] bcachefs: Simplify option logic in rebalance
|
||
|
Content-Type: text/plain; charset="utf-8"
|
||
|
Content-Transfer-Encoding: 8bit
|
||
|
|
||
|
Since bch2_move_get_io_opts() now synchronizes io_opts with options from
|
||
|
bch_extent_rebalance, delete the ad-hoc logic in rebalance.c that
|
||
|
previously did this.
|
||
|
|
||
|
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
|
||
|
Signed-off-by: Alexander Miroshnichenko <alex@millerson.name>
|
||
|
---
|
||
|
fs/bcachefs/extents.c | 20 +++++++++---------
|
||
|
fs/bcachefs/extents.h | 3 +--
|
||
|
fs/bcachefs/rebalance.c | 47 +++++++++++++----------------------------
|
||
|
3 files changed, 26 insertions(+), 44 deletions(-)
|
||
|
|
||
|
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
|
||
|
index 4988056ab4f1..bee083d787f2 100644
|
||
|
--- a/fs/bcachefs/extents.c
|
||
|
+++ b/fs/bcachefs/extents.c
|
||
|
@@ -1447,14 +1447,15 @@ const struct bch_extent_rebalance *bch2_bkey_rebalance_opts(struct bkey_s_c k)
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
-unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k,
|
||
|
- unsigned target, unsigned compression)
|
||
|
+unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c,
|
||
|
+ struct bch_io_opts *opts,
|
||
|
+ struct bkey_s_c k)
|
||
|
{
|
||
|
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
|
||
|
unsigned rewrite_ptrs = 0;
|
||
|
|
||
|
- if (compression) {
|
||
|
- unsigned compression_type = bch2_compression_opt_to_type(compression);
|
||
|
+ if (opts->background_compression) {
|
||
|
+ unsigned compression_type = bch2_compression_opt_to_type(opts->background_compression);
|
||
|
const union bch_extent_entry *entry;
|
||
|
struct extent_ptr_decoded p;
|
||
|
unsigned ptr_bit = 1;
|
||
|
@@ -1472,11 +1473,12 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k,
|
||
|
}
|
||
|
}
|
||
|
incompressible:
|
||
|
- if (target && bch2_target_accepts_data(c, BCH_DATA_user, target)) {
|
||
|
+ if (opts->background_target &&
|
||
|
+ bch2_target_accepts_data(c, BCH_DATA_user, opts->background_target)) {
|
||
|
unsigned ptr_bit = 1;
|
||
|
|
||
|
bkey_for_each_ptr(ptrs, ptr) {
|
||
|
- if (!ptr->cached && !bch2_dev_in_target(c, ptr->dev, target))
|
||
|
+ if (!ptr->cached && !bch2_dev_in_target(c, ptr->dev, opts->background_target))
|
||
|
rewrite_ptrs |= ptr_bit;
|
||
|
ptr_bit <<= 1;
|
||
|
}
|
||
|
@@ -1529,8 +1531,7 @@ bool bch2_bkey_rebalance_needs_update(struct bch_fs *c, struct bch_io_opts *opts
|
||
|
|
||
|
const struct bch_extent_rebalance *old = bch2_bkey_rebalance_opts(k);
|
||
|
|
||
|
- if (k.k->type == KEY_TYPE_reflink_v ||
|
||
|
- bch2_bkey_ptrs_need_rebalance(c, k, opts->background_target, opts->background_compression)) {
|
||
|
+ if (k.k->type == KEY_TYPE_reflink_v || bch2_bkey_ptrs_need_rebalance(c, opts, k)) {
|
||
|
struct bch_extent_rebalance new = io_opts_to_rebalance_opts(opts);
|
||
|
return old == NULL || memcmp(old, &new, sizeof(new));
|
||
|
} else {
|
||
|
@@ -1548,8 +1549,7 @@ int bch2_bkey_set_needs_rebalance(struct bch_fs *c, struct bch_io_opts *opts,
|
||
|
struct bch_extent_rebalance *old =
|
||
|
(struct bch_extent_rebalance *) bch2_bkey_rebalance_opts(k.s_c);
|
||
|
|
||
|
- if (k.k->type == KEY_TYPE_reflink_v ||
|
||
|
- bch2_bkey_ptrs_need_rebalance(c, k.s_c, opts->background_target, opts->background_compression)) {
|
||
|
+ if (k.k->type == KEY_TYPE_reflink_v || bch2_bkey_ptrs_need_rebalance(c, opts, k.s_c)) {
|
||
|
if (!old) {
|
||
|
old = bkey_val_end(k);
|
||
|
k.k->u64s += sizeof(*old) / sizeof(u64);
|
||
|
diff --git a/fs/bcachefs/extents.h b/fs/bcachefs/extents.h
|
||
|
index abe7d4b2fc6b..156fbb8e04d5 100644
|
||
|
--- a/fs/bcachefs/extents.h
|
||
|
+++ b/fs/bcachefs/extents.h
|
||
|
@@ -711,8 +711,7 @@ static inline bool bch2_extent_ptr_eq(struct bch_extent_ptr ptr1,
|
||
|
void bch2_ptr_swab(struct bkey_s);
|
||
|
|
||
|
const struct bch_extent_rebalance *bch2_bkey_rebalance_opts(struct bkey_s_c);
|
||
|
-unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *, struct bkey_s_c,
|
||
|
- unsigned, unsigned);
|
||
|
+unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *, struct bch_io_opts *, struct bkey_s_c);
|
||
|
u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *, struct bkey_s_c);
|
||
|
|
||
|
bool bch2_bkey_rebalance_needs_update(struct bch_fs *, struct bch_io_opts *, struct bkey_s_c);
|
||
|
diff --git a/fs/bcachefs/rebalance.c b/fs/bcachefs/rebalance.c
|
||
|
index e79459a5891d..3be9c85dd55d 100644
|
||
|
--- a/fs/bcachefs/rebalance.c
|
||
|
+++ b/fs/bcachefs/rebalance.c
|
||
|
@@ -121,6 +121,9 @@ static int bch2_bkey_clear_needs_rebalance(struct btree_trans *trans,
|
||
|
struct btree_iter *iter,
|
||
|
struct bkey_s_c k)
|
||
|
{
|
||
|
+ if (!bch2_bkey_rebalance_opts(k))
|
||
|
+ return 0;
|
||
|
+
|
||
|
struct bkey_i *n = bch2_bkey_make_mut(trans, iter, &k, 0);
|
||
|
int ret = PTR_ERR_OR_ZERO(n);
|
||
|
if (ret)
|
||
|
@@ -134,31 +137,27 @@ static int bch2_bkey_clear_needs_rebalance(struct btree_trans *trans,
|
||
|
static struct bkey_s_c next_rebalance_extent(struct btree_trans *trans,
|
||
|
struct bpos work_pos,
|
||
|
struct btree_iter *extent_iter,
|
||
|
+ struct bch_io_opts *io_opts,
|
||
|
struct data_update_opts *data_opts)
|
||
|
{
|
||
|
struct bch_fs *c = trans->c;
|
||
|
- struct bkey_s_c k;
|
||
|
|
||
|
bch2_trans_iter_exit(trans, extent_iter);
|
||
|
bch2_trans_iter_init(trans, extent_iter,
|
||
|
work_pos.inode ? BTREE_ID_extents : BTREE_ID_reflink,
|
||
|
work_pos,
|
||
|
BTREE_ITER_all_snapshots);
|
||
|
- k = bch2_btree_iter_peek_slot(extent_iter);
|
||
|
+ struct bkey_s_c k = bch2_btree_iter_peek_slot(extent_iter);
|
||
|
if (bkey_err(k))
|
||
|
return k;
|
||
|
|
||
|
- const struct bch_extent_rebalance *r = k.k ? bch2_bkey_rebalance_opts(k) : NULL;
|
||
|
- if (!r) {
|
||
|
- /* raced due to btree write buffer, nothing to do */
|
||
|
- return bkey_s_c_null;
|
||
|
- }
|
||
|
+ int ret = bch2_move_get_io_opts_one(trans, io_opts, extent_iter, k);
|
||
|
+ if (ret)
|
||
|
+ return bkey_s_c_err(ret);
|
||
|
|
||
|
memset(data_opts, 0, sizeof(*data_opts));
|
||
|
-
|
||
|
- data_opts->rewrite_ptrs =
|
||
|
- bch2_bkey_ptrs_need_rebalance(c, k, r->background_target, r->background_compression);
|
||
|
- data_opts->target = r->background_target;
|
||
|
+ data_opts->rewrite_ptrs = bch2_bkey_ptrs_need_rebalance(c, io_opts, k);
|
||
|
+ data_opts->target = io_opts->background_target;
|
||
|
data_opts->write_flags |= BCH_WRITE_ONLY_SPECIFIED_DEVS;
|
||
|
|
||
|
if (!data_opts->rewrite_ptrs) {
|
||
|
@@ -179,9 +178,9 @@ static struct bkey_s_c next_rebalance_extent(struct btree_trans *trans,
|
||
|
struct printbuf buf = PRINTBUF;
|
||
|
|
||
|
prt_str(&buf, "target=");
|
||
|
- bch2_target_to_text(&buf, c, r->background_target);
|
||
|
+ bch2_target_to_text(&buf, c, io_opts->background_target);
|
||
|
prt_str(&buf, " compression=");
|
||
|
- bch2_compression_opt_to_text(&buf, r->background_compression);
|
||
|
+ bch2_compression_opt_to_text(&buf, io_opts->background_compression);
|
||
|
prt_str(&buf, " ");
|
||
|
bch2_bkey_val_to_text(&buf, c, k);
|
||
|
|
||
|
@@ -212,14 +211,10 @@ static int do_rebalance_extent(struct moving_context *ctxt,
|
||
|
bch2_bkey_buf_init(&sk);
|
||
|
|
||
|
ret = bkey_err(k = next_rebalance_extent(trans, work_pos,
|
||
|
- extent_iter, &data_opts));
|
||
|
+ extent_iter, &io_opts, &data_opts));
|
||
|
if (ret || !k.k)
|
||
|
goto out;
|
||
|
|
||
|
- ret = bch2_move_get_io_opts_one(trans, &io_opts, extent_iter, k);
|
||
|
- if (ret)
|
||
|
- goto out;
|
||
|
-
|
||
|
atomic64_add(k.k->size, &ctxt->stats->sectors_seen);
|
||
|
|
||
|
/*
|
||
|
@@ -253,20 +248,8 @@ static bool rebalance_pred(struct bch_fs *c, void *arg,
|
||
|
struct bch_io_opts *io_opts,
|
||
|
struct data_update_opts *data_opts)
|
||
|
{
|
||
|
- unsigned target, compression;
|
||
|
-
|
||
|
- if (k.k->p.inode) {
|
||
|
- target = io_opts->background_target;
|
||
|
- compression = io_opts->background_compression;
|
||
|
- } else {
|
||
|
- const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k);
|
||
|
-
|
||
|
- target = r ? r->background_target : io_opts->background_target;
|
||
|
- compression = r ? r->background_compression : io_opts->background_compression;
|
||
|
- }
|
||
|
-
|
||
|
- data_opts->rewrite_ptrs = bch2_bkey_ptrs_need_rebalance(c, k, target, compression);
|
||
|
- data_opts->target = target;
|
||
|
+ data_opts->rewrite_ptrs = bch2_bkey_ptrs_need_rebalance(c, io_opts, k);
|
||
|
+ data_opts->target = io_opts->background_target;
|
||
|
data_opts->write_flags |= BCH_WRITE_ONLY_SPECIFIED_DEVS;
|
||
|
return data_opts->rewrite_ptrs != 0;
|
||
|
}
|
||
|
--
|
||
|
2.45.2
|
||
|
|