Skip to content

Commit 4a9eb20

Browse files
author
Kent Overstreet
committed
bcachefs: Kill bkey_buf usage in data_update_index_update()
Reduce stack usage - bkey_buf has a 96 byte buffer on the stack, but the btree_trans bump allocator works just fine here. Signed-off-by: Kent Overstreet <[email protected]>
1 parent bfc0c6f commit 4a9eb20

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

fs/bcachefs/data_update.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,9 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
187187
struct data_update *m =
188188
container_of(op, struct data_update, op);
189189
struct keylist *keys = &op->insert_keys;
190-
struct bkey_buf _new, _insert;
191190
struct printbuf journal_msg = PRINTBUF;
192191
int ret = 0;
193192

194-
bch2_bkey_buf_init(&_new);
195-
bch2_bkey_buf_init(&_insert);
196-
bch2_bkey_buf_realloc(&_insert, c, U8_MAX);
197-
198193
bch2_trans_iter_init(trans, &iter, m->btree_id,
199194
bkey_start_pos(&bch2_keylist_front(keys)->k),
200195
BTREE_ITER_slots|BTREE_ITER_intent);
@@ -229,11 +224,22 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
229224
goto nowork;
230225
}
231226

232-
bkey_reassemble(_insert.k, k);
233-
insert = _insert.k;
227+
insert = bch2_trans_kmalloc(trans,
228+
bkey_bytes(k.k) +
229+
bkey_val_bytes(&new->k) +
230+
sizeof(struct bch_extent_rebalance));
231+
ret = PTR_ERR_OR_ZERO(insert);
232+
if (ret)
233+
goto err;
234+
235+
bkey_reassemble(insert, k);
236+
237+
new = bch2_trans_kmalloc(trans, bkey_bytes(&new->k));
238+
ret = PTR_ERR_OR_ZERO(new);
239+
if (ret)
240+
goto err;
234241

235-
bch2_bkey_buf_copy(&_new, c, bch2_keylist_front(keys));
236-
new = bkey_i_to_extent(_new.k);
242+
bkey_copy(&new->k_i, bch2_keylist_front(keys));
237243
bch2_cut_front(iter.pos, &new->k_i);
238244

239245
bch2_cut_front(iter.pos, insert);
@@ -457,8 +463,6 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
457463
out:
458464
printbuf_exit(&journal_msg);
459465
bch2_trans_iter_exit(trans, &iter);
460-
bch2_bkey_buf_exit(&_insert, c);
461-
bch2_bkey_buf_exit(&_new, c);
462466
BUG_ON(bch2_err_matches(ret, BCH_ERR_transaction_restart));
463467
return ret;
464468
}

0 commit comments

Comments
 (0)