Commit 0cc455b3 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Inlining improvements

 - Don't call into bch2_encrypt_bio() when we're not encrypting
 - Pull slowpath out of trans_lock_write()
 - Make sure bc2h_trans_journal_res_get() gets inlined.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 182c7bbf
...@@ -1160,7 +1160,7 @@ int __must_check bch2_btree_path_traverse(struct btree_trans *trans, ...@@ -1160,7 +1160,7 @@ int __must_check bch2_btree_path_traverse(struct btree_trans *trans,
btree_path_traverse_one(trans, path, flags, _RET_IP_); btree_path_traverse_one(trans, path, flags, _RET_IP_);
} }
static void btree_path_copy(struct btree_trans *trans, struct btree_path *dst, static inline void btree_path_copy(struct btree_trans *trans, struct btree_path *dst,
struct btree_path *src) struct btree_path *src)
{ {
unsigned i, offset = offsetof(struct btree_path, pos); unsigned i, offset = offsetof(struct btree_path, pos);
...@@ -1189,6 +1189,7 @@ static struct btree_path *btree_path_clone(struct btree_trans *trans, struct btr ...@@ -1189,6 +1189,7 @@ static struct btree_path *btree_path_clone(struct btree_trans *trans, struct btr
return new; return new;
} }
__flatten
struct btree_path *__bch2_btree_path_make_mut(struct btree_trans *trans, struct btree_path *__bch2_btree_path_make_mut(struct btree_trans *trans,
struct btree_path *path, bool intent) struct btree_path *path, bool intent)
{ {
......
...@@ -291,7 +291,7 @@ bch2_trans_journal_preres_get_cold(struct btree_trans *trans, unsigned u64s, ...@@ -291,7 +291,7 @@ bch2_trans_journal_preres_get_cold(struct btree_trans *trans, unsigned u64s,
return 0; return 0;
} }
static inline int bch2_trans_journal_res_get(struct btree_trans *trans, static __always_inline int bch2_trans_journal_res_get(struct btree_trans *trans,
unsigned flags) unsigned flags)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
...@@ -729,33 +729,34 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, ...@@ -729,33 +729,34 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
return ret; return ret;
} }
static noinline int trans_lock_write_fail(struct btree_trans *trans, struct btree_insert_entry *i)
{
while (--i >= trans->updates) {
if (same_leaf_as_prev(trans, i))
continue;
bch2_btree_node_unlock_write(trans, i->path, insert_l(i)->b);
}
trace_and_count(trans->c, trans_restart_would_deadlock_write, trans);
return btree_trans_restart(trans, BCH_ERR_transaction_restart_would_deadlock_write);
}
static inline int trans_lock_write(struct btree_trans *trans) static inline int trans_lock_write(struct btree_trans *trans)
{ {
struct btree_insert_entry *i; struct btree_insert_entry *i;
int ret;
trans_for_each_update(trans, i) { trans_for_each_update(trans, i) {
if (same_leaf_as_prev(trans, i)) if (same_leaf_as_prev(trans, i))
continue; continue;
ret = bch2_btree_node_lock_write(trans, i->path, &insert_l(i)->b->c); if (bch2_btree_node_lock_write(trans, i->path, &insert_l(i)->b->c))
if (ret) return trans_lock_write_fail(trans, i);
goto fail;
bch2_btree_node_prep_for_write(trans, i->path, insert_l(i)->b); bch2_btree_node_prep_for_write(trans, i->path, insert_l(i)->b);
} }
return 0; return 0;
fail:
while (--i >= trans->updates) {
if (same_leaf_as_prev(trans, i))
continue;
bch2_btree_node_unlock_write_inlined(trans, i->path, insert_l(i)->b);
}
trace_and_count(trans->c, trans_restart_would_deadlock_write, trans);
return btree_trans_restart(trans, BCH_ERR_transaction_restart_would_deadlock_write);
} }
static noinline void bch2_drop_overwrites_from_journal(struct btree_trans *trans) static noinline void bch2_drop_overwrites_from_journal(struct btree_trans *trans)
......
...@@ -316,7 +316,7 @@ struct bch_csum bch2_checksum_bio(struct bch_fs *c, unsigned type, ...@@ -316,7 +316,7 @@ struct bch_csum bch2_checksum_bio(struct bch_fs *c, unsigned type,
return __bch2_checksum_bio(c, type, nonce, bio, &iter); return __bch2_checksum_bio(c, type, nonce, bio, &iter);
} }
int bch2_encrypt_bio(struct bch_fs *c, unsigned type, int __bch2_encrypt_bio(struct bch_fs *c, unsigned type,
struct nonce nonce, struct bio *bio) struct nonce nonce, struct bio *bio)
{ {
struct bio_vec bv; struct bio_vec bv;
......
...@@ -61,9 +61,17 @@ int bch2_rechecksum_bio(struct bch_fs *, struct bio *, struct bversion, ...@@ -61,9 +61,17 @@ int bch2_rechecksum_bio(struct bch_fs *, struct bio *, struct bversion,
struct bch_extent_crc_unpacked *, struct bch_extent_crc_unpacked *,
unsigned, unsigned, unsigned); unsigned, unsigned, unsigned);
int bch2_encrypt_bio(struct bch_fs *, unsigned, int __bch2_encrypt_bio(struct bch_fs *, unsigned,
struct nonce, struct bio *); struct nonce, struct bio *);
static inline int bch2_encrypt_bio(struct bch_fs *c, unsigned type,
struct nonce nonce, struct bio *bio)
{
return bch2_csum_type_is_encryption(type)
? __bch2_encrypt_bio(c, type, nonce, bio)
: 0;
}
int bch2_decrypt_sb_key(struct bch_fs *, struct bch_sb_field_crypt *, int bch2_decrypt_sb_key(struct bch_fs *, struct bch_sb_field_crypt *,
struct bch_key *); struct bch_key *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment