bcachefs: Kill bch_write_op.index_update_fn

This deletes bch_write_op.index_update_fn: indirect function calls have
gotten considerably more expensive post spectre/meltdown, and we only
have two different index_update_fns - this patch adds a flag to specify
which one to use (normal vs. data move path).

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2022-10-28 23:57:01 -04:00
parent 7e94eeffe0
commit af17118319
5 changed files with 42 additions and 27 deletions

View file

@ -432,7 +432,7 @@ int bch2_fpunch(struct bch_fs *c, u64 inum, u64 start, u64 end,
return ret;
}
int bch2_write_index_default(struct bch_write_op *op)
static int bch2_write_index_default(struct bch_write_op *op)
{
struct bch_fs *c = op->c;
struct bkey_buf sk;
@ -577,7 +577,7 @@ static void __bch2_write_index(struct bch_write_op *op)
struct bch_extent_ptr *ptr;
struct bkey_i *src, *dst = keys->keys, *n, *k;
unsigned dev;
int ret;
int ret = 0;
for (src = keys->keys; src != keys->top; src = n) {
n = bkey_next(src);
@ -614,7 +614,10 @@ static void __bch2_write_index(struct bch_write_op *op)
if (!bch2_keylist_empty(keys)) {
u64 sectors_start = keylist_sectors(keys);
int ret = op->index_update_fn(op);
ret = !(op->flags & BCH_WRITE_MOVE)
? bch2_write_index_default(op)
: bch2_migrate_index_update(op);
BUG_ON(ret == -EINTR);
BUG_ON(keylist_sectors(keys) && !ret);
@ -624,7 +627,7 @@ static void __bch2_write_index(struct bch_write_op *op)
if (ret) {
bch_err_inum_ratelimited(c, op->pos.inode,
"write error %i from btree update", ret);
op->error = ret;
goto err;
}
}
out:

View file

@ -29,23 +29,39 @@ void bch2_submit_wbio_replicas(struct bch_write_bio *, struct bch_fs *,
const char *bch2_blk_status_to_str(blk_status_t);
enum bch_write_flags {
BCH_WRITE_ALLOC_NOWAIT = (1 << 0),
BCH_WRITE_CACHED = (1 << 1),
BCH_WRITE_FLUSH = (1 << 2),
BCH_WRITE_DATA_ENCODED = (1 << 3),
BCH_WRITE_PAGES_STABLE = (1 << 4),
BCH_WRITE_PAGES_OWNED = (1 << 5),
BCH_WRITE_ONLY_SPECIFIED_DEVS = (1 << 6),
BCH_WRITE_WROTE_DATA_INLINE = (1 << 7),
BCH_WRITE_FROM_INTERNAL = (1 << 8),
BCH_WRITE_CHECK_ENOSPC = (1 << 9),
/* Internal: */
BCH_WRITE_JOURNAL_SEQ_PTR = (1 << 10),
BCH_WRITE_SKIP_CLOSURE_PUT = (1 << 11),
BCH_WRITE_DONE = (1 << 12),
__BCH_WRITE_ALLOC_NOWAIT,
__BCH_WRITE_CACHED,
__BCH_WRITE_FLUSH,
__BCH_WRITE_DATA_ENCODED,
__BCH_WRITE_PAGES_STABLE,
__BCH_WRITE_PAGES_OWNED,
__BCH_WRITE_ONLY_SPECIFIED_DEVS,
__BCH_WRITE_WROTE_DATA_INLINE,
__BCH_WRITE_FROM_INTERNAL,
__BCH_WRITE_CHECK_ENOSPC,
__BCH_WRITE_MOVE,
__BCH_WRITE_JOURNAL_SEQ_PTR,
__BCH_WRITE_SKIP_CLOSURE_PUT,
__BCH_WRITE_DONE,
};
#define BCH_WRITE_ALLOC_NOWAIT (1U << __BCH_WRITE_ALLOC_NOWAIT)
#define BCH_WRITE_CACHED (1U << __BCH_WRITE_CACHED)
#define BCH_WRITE_FLUSH (1U << __BCH_WRITE_FLUSH)
#define BCH_WRITE_DATA_ENCODED (1U << __BCH_WRITE_DATA_ENCODED)
#define BCH_WRITE_PAGES_STABLE (1U << __BCH_WRITE_PAGES_STABLE)
#define BCH_WRITE_PAGES_OWNED (1U << __BCH_WRITE_PAGES_OWNED)
#define BCH_WRITE_ONLY_SPECIFIED_DEVS (1U << __BCH_WRITE_ONLY_SPECIFIED_DEVS)
#define BCH_WRITE_WROTE_DATA_INLINE (1U << __BCH_WRITE_WROTE_DATA_INLINE)
#define BCH_WRITE_FROM_INTERNAL (1U << __BCH_WRITE_FROM_INTERNAL)
#define BCH_WRITE_CHECK_ENOSPC (1U << __BCH_WRITE_CHECK_ENOSPC)
#define BCH_WRITE_MOVE (1U << __BCH_WRITE_MOVE)
/* Internal: */
#define BCH_WRITE_JOURNAL_SEQ_PTR (1U << __BCH_WRITE_JOURNAL_SEQ_PTR)
#define BCH_WRITE_SKIP_CLOSURE_PUT (1U << __BCH_WRITE_SKIP_CLOSURE_PUT)
#define BCH_WRITE_DONE (1U << __BCH_WRITE_DONE)
static inline u64 *op_journal_seq(struct bch_write_op *op)
{
return (op->flags & BCH_WRITE_JOURNAL_SEQ_PTR)
@ -74,8 +90,6 @@ int bch2_fpunch_at(struct btree_trans *, struct btree_iter *,
struct bpos, u64 *, s64 *);
int bch2_fpunch(struct bch_fs *c, u64, u64, u64, u64 *, s64 *);
int bch2_write_index_default(struct bch_write_op *);
static inline void bch2_write_op_init(struct bch_write_op *op, struct bch_fs *c,
struct bch_io_opts opts)
{
@ -101,7 +115,6 @@ static inline void bch2_write_op_init(struct bch_write_op *op, struct bch_fs *c,
op->journal_seq = 0;
op->new_i_size = U64_MAX;
op->i_sectors_delta = 0;
op->index_update_fn = bch2_write_index_default;
}
void bch2_write(struct closure *);

View file

@ -146,8 +146,6 @@ struct bch_write_op {
u64 new_i_size;
s64 i_sectors_delta;
int (*index_update_fn)(struct bch_write_op *);
struct bch_devs_mask failed;
struct keylist insert_keys;

View file

@ -52,7 +52,7 @@ struct moving_context {
wait_queue_head_t wait;
};
static int bch2_migrate_index_update(struct bch_write_op *op)
int bch2_migrate_index_update(struct bch_write_op *op)
{
struct bch_fs *c = op->c;
struct btree_trans trans;
@ -266,11 +266,11 @@ int bch2_migrate_write_init(struct bch_fs *c, struct migrate_write *m,
m->op.flags |= BCH_WRITE_PAGES_STABLE|
BCH_WRITE_PAGES_OWNED|
BCH_WRITE_DATA_ENCODED|
BCH_WRITE_FROM_INTERNAL;
BCH_WRITE_FROM_INTERNAL|
BCH_WRITE_MOVE;
m->op.nr_replicas = data_opts.nr_replicas;
m->op.nr_replicas_required = data_opts.nr_replicas;
m->op.index_update_fn = bch2_migrate_index_update;
switch (data_cmd) {
case DATA_ADD_REPLICAS: {

View file

@ -41,6 +41,7 @@ struct migrate_write {
struct bch_write_op op;
};
int bch2_migrate_index_update(struct bch_write_op *);
void bch2_migrate_read_done(struct migrate_write *, struct bch_read_bio *);
int bch2_migrate_write_init(struct bch_fs *, struct migrate_write *,
struct write_point_specifier,