Commit d7e77f53 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

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: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent ec4edd7b
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -285,9 +285,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
						k.k->p, bkey_start_pos(&insert->k)) ?:
			bch2_insert_snapshot_whiteouts(trans, m->btree_id,
						k.k->p, insert->k.p) ?:
			bch2_bkey_set_needs_rebalance(c, insert,
						      op->opts.background_target,
						      op->opts.background_compression) ?:
			bch2_bkey_set_needs_rebalance(c, insert, &op->opts) ?:
			bch2_trans_update(trans, &iter, insert,
				BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE) ?:
			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_MOVE|
		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;

	bkey_for_each_ptr(ptrs, ptr)
+3 −1
Original line number Diff line number Diff line
@@ -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,
				  unsigned target, unsigned compression)
				  struct bch_io_opts *opts)
{
	struct bkey_s k = bkey_i_to_s(_k);
	struct bch_extent_rebalance *r;
	unsigned target = opts->background_target;
	unsigned compression = background_compression(*opts);
	bool needs_rebalance;

	if (!bkey_extent_is_direct_data(k.k))
+1 −1
Original line number Diff line number Diff line
@@ -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);

int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bkey_i *,
				  unsigned, unsigned);
				  struct bch_io_opts *);

/* Generic extent code: */

+1 −3
Original line number Diff line number Diff line
@@ -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);

		ret =   bch2_bkey_set_needs_rebalance(c, copy,
					opts.background_target,
					opts.background_compression) ?:
		ret =   bch2_bkey_set_needs_rebalance(c, copy, &opts) ?:
			bch2_btree_insert_trans(trans, BTREE_ID_extents, &delete, 0) ?:
			bch2_btree_insert_trans(trans, BTREE_ID_extents, copy, 0) ?:
			bch2_logged_op_update(trans, &op->k_i) ?:
+1 −3
Original line number Diff line number Diff line
@@ -362,9 +362,7 @@ static int bch2_write_index_default(struct bch_write_op *op)
				     bkey_start_pos(&sk.k->k),
				     BTREE_ITER_SLOTS|BTREE_ITER_INTENT);

		ret =   bch2_bkey_set_needs_rebalance(c, sk.k,
					op->opts.background_target,
					op->opts.background_compression) ?:
		ret =   bch2_bkey_set_needs_rebalance(c, sk.k, &op->opts) ?:
			bch2_extent_update(trans, inum, &iter, sk.k,
					&op->res,
					op->new_i_size, &op->i_sectors_delta,
Loading