Repository navigation
fix(orchestrator): preserve MAP_NORESERVE for guest memfd views - #3834
Closed
ClearLove181 wants to merge 1 commit into
Closed
ClearLove181 wants to merge 1 commit into
ClearLove181 wants to merge 1 commit into
Conversation
Avoid observer-induced HugeTLB reservations during lazy snapshot restore. Add a deterministic empty-pool regression and document reproduction steps. Preserve ENOMEM classification and existing placement policy.
ClearLove181
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
November 17, 2026 03:47
|
We require contributors to sign our Contributor License Agreement, and we don't have @ClearLove181 on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check' |
Contributor
|
Hey @ClearLove181, thanks for the careful write-up and repro! You're right that our read-only view is what reserves the huge pages, but that's on purpose: it lets a node refuse a sandbox it can't fully back at start, instead of the guest crashing later on a page fault the pool can't serve. So we'll pass on this one. For the pause → resume overlap, |
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.
Restoring a hugetlb-backed sandbox can fail in
NewFromFdbefore any guest page is read:Firecracker maps its guest memfd with
MAP_SHARED | MAP_NORESERVE, but the orchestrator's read-only mapping used onlyMAP_SHARED. For hugetlbfs, that observer establishes reservations for the file's unreserved range. With several sandboxes, or overlapping old/new memfds during pause and resume, this can fail even while ordinary RAM is available.This change adds
MAP_NORESERVEto the observer, preserving the owner's lazy-allocation policy.GuestMemoryErrorwrapping for genuine mmapENOMEMremains in place. It does not change placement checks or host hugepage settings, and it does not guarantee future page faults can succeed under actual memory exhaustion.The accounting change is intentional: an observer no longer adds the guest's unpopulated range to
HugePages_Rsvd. Deployments that require admission against configured guest RAM should use the explicit allocated-memory admission limit rather than relying on this read-only view to reserve it. Hugepage fault-time exhaustion remains possible, as it already is for the owner'sMAP_NORESERVEmapping.Regression and reproduction
TestNewFromFd_HugetlbNoReservationuses an empty 1 GiB hugepage pool with overcommit disabled. It creates a sparse memfd and a no-reservation owner mapping, verifies that a reserving observer returnsENOMEM, and then checks thatNewFromFdsucceeds. Neither mapping is accessed, so the test consumes no physical huge pages and changes no sysctl. Unsupported hosts or callers without hugetlb permissions report an explicit skip.Run from the repository root on a suitable Linux host:
Removing only
MAP_NORESERVEfromNewFromFdmakes the new regression fail withmmap memfd: cannot allocate memory; restoring the flag makes it pass. Detailed prerequisites and commands are indocs/debugging-memfd-hugetlb.md.Validation
Tested on Linux x86_64 (Ubuntu 24.04 / WSL2 kernel 6.6.87.2), using Go 1.27.3 and golangci-lint 2.15.0, based on
mainat391b224:mmap memfd: cannot allocate memoryand passes after the fix; it was executed, not skipped.go test -race -v -count=1 ./packages/orchestrator/pkg/sandbox/block -run 'TestNewFromFd|TestNewCacheFromMemfd|TestDedupedMemfdCache|TestMemfdIdentitySource'— passed, including the existingTestNewFromFdMarksENOMEMclassification test.go test -race -count=1 -timeout=5m ./packages/orchestrator/pkg/sandbox/block— the full block package passed.packages/orchestrator:golangci-lint run ./pkg/sandbox/block/... --timeout=5m— 0 issues.git diff --cached --check— passed.Repository-wide
make test/make lintand the KVM integration suite were not run; the current-main checks above are scoped to the affected package.The same fix was also backported to a self-hosted Linux deployment using 4 GiB sandboxes. The previously failing release then passed pause/resume, post-resume checks, destroy/recreate, and object-storage persistence verification. This deployment validation is separate from the current-main test results above.
Reference: Linux hugetlb reservation semantics.