Skip to content

[Feat] New address allocator - #6364

Draft
ShadowCurse wants to merge 3 commits into
firecracker-microvm:mainfrom
ShadowCurse:new_address_allocator
Draft

ShadowCurse wants to merge 3 commits into
firecracker-microvm:mainfrom
ShadowCurse:new_address_allocator

Conversation

@ShadowCurse

Copy link
Copy Markdown
Contributor

Changes

Replace vm-allocator AddressAllocator with home made AddressAllocator. This brings some speed and memory savings with a much simpler internal implementation.

Since this was the last type used from vm-allocator crate, drop the crate.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkbuild --all to verify that the PR passes
    build checks on all supported architectures.
  • I have run tools/devtool checkstyle --no-clippy to verify that the PR
    passes the automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

@ShadowCurse ShadowCurse self-assigned this Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.08333% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.60%. Comparing base (76cb694) to head (57eb38b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/vmm/src/vstate/address_allocator.rs 92.76% 11 Missing ⚠️
src/vmm/src/devices/virtio/transport/pci/device.rs 78.26% 5 Missing ⚠️
src/vmm/src/builder.rs 80.00% 2 Missing ⚠️
src/vmm/src/devices/pci/pci_segment.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6364      +/-   ##
==========================================
+ Coverage   83.59%   83.60%   +0.01%     
==========================================
  Files         282      283       +1     
  Lines       33585    33712     +127     
==========================================
+ Hits        28074    28184     +110     
- Misses       5511     5528      +17     
Flag Coverage Δ
5.10-m5n.metal 83.75% <91.56%> (+<0.01%) ⬆️
5.10-m6a.metal 83.18% <91.56%> (+<0.01%) ⬆️
5.10-m6g.metal 80.89% <91.81%> (+0.02%) ⬆️
5.10-m6i.metal 83.75% <91.56%> (+<0.01%) ⬆️
5.10-m7a.metal-48xl 83.17% <91.56%> (+0.01%) ⬆️
5.10-m7g.metal 80.89% <91.81%> (+0.02%) ⬆️
5.10-m7i.metal-24xl 83.73% <91.56%> (+0.02%) ⬆️
5.10-m7i.metal-48xl 83.73% <91.56%> (+<0.01%) ⬆️
5.10-m8g.metal-24xl 80.89% <91.81%> (+0.04%) ⬆️
5.10-m8g.metal-48xl 80.89% <91.81%> (+0.02%) ⬆️
5.10-m8i.metal-48xl 83.72% <91.56%> (+<0.01%) ⬆️
5.10-m8i.metal-96xl 83.73% <91.56%> (+0.01%) ⬆️
5.10-m9g.metal-48xl 80.89% <91.81%> (+0.02%) ⬆️
6.1-m5n.metal 83.87% <91.56%> (+0.02%) ⬆️
6.1-m6a.metal 83.31% <91.56%> (+0.01%) ⬆️
6.1-m6g.metal 80.88% <91.81%> (+0.02%) ⬆️
6.1-m6i.metal 83.87% <91.56%> (+<0.01%) ⬆️
6.1-m7a.metal-48xl 83.30% <91.56%> (+<0.01%) ⬆️
6.1-m7g.metal 80.89% <91.81%> (+0.04%) ⬆️
6.1-m7i.metal-24xl 83.88% <91.56%> (+0.02%) ⬆️
6.1-m7i.metal-48xl 83.89% <91.56%> (+0.01%) ⬆️
6.1-m8g.metal-24xl 80.89% <91.81%> (+0.04%) ⬆️
6.1-m8g.metal-48xl 80.89% <91.81%> (+0.02%) ⬆️
6.1-m8i.metal-48xl 83.88% <91.56%> (+0.01%) ⬆️
6.1-m8i.metal-96xl 83.89% <91.56%> (+0.01%) ⬆️
6.1-m9g.metal-48xl 80.89% <91.81%> (+0.02%) ⬆️
6.18-m5n.metal 83.87% <91.56%> (+<0.01%) ⬆️
6.18-m6a.metal 83.31% <91.56%> (+0.01%) ⬆️
6.18-m6g.metal 80.98% <91.81%> (+0.02%) ⬆️
6.18-m6i.metal 83.87% <91.56%> (+0.01%) ⬆️
6.18-m7a.metal-48xl 83.30% <91.56%> (+0.01%) ⬆️
6.18-m7g.metal 80.98% <91.81%> (+0.04%) ⬆️
6.18-m7i.metal-24xl 83.88% <91.56%> (+0.02%) ⬆️
6.18-m7i.metal-48xl 83.88% <91.56%> (+<0.01%) ⬆️
6.18-m8g.metal-24xl 80.98% <91.81%> (+0.02%) ⬆️
6.18-m8g.metal-48xl 80.98% <91.81%> (+0.02%) ⬆️
6.18-m8i.metal-48xl 83.88% <91.56%> (+0.01%) ⬆️
6.18-m8i.metal-96xl 83.88% <91.56%> (+0.01%) ⬆️
6.18-m9g.metal-48xl 80.98% <91.81%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ShadowCurse
ShadowCurse force-pushed the new_address_allocator branch 2 times, most recently from 26935c6 to b0ad0e8 Compare October 30, 2026 18:17
Add new allocator of address ranges to replace the vm-allocator one. It
tries to keep more or less the same API but differs in the
implementation which gives it speed and memory usage benefits.

The basic design of new allocator is to keep allocated ranges in a
sorted  static array, with free ranges being gaps between them.

Compared to vm-allocator, which keeps free and allocated ranges in an
interval tree of boxed nodes, measured on an m8g host with 16 to 255
allocated ranges:
- first and last match allocations are 4 to 9 times faster,
- an exact allocation followed by a free is 1.2 to 4.5 times faster
  with 16 ranges, and from 1.5 times faster to 4 times slower with 128
  and 255, as both shift the ranges after the one they insert or remove,
- cloning it for a snapshot takes a constant 53ns instead of 0.7us to
  11us,
- serializing and deserializing it is 70 to 450 times faster, and it
  takes 3.6 to 3.7 times less space in a snapshot.

Compared to the parts of vm-allocator 0.1.4 used by Firecracker (error
types, address allocator and interval tree), with coverage measured by
llvm-cov over each implementation's own unit tests:
- lines of code (excluding comments, blanks and tests): 591 vs 212,
- instrumented lines: 451 vs 223,
- line coverage: 90.2% vs 95.1%.

The new allocator also comes with Kani proofs that, for any valid
allocator, allocation with each policy and free behave as specified.

Signed-off-by: Egor Lazarchuk <[email protected]>
Replace vm-allocator with new address allocator.
Most noticable changes here are:
- new allocator returns first address of the allocation, so callers
don't need to call `.start()` all the time.
- freeing a range is done with start/len pairs instaed of ranges

Signed-off-by: Egor Lazarchuk <[email protected]>
Nothing uses it anymore.

Signed-off-by: Egor Lazarchuk <[email protected]>
@ShadowCurse
ShadowCurse force-pushed the new_address_allocator branch from b0ad0e8 to 57eb38b Compare October 30, 2026 18:32
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.

1 participant