Repository navigation
Use talc as the guest heap allocator - #1928
Conversation
This comment has been minimized.
This comment has been minimized.
6919f7f to
b364493
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The unsafe heap claim lacks the required safety justification for its exclusive memory ownership invariant.
1 open finding
What changed in this PR
Switches the guest heap allocator to talc to reduce page touches during sandbox initialization.
Changes:
- Replaces
buddy_system_allocatorwith mutex-protectedtalc. - Updates dependency locks and changelog documentation.
| File | Description |
|---|---|
src/hyperlight_guest_bin/src/lib.rs |
Implements and initializes the talc guest allocator. |
src/hyperlight_guest_bin/Cargo.toml |
Replaces the allocator dependency. |
Cargo.lock |
Updates workspace dependencies. |
src/tests/rust_guests/Cargo.lock |
Updates guest test dependencies. |
CHANGELOG.md |
Documents the performance improvement. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
b364493 to
c3a949a
Compare
This comment has been minimized.
This comment has been minimized.
c3a949a to
844a1bf
Compare
This comment has been minimized.
This comment has been minimized.
andreiltd
left a comment
There was a problem hiding this comment.
Nice! I wonder about using locking api rather than cell which talc seems to support as well? This would require unsafe impl Sync wrapper but would avoid atomic locking overhead?
Off-topic: there is an interesting article: https://matklad.github.io/2020/01/02/spinlocks-considered-harmful.html. The interrupts part I think is relevant to hyperligiht because interrupt handler can allocate while the interrupted code holds the heap lock.
I tried the Cell option first, and it works, but decided to go with the lock instead to mimic current behavior (and I think deadlocking is slightly preferable to silent heap corruption?). The article was interesting indeed, we need to be careful we don't allocate heap in an exception handler |
844a1bf to
b55b4ad
Compare
This comment has been minimized.
This comment has been minimized.
b55b4ad to
e92a004
Compare
This comment has been minimized.
This comment has been minimized.
e92a004 to
ed6a16a
Compare
ed6a16a to
39f4ba1
Compare
This comment has been minimized.
This comment has been minimized.
buddy_system_allocator writes a free-list pointer at the start of every power-of-two heap block during guest init. talc writes only the start and end of the heap. The host populates snapshot memory on first guest touch, so fewer written pages make sandbox creation faster. Criterion sandboxes/create_initialized: * MSHV: 25% to 37% faster for small to large heaps * KVM: 9% to 11% faster for small and large heaps Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Add a SAFETY comment to the guest heap claim. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
39f4ba1 to
a8850fc
Compare
jsturtevant
left a comment
There was a problem hiding this comment.
Nice improvement for such a small change, really interesting that the its so close in api!
Benchmark ResultsMeasured commit: kvm / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
kvm / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / amd (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / intel (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
Reported by |

Switch the guest heap allocator from
buddy_system_allocatortotalc.buddy_system_allocatorinit writes a free-list pointer at the start of every power-of-two heap block.talcwrites only the start and end of the heap, so guest init touches fewer heap pages.talcruns behind aspinmutex, astalcrecommends.spinis already a dependency.Benchmarks
Compared to
main. MSHV runs Linux 6.6.137.mshv2-5 and 6.6.100.mshv1-2. KVM runs Linux 6.17.sandboxes/create_initialized/smallsandboxes/create_initialized/mediumsandboxes/create_initialized/largesnapshot_files/cold_start_via_evolve/smallOn 6.6.137 each first touch populates a 2 MiB chunk, and buddy's init touches 2 to 7 more chunks than
talc. 6.6.100 is unchanged because it pins guest memory. Other benchmarks are unchanged.Related to #343 but not closing it, as we might want to still evaluate mimalloc or snmalloc, which would require a bigger chunk of work