Thanks to visit codestin.com
Credit goes to github.com

Skip to content

vmm: Revert "vmm: create memfd for private mappings" - #8246

Merged
rbradford merged 1 commit into
cloud-hypervisor:mainfrom
rbradford:202605/revert-memfd-private
May 18, 2026
Merged

rbradford merged 1 commit into
cloud-hypervisor:mainfrom
rbradford:202605/revert-memfd-private

Conversation

@rbradford

Copy link
Copy Markdown
Member

This reverts commit ced3762.

This change lead to a serious memory regression when not using hugepages
or shared=on.

MAP_PRIVATE creates an anonymous memory allocation for every page
written when the backing store is a file. This CoW behaviour is useful
but leads to double allocations when the backing store is an empty file
created by memfd_create(). When the page is written to, the CoW
semantics require a real page to be created in the memory for the memfd
(previously before the page was touched they would all point to the zero
page). This real page is filled with zeroes because in theory this page
would be accessible via read/write syscalls on the FD even though in our
implementation it is only ever mmap()ed.

The intention of the commit was to enable fallocate() to be used to
punch holes but that would only affect the inaccessible backing page and
the page in the CoW anonymous memory would be unaffected. Leading it
likely not to have the desired effect.

Fixes: #8211

Signed-off-by: Rob Bradford [email protected]

This reverts commit ced3762.

This change lead to a serious memory regression when not using hugepages
or shared=on.

`MAP_PRIVATE` creates an anonymous memory allocation for every page
written when the backing store is a file. This CoW behaviour is useful
but leads to double allocations when the backing store is an empty file
created by `memfd_create()`. When the page is written to, the CoW
semantics require a real page to be created in the memory for the memfd
(previously before the page was touched they would all point to the zero
page). This real page is filled with zeroes because in theory this page
would be accessible via read/write syscalls on the FD even though in our
implementation it is only ever `mmap()`ed.

The intention of the commit was to enable `fallocate()` to be used to
punch holes but that would only affect the inaccessible backing page and
the page in the CoW anonymous memory would be unaffected. Leading it
likely not to have the desired effect.

Fixes: cloud-hypervisor#8211

Signed-off-by: Rob Bradford <[email protected]>
@rbradford
rbradford requested a review from a team as a code owner May 18, 2026 12:34

@phip1611 phip1611 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! We were also wondering about OOM issues in our pipeline...

ping @snue

@rbradford

Copy link
Copy Markdown
Member Author

I also considered fixing it by using MAP_SHARED on the default path - that would avoid having the duplicated page (no CoW - page writes just hit the memfd) but then I feel like I would rather just do #8188

@rbradford

Copy link
Copy Markdown
Member Author

@phip1611 It's strange how this didn't affect the Windows runs on the PR itself or later ones. Nor was it picked up by the test_memory_mergeable tests.

@rbradford
rbradford enabled auto-merge May 18, 2026 12:43

@weltling weltling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've been experimenting with this for several hours, too. The OOM symptom
could be fixed by readding MAP_ANONYMOUS, but that would undermine the initial intention for fallocate. The behaviors probably need to be tied to the console options, so then corresponding flags combinations would be used.

Thanks!

@rbradford
rbradford added this pull request to the merge queue May 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks May 18, 2026
@rbradford
rbradford merged commit 547a789 into cloud-hypervisor:main May 18, 2026
41 checks passed
@rbradford
rbradford deleted the 202605/revert-memfd-private branch June 12, 2026 10:35
@rbradford rbradford added the bug-fix Bug fix to include in release notes label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix Bug fix to include in release notes

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Windows integration test worker is failing due to SIGKILL

3 participants