Skip to content

Commit d7e77f5

Browse files
author
Kent Overstreet
committed
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>
1 parent ec4edd7 commit d7e77f5

File tree

11 files changed

+24
-23
lines changed

11 files changed

+24
-23
lines changed

fs/bcachefs/data_update.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
285285
k.k->p, bkey_start_pos(&insert->k)) ?:
286286
bch2_insert_snapshot_whiteouts(trans, m->btree_id,
287287
k.k->p, insert->k.p) ?:
288-
bch2_bkey_set_needs_rebalance(c, insert,
289-
op->opts.background_target,
290-
op->opts.background_compression) ?:
288+
bch2_bkey_set_needs_rebalance(c, insert, &op->opts) ?:
291289
bch2_trans_update(trans, &iter, insert,
292290
BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE) ?:
293291
bch2_trans_commit(trans, &op->res,
@@ -529,7 +527,7 @@ int bch2_data_update_init(struct btree_trans *trans,
529527
BCH_WRITE_DATA_ENCODED|
530528
BCH_WRITE_MOVE|
531529
m->data_opts.write_flags;
532-
m->op.compression_opt = io_opts.background_compression ?: io_opts.compression;
530+
m->op.compression_opt = background_compression(io_opts);
533531
m->op.watermark = m->data_opts.btree_insert_flags & BCH_WATERMARK_MASK;
534532

535533
bkey_for_each_ptr(ptrs, ptr)

fs/bcachefs/extents.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,10 +1335,12 @@ bool bch2_bkey_needs_rebalance(struct bch_fs *c, struct bkey_s_c k)
13351335
}
13361336

13371337
int bch2_bkey_set_needs_rebalance(struct bch_fs *c, struct bkey_i *_k,
1338-
unsigned target, unsigned compression)
1338+
struct bch_io_opts *opts)
13391339
{
13401340
struct bkey_s k = bkey_i_to_s(_k);
13411341
struct bch_extent_rebalance *r;
1342+
unsigned target = opts->background_target;
1343+
unsigned compression = background_compression(*opts);
13421344
bool needs_rebalance;
13431345

13441346
if (!bkey_extent_is_direct_data(k.k))

fs/bcachefs/extents.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *, struct bkey_s_c,
708708
bool bch2_bkey_needs_rebalance(struct bch_fs *, struct bkey_s_c);
709709

710710
int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bkey_i *,
711-
unsigned, unsigned);
711+
struct bch_io_opts *);
712712

713713
/* Generic extent code: */
714714

fs/bcachefs/io_misc.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,7 @@ case LOGGED_OP_FINSERT_shift_extents:
442442

443443
op->v.pos = cpu_to_le64(insert ? bkey_start_offset(&delete.k) : delete.k.p.offset);
444444

445-
ret = bch2_bkey_set_needs_rebalance(c, copy,
446-
opts.background_target,
447-
opts.background_compression) ?:
445+
ret = bch2_bkey_set_needs_rebalance(c, copy, &opts) ?:
448446
bch2_btree_insert_trans(trans, BTREE_ID_extents, &delete, 0) ?:
449447
bch2_btree_insert_trans(trans, BTREE_ID_extents, copy, 0) ?:
450448
bch2_logged_op_update(trans, &op->k_i) ?:

fs/bcachefs/io_write.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,7 @@ static int bch2_write_index_default(struct bch_write_op *op)
362362
bkey_start_pos(&sk.k->k),
363363
BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
364364

365-
ret = bch2_bkey_set_needs_rebalance(c, sk.k,
366-
op->opts.background_target,
367-
op->opts.background_compression) ?:
365+
ret = bch2_bkey_set_needs_rebalance(c, sk.k, &op->opts) ?:
368366
bch2_extent_update(trans, inum, &iter, sk.k,
369367
&op->res,
370368
op->new_i_size, &op->i_sectors_delta,

fs/bcachefs/move.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void bch2_data_update_opts_to_text(struct printbuf *out, struct bch_fs *c
5858

5959
prt_str(out, "compression: ");
6060
prt_tab(out);
61-
bch2_compression_opt_to_text(out, io_opts->background_compression ?: io_opts->compression);
61+
bch2_compression_opt_to_text(out, background_compression(*io_opts));
6262
prt_newline(out);
6363

6464
prt_str(out, "extra replicas: ");

fs/bcachefs/opts.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ struct bch_io_opts {
564564
#undef x
565565
};
566566

567+
static inline unsigned background_compression(struct bch_io_opts opts)
568+
{
569+
return opts.background_compression ?: opts.compression;
570+
}
571+
567572
struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
568573
bool bch2_opt_is_inode_opt(enum bch_opt_id);
569574

fs/bcachefs/rebalance.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,12 @@ static bool rebalance_pred(struct bch_fs *c, void *arg,
253253

254254
if (k.k->p.inode) {
255255
target = io_opts->background_target;
256-
compression = io_opts->background_compression ?: io_opts->compression;
256+
compression = background_compression(*io_opts);
257257
} else {
258258
const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k);
259259

260260
target = r ? r->target : io_opts->background_target;
261-
compression = r ? r->compression :
262-
(io_opts->background_compression ?: io_opts->compression);
261+
compression = r ? r->compression : background_compression(*io_opts);
263262
}
264263

265264
data_opts->rewrite_ptrs = bch2_bkey_ptrs_need_rebalance(c, k, target, compression);

fs/bcachefs/reflink.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,7 @@ s64 bch2_remap_range(struct bch_fs *c,
545545
min(src_k.k->p.offset - src_want.offset,
546546
dst_end.offset - dst_iter.pos.offset));
547547

548-
ret = bch2_bkey_set_needs_rebalance(c, new_dst.k,
549-
opts.background_target,
550-
opts.background_compression) ?:
548+
ret = bch2_bkey_set_needs_rebalance(c, new_dst.k, &opts) ?:
551549
bch2_extent_update(trans, dst_inum, &dst_iter,
552550
new_dst.k, &disk_res,
553551
new_i_size, i_sectors_delta,

fs/bcachefs/sysfs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,10 @@ STORE(bch2_fs_opts_dir)
726726
bch2_opt_set_sb(c, opt, v);
727727
bch2_opt_set_by_id(&c->opts, id, v);
728728

729-
if ((id == Opt_background_target ||
730-
id == Opt_background_compression) && v)
729+
if (v &&
730+
(id == Opt_background_target ||
731+
id == Opt_background_compression ||
732+
(id == Opt_compression && !c->opts.background_compression)))
731733
bch2_set_rebalance_needs_scan(c, 0);
732734

733735
ret = size;

0 commit comments

Comments
 (0)