mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 21:38:32 +08:00
bcachefs: opts->compression can now also be applied in the background
The "apply this compression method in the background" paths now use the compression option if background_compression is not set; this means that setting or changing the compression option will cause existing data to be compressed accordingly in the background. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
ec4edd7b9d
commit
d7e77f53e9
@ -285,9 +285,7 @@ restart_drop_extra_replicas:
|
|||||||
k.k->p, bkey_start_pos(&insert->k)) ?:
|
k.k->p, bkey_start_pos(&insert->k)) ?:
|
||||||
bch2_insert_snapshot_whiteouts(trans, m->btree_id,
|
bch2_insert_snapshot_whiteouts(trans, m->btree_id,
|
||||||
k.k->p, insert->k.p) ?:
|
k.k->p, insert->k.p) ?:
|
||||||
bch2_bkey_set_needs_rebalance(c, insert,
|
bch2_bkey_set_needs_rebalance(c, insert, &op->opts) ?:
|
||||||
op->opts.background_target,
|
|
||||||
op->opts.background_compression) ?:
|
|
||||||
bch2_trans_update(trans, &iter, insert,
|
bch2_trans_update(trans, &iter, insert,
|
||||||
BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE) ?:
|
BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE) ?:
|
||||||
bch2_trans_commit(trans, &op->res,
|
bch2_trans_commit(trans, &op->res,
|
||||||
@ -529,7 +527,7 @@ int bch2_data_update_init(struct btree_trans *trans,
|
|||||||
BCH_WRITE_DATA_ENCODED|
|
BCH_WRITE_DATA_ENCODED|
|
||||||
BCH_WRITE_MOVE|
|
BCH_WRITE_MOVE|
|
||||||
m->data_opts.write_flags;
|
m->data_opts.write_flags;
|
||||||
m->op.compression_opt = io_opts.background_compression ?: io_opts.compression;
|
m->op.compression_opt = background_compression(io_opts);
|
||||||
m->op.watermark = m->data_opts.btree_insert_flags & BCH_WATERMARK_MASK;
|
m->op.watermark = m->data_opts.btree_insert_flags & BCH_WATERMARK_MASK;
|
||||||
|
|
||||||
bkey_for_each_ptr(ptrs, ptr)
|
bkey_for_each_ptr(ptrs, ptr)
|
||||||
|
@ -1335,10 +1335,12 @@ bool bch2_bkey_needs_rebalance(struct bch_fs *c, struct bkey_s_c k)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int bch2_bkey_set_needs_rebalance(struct bch_fs *c, struct bkey_i *_k,
|
int bch2_bkey_set_needs_rebalance(struct bch_fs *c, struct bkey_i *_k,
|
||||||
unsigned target, unsigned compression)
|
struct bch_io_opts *opts)
|
||||||
{
|
{
|
||||||
struct bkey_s k = bkey_i_to_s(_k);
|
struct bkey_s k = bkey_i_to_s(_k);
|
||||||
struct bch_extent_rebalance *r;
|
struct bch_extent_rebalance *r;
|
||||||
|
unsigned target = opts->background_target;
|
||||||
|
unsigned compression = background_compression(*opts);
|
||||||
bool needs_rebalance;
|
bool needs_rebalance;
|
||||||
|
|
||||||
if (!bkey_extent_is_direct_data(k.k))
|
if (!bkey_extent_is_direct_data(k.k))
|
||||||
|
@ -708,7 +708,7 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *, struct bkey_s_c,
|
|||||||
bool bch2_bkey_needs_rebalance(struct bch_fs *, struct bkey_s_c);
|
bool bch2_bkey_needs_rebalance(struct bch_fs *, struct bkey_s_c);
|
||||||
|
|
||||||
int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bkey_i *,
|
int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bkey_i *,
|
||||||
unsigned, unsigned);
|
struct bch_io_opts *);
|
||||||
|
|
||||||
/* Generic extent code: */
|
/* Generic extent code: */
|
||||||
|
|
||||||
|
@ -442,9 +442,7 @@ case LOGGED_OP_FINSERT_shift_extents:
|
|||||||
|
|
||||||
op->v.pos = cpu_to_le64(insert ? bkey_start_offset(&delete.k) : delete.k.p.offset);
|
op->v.pos = cpu_to_le64(insert ? bkey_start_offset(&delete.k) : delete.k.p.offset);
|
||||||
|
|
||||||
ret = bch2_bkey_set_needs_rebalance(c, copy,
|
ret = bch2_bkey_set_needs_rebalance(c, copy, &opts) ?:
|
||||||
opts.background_target,
|
|
||||||
opts.background_compression) ?:
|
|
||||||
bch2_btree_insert_trans(trans, BTREE_ID_extents, &delete, 0) ?:
|
bch2_btree_insert_trans(trans, BTREE_ID_extents, &delete, 0) ?:
|
||||||
bch2_btree_insert_trans(trans, BTREE_ID_extents, copy, 0) ?:
|
bch2_btree_insert_trans(trans, BTREE_ID_extents, copy, 0) ?:
|
||||||
bch2_logged_op_update(trans, &op->k_i) ?:
|
bch2_logged_op_update(trans, &op->k_i) ?:
|
||||||
|
@ -362,9 +362,7 @@ static int bch2_write_index_default(struct bch_write_op *op)
|
|||||||
bkey_start_pos(&sk.k->k),
|
bkey_start_pos(&sk.k->k),
|
||||||
BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
|
BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
|
||||||
|
|
||||||
ret = bch2_bkey_set_needs_rebalance(c, sk.k,
|
ret = bch2_bkey_set_needs_rebalance(c, sk.k, &op->opts) ?:
|
||||||
op->opts.background_target,
|
|
||||||
op->opts.background_compression) ?:
|
|
||||||
bch2_extent_update(trans, inum, &iter, sk.k,
|
bch2_extent_update(trans, inum, &iter, sk.k,
|
||||||
&op->res,
|
&op->res,
|
||||||
op->new_i_size, &op->i_sectors_delta,
|
op->new_i_size, &op->i_sectors_delta,
|
||||||
|
@ -58,7 +58,7 @@ static void bch2_data_update_opts_to_text(struct printbuf *out, struct bch_fs *c
|
|||||||
|
|
||||||
prt_str(out, "compression: ");
|
prt_str(out, "compression: ");
|
||||||
prt_tab(out);
|
prt_tab(out);
|
||||||
bch2_compression_opt_to_text(out, io_opts->background_compression ?: io_opts->compression);
|
bch2_compression_opt_to_text(out, background_compression(*io_opts));
|
||||||
prt_newline(out);
|
prt_newline(out);
|
||||||
|
|
||||||
prt_str(out, "extra replicas: ");
|
prt_str(out, "extra replicas: ");
|
||||||
|
@ -564,6 +564,11 @@ struct bch_io_opts {
|
|||||||
#undef x
|
#undef x
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline unsigned background_compression(struct bch_io_opts opts)
|
||||||
|
{
|
||||||
|
return opts.background_compression ?: opts.compression;
|
||||||
|
}
|
||||||
|
|
||||||
struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
|
struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
|
||||||
bool bch2_opt_is_inode_opt(enum bch_opt_id);
|
bool bch2_opt_is_inode_opt(enum bch_opt_id);
|
||||||
|
|
||||||
|
@ -253,13 +253,12 @@ static bool rebalance_pred(struct bch_fs *c, void *arg,
|
|||||||
|
|
||||||
if (k.k->p.inode) {
|
if (k.k->p.inode) {
|
||||||
target = io_opts->background_target;
|
target = io_opts->background_target;
|
||||||
compression = io_opts->background_compression ?: io_opts->compression;
|
compression = background_compression(*io_opts);
|
||||||
} else {
|
} else {
|
||||||
const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k);
|
const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k);
|
||||||
|
|
||||||
target = r ? r->target : io_opts->background_target;
|
target = r ? r->target : io_opts->background_target;
|
||||||
compression = r ? r->compression :
|
compression = r ? r->compression : background_compression(*io_opts);
|
||||||
(io_opts->background_compression ?: io_opts->compression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data_opts->rewrite_ptrs = bch2_bkey_ptrs_need_rebalance(c, k, target, compression);
|
data_opts->rewrite_ptrs = bch2_bkey_ptrs_need_rebalance(c, k, target, compression);
|
||||||
|
@ -545,9 +545,7 @@ s64 bch2_remap_range(struct bch_fs *c,
|
|||||||
min(src_k.k->p.offset - src_want.offset,
|
min(src_k.k->p.offset - src_want.offset,
|
||||||
dst_end.offset - dst_iter.pos.offset));
|
dst_end.offset - dst_iter.pos.offset));
|
||||||
|
|
||||||
ret = bch2_bkey_set_needs_rebalance(c, new_dst.k,
|
ret = bch2_bkey_set_needs_rebalance(c, new_dst.k, &opts) ?:
|
||||||
opts.background_target,
|
|
||||||
opts.background_compression) ?:
|
|
||||||
bch2_extent_update(trans, dst_inum, &dst_iter,
|
bch2_extent_update(trans, dst_inum, &dst_iter,
|
||||||
new_dst.k, &disk_res,
|
new_dst.k, &disk_res,
|
||||||
new_i_size, i_sectors_delta,
|
new_i_size, i_sectors_delta,
|
||||||
|
@ -726,8 +726,10 @@ STORE(bch2_fs_opts_dir)
|
|||||||
bch2_opt_set_sb(c, opt, v);
|
bch2_opt_set_sb(c, opt, v);
|
||||||
bch2_opt_set_by_id(&c->opts, id, v);
|
bch2_opt_set_by_id(&c->opts, id, v);
|
||||||
|
|
||||||
if ((id == Opt_background_target ||
|
if (v &&
|
||||||
id == Opt_background_compression) && v)
|
(id == Opt_background_target ||
|
||||||
|
id == Opt_background_compression ||
|
||||||
|
(id == Opt_compression && !c->opts.background_compression)))
|
||||||
bch2_set_rebalance_needs_scan(c, 0);
|
bch2_set_rebalance_needs_scan(c, 0);
|
||||||
|
|
||||||
ret = size;
|
ret = size;
|
||||||
|
@ -590,8 +590,9 @@ err:
|
|||||||
mutex_unlock(&inode->ei_update_lock);
|
mutex_unlock(&inode->ei_update_lock);
|
||||||
|
|
||||||
if (value &&
|
if (value &&
|
||||||
(opt_id == Opt_background_compression ||
|
(opt_id == Opt_background_target ||
|
||||||
opt_id == Opt_background_target))
|
opt_id == Opt_background_compression ||
|
||||||
|
(opt_id == Opt_compression && !inode_opt_get(c, &inode->ei_inode, background_compression))))
|
||||||
bch2_set_rebalance_needs_scan(c, inode->ei_inode.bi_inum);
|
bch2_set_rebalance_needs_scan(c, inode->ei_inode.bi_inum);
|
||||||
|
|
||||||
return bch2_err_class(ret);
|
return bch2_err_class(ret);
|
||||||
|
Loading…
Reference in New Issue
Block a user