diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-04-17 15:54:14 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-04-17 16:10:10 -0400 |
commit | dd0f47902c72e38a1d6d6eae3b51f2f1804ac8a3 (patch) | |
tree | 3e2528e278a9ae679fa3708011481d0d2eae474a | |
parent | e5e8f203d77f90d1af8ebfd794eb1593582b85cc (diff) |
bcachefs: alloc tagging support for bkey bufs
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/bkey_buf.h | 49 | ||||
-rw-r--r-- | include/linux/alloc_tag.h | 8 |
2 files changed, 30 insertions, 27 deletions
diff --git a/fs/bcachefs/bkey_buf.h b/fs/bcachefs/bkey_buf.h index a30c4ae8eb36..8031cae39c30 100644 --- a/fs/bcachefs/bkey_buf.h +++ b/fs/bcachefs/bkey_buf.h @@ -10,41 +10,36 @@ struct bkey_buf { u64 onstack[12]; }; -static inline void bch2_bkey_buf_realloc(struct bkey_buf *s, +static inline void bch2_bkey_buf_realloc_noprof(struct bkey_buf *s, struct bch_fs *c, unsigned u64s) { if (s->k == (void *) s->onstack && u64s > ARRAY_SIZE(s->onstack)) { - s->k = mempool_alloc(&c->large_bkey_pool, GFP_NOFS); + s->k = mempool_alloc_noprof(&c->large_bkey_pool, GFP_NOFS); memcpy(s->k, s->onstack, sizeof(s->onstack)); } } -static inline void bch2_bkey_buf_reassemble(struct bkey_buf *s, - struct bch_fs *c, - struct bkey_s_c k) -{ - bch2_bkey_buf_realloc(s, c, k.k->u64s); - bkey_reassemble(s->k, k); -} - -static inline void bch2_bkey_buf_copy(struct bkey_buf *s, - struct bch_fs *c, - struct bkey_i *src) -{ - bch2_bkey_buf_realloc(s, c, src->k.u64s); - bkey_copy(s->k, src); -} - -static inline void bch2_bkey_buf_unpack(struct bkey_buf *s, - struct bch_fs *c, - struct btree *b, - struct bkey_packed *src) -{ - bch2_bkey_buf_realloc(s, c, BKEY_U64s + - bkeyp_val_u64s(&b->format, src)); - bch2_bkey_unpack(b, s->k, src); -} +#define bch2_bkey_buf_realloc(...) alloc_hooks_void(bch2_bkey_buf_realloc_noprof(__VA_ARGS__)) + +#define bch2_bkey_buf_reassemble(_s, _c, _k) \ +do { \ + bch2_bkey_buf_realloc(_s, _c, (_k).k->u64s); \ + bkey_reassemble((_s)->k, _k); \ +} while (0) + +#define bch2_bkey_buf_copy(_s, _c, _src) \ +do { \ + bch2_bkey_buf_realloc(_s, _c, (_src)->k.u64s); \ + bkey_copy((_s)->k, _src); \ +} while (0) + +#define bch2_bkey_buf_unpack(_s, _c, _b, _src) \ +do { \ + bch2_bkey_buf_realloc(_s, _c, BKEY_U64s + \ + bkeyp_val_u64s(&_b->format, _src)); \ + bch2_bkey_unpack(_b, (_s)->k, _src); \ +} while (0) static inline void bch2_bkey_buf_init(struct bkey_buf *s) { diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 100ddf66eb8e..cf04d71b5fce 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -202,4 +202,12 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) {} alloc_hooks_tag(&_alloc_tag, _do_alloc); \ }) +#define alloc_hooks_void(_do) \ +do { \ + DEFINE_ALLOC_TAG(_tag); \ + struct alloc_tag * __maybe_unused _old = alloc_tag_save(&_tag); \ + _do; \ + alloc_tag_restore(&_tag, _old); \ +} while (0) + #endif /* _LINUX_ALLOC_TAG_H */ |