fix(placement,fc): memory-aware sandbox placement and DeflateOnOom - #3380
Open
AdaAibaby wants to merge 1 commit into
Open
fix(placement,fc): memory-aware sandbox placement and DeflateOnOom#3380AdaAibaby wants to merge 1 commit into
AdaAibaby wants to merge 1 commit into
Conversation
Closes e2b-dev#3379. Three improvements to prevent host OOM and reduce avoidable in-guest OOM kills when sandboxes approach their Firecracker MemSizeMib limit. 1. Memory hard filter in BestOfK placement Add BestOfKConfig.M (memory overcommit ratio) populated from the new best-of-k-max-memory-overcommit feature flag (default 0 = disabled). When M > 0, sample() skips nodes where MemoryAllocatedBytes + requested > M × MemoryTotalBytes so sandboxes are never scheduled onto hosts without available memory. The filter is a no-op when M=0 (current behaviour) or when a node has not yet reported MemoryTotalBytes, preserving backward compat. 2. balloon DeflateOnOom = true The virtio-balloon was configured with DeflateOnOom=false, meaning pages returned to the host via free-page hinting were not given back to the guest when it approached its memory ceiling. Setting it to true allows Firecracker to deflate the balloon on demand, reducing avoidable in-guest OOM kills without changing the hard MemSizeMib ceiling enforced by the VMM. 3. Tests and helpers - 6 new table-driven tests cover all branches of the memory filter (disabled, full node, headroom, overcommit, unknown total, tiebreak) - WithTotalMemoryBytes TestOption added to the node mock so tests can express realistic memory scenarios without reaching into internals
ValentaTomas
force-pushed
the
main
branch
2 times, most recently
from
July 25, 2026 22:53
5aad415 to
d71980e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements all improvements from #3379. Three gaps in memory management are addressed:
1. Memory-aware placement filter (
BestOfKMaxMemoryOvercommitfeature flag)The BestOfK scheduler was purely CPU-aware — nodes were never filtered or scored on memory, creating a path to host OOM. This adds a hard memory filter in
sample()controlled by a new LaunchDarkly flag:A node is excluded from placement when:
Safety guards:
MemoryTotalBytes = 0(node hasn't checked in yet) → filter is skipped2. Balloon
DeflateOnOom = trueThe virtio-balloon was configured with
DeflateOnOom = false. When free-page hinting reclaimed idle pages from the guest and the guest later needed that memory, the balloon would not deflate — causing avoidable in-guest OOM kills. SettingDeflateOnOom = trueallows Firecracker to return those pages to the guest on demand. The FirecrackerMemSizeMibhard ceiling is unchanged.3. Test infrastructure
WithTotalMemoryBytes(bytes uint64)test helper added to the node mockFiles changed
packages/orchestrator/pkg/sandbox/fc/client.godeflateOnOom = truepackages/shared/pkg/featureflags/flags.goBestOfKMaxMemoryOvercommitflagpackages/api/internal/orchestrator/placement/placement_best_of_K.goM float64in config, memory filter insample()packages/api/internal/orchestrator/orchestrator.goMto configpackages/api/internal/orchestrator/nodemanager/mock.goWithTotalMemoryBytestest optionpackages/api/internal/orchestrator/placement/placement_memory_filter_test.gopackages/api/internal/orchestrator/placement/placement_best_of_K_test.gosample()call sitesRollout
MemoryAllocatedBytes/MemoryTotalBytesper node in existing dashboardsbest-of-k-max-memory-overcommit = 100in LaunchDarkly/cc @jakubno @dobrac @ValentaTomas @arkamar @tvi Looking forward to your code review.