Skip to content

bforest: Allocate all nodes upfront for insertion - #14637

Open
adamrk wants to merge 6 commits into
bytecodealliance:mainfrom
adamrk:abk/bforest-split-oom
Open

adamrk wants to merge 6 commits into
bytecodealliance:mainfrom
adamrk:abk/bforest-split-oom

Conversation

@adamrk

@adamrk adamrk commented Oct 9, 2026

Copy link
Copy Markdown
Member

When we need to split nodes in a bforest to perform an insertion, allocate
the worst case depth + 1 nodes all up front so that the insertion
atomically completes or fails. Otherwise the bforest can drop nodes that
were in the tree.

adamrk added 4 commits October 9, 2026 15:55
When we need to split nodes in a bforest to perform an insertion, allocate
the worst case depth + 1 nodes all up front so that the insertion
atomically completes or fails. Otherwise the bforest can silently drop
nodes that were in the tree.
@adamrk
adamrk requested review from a team as code owners October 9, 2026 20:29
@adamrk
adamrk requested review from alexcrichton and removed request for a team October 9, 2026 20:29
Comment on lines -1102 to +1134
assert_eq!(m.tpath(110, f, &()), "node2[0]--node0[0]");
assert_eq!(m.tpath(140, f, &()), "node2[0]--node0[3]");
assert_eq!(m.tpath(210, f, &()), "node2[1]--node1[0]");
assert_eq!(m.tpath(270, f, &()), "node2[1]--node1[6]");
assert_eq!(m.tpath(310, f, &()), "node2[2]--node3[0]");
assert_eq!(m.tpath(810, f, &()), "node2[7]--node8[0]");
assert_eq!(m.tpath(870, f, &()), "node2[7]--node8[6]");
assert_eq!(m.tpath(110, f, &()), "node1[0]--node0[0]");
assert_eq!(m.tpath(140, f, &()), "node1[0]--node0[3]");
assert_eq!(m.tpath(210, f, &()), "node1[1]--node2[0]");
assert_eq!(m.tpath(270, f, &()), "node1[1]--node2[6]");
assert_eq!(m.tpath(310, f, &()), "node1[2]--node5[0]");
assert_eq!(m.tpath(810, f, &()), "node1[7]--node10[0]");
assert_eq!(m.tpath(870, f, &()), "node1[7]--node10[6]");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of these tests change because the node ids are different now. This is because 1) when reserving, the nodes end up in the free list in the opposite order in which the were allocated and 2) we reserve the worst case each time instead of the exact amount needed. I was thinking that making those changes isn't worth the added complexity.

@alexcrichton
alexcrichton requested review from fitzgen and removed request for alexcrichton October 9, 2026 20:34
@alexcrichton

Copy link
Copy Markdown
Member

I'll defer this to @fitzgen as he's more familiar with this than I, but I'd recommend against a test-only bool to fail allocations and instead relying only on the OOM test/fuzz harness we have for handling that. Could the tests be moved over there for OOM-related things?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants