Commit 8f82280e authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Use one buffer for sorting whiteouts

We're not really supposed to allocate from the same mempool more than
once.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent c297a763
...@@ -118,30 +118,32 @@ static void sort_bkey_ptrs(const struct btree *bt, ...@@ -118,30 +118,32 @@ static void sort_bkey_ptrs(const struct btree *bt,
static void bch2_sort_whiteouts(struct bch_fs *c, struct btree *b) static void bch2_sort_whiteouts(struct bch_fs *c, struct btree *b)
{ {
struct bkey_packed *new_whiteouts, **whiteout_ptrs, *k; struct bkey_packed *new_whiteouts, **ptrs, **ptrs_end, *k;
bool used_mempool1 = false, used_mempool2 = false; bool used_mempool = false;
unsigned order, i, nr = 0; unsigned order;
if (!b->whiteout_u64s) if (!b->whiteout_u64s)
return; return;
order = get_order(b->whiteout_u64s * sizeof(u64)); order = get_order(b->whiteout_u64s * sizeof(u64));
new_whiteouts = btree_bounce_alloc(c, order, &used_mempool1); new_whiteouts = btree_bounce_alloc(c, order, &used_mempool);
whiteout_ptrs = btree_bounce_alloc(c, order, &used_mempool2);
ptrs = ptrs_end = ((void *) new_whiteouts + (PAGE_SIZE << order));
for (k = unwritten_whiteouts_start(c, b); for (k = unwritten_whiteouts_start(c, b);
k != unwritten_whiteouts_end(c, b); k != unwritten_whiteouts_end(c, b);
k = bkey_next(k)) k = bkey_next(k))
whiteout_ptrs[nr++] = k; *--ptrs = k;
sort_bkey_ptrs(b, whiteout_ptrs, nr); sort_bkey_ptrs(b, ptrs, ptrs_end - ptrs);
k = new_whiteouts; k = new_whiteouts;
for (i = 0; i < nr; i++) { while (ptrs != ptrs_end) {
bkey_copy(k, whiteout_ptrs[i]); bkey_copy(k, *ptrs);
k = bkey_next(k); k = bkey_next(k);
ptrs++;
} }
verify_no_dups(b, new_whiteouts, verify_no_dups(b, new_whiteouts,
...@@ -150,8 +152,7 @@ static void bch2_sort_whiteouts(struct bch_fs *c, struct btree *b) ...@@ -150,8 +152,7 @@ static void bch2_sort_whiteouts(struct bch_fs *c, struct btree *b)
memcpy_u64s(unwritten_whiteouts_start(c, b), memcpy_u64s(unwritten_whiteouts_start(c, b),
new_whiteouts, b->whiteout_u64s); new_whiteouts, b->whiteout_u64s);
btree_bounce_free(c, order, used_mempool2, whiteout_ptrs); btree_bounce_free(c, order, used_mempool, new_whiteouts);
btree_bounce_free(c, order, used_mempool1, new_whiteouts);
} }
static bool should_compact_bset(struct btree *b, struct bset_tree *t, static bool should_compact_bset(struct btree *b, struct bset_tree *t,
......
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