Repository navigation
virtio-devices: balloon: Remap released copy-on-write memory - #7
Merged
Merged
Conversation
A VM restored with memory_restore_mode=copyonwrite maps the snapshot file MAP_PRIVATE over its guest RAM. MADV_DONTNEED there only drops the private copy: the next guest touch of a released page, even a write, faults the page back in from the snapshot file with read-around. With free page reporting on, every page the guest frees and reuses pays that read. Map anonymous memory over the 2 MiB-aligned part of each released range instead, so a reused page is zero-filled without I/O. The head and tail below 2 MiB keep MADV_DONTNEED, which bounds the mappings to one per 2 MiB of guest RAM, well under vm.max_map_count. The new mapping keeps the region's MAP_NORESERVE, and a failed mmap falls back to MADV_DONTNEED. The remapped range gets MADV_DONTDUMP like the rest of guest RAM, and MADV_NOHUGEPAGE: a private copy of a file page is 4 KiB today, and hugepage memory never takes the copy-on-write restore path, so a reused page keeps costing 4 KiB instead of a 2 MiB host page. An overlay region still records itself as anonymous, so the memory manager notes that the overlay was mapped and the balloon remaps only then. OnDemand restore never remaps, which would drop the userfaultfd registration. Signed-off-by: CMGS <ilskdw@gmail.com>
Signed-off-by: CMGS <ilskdw@gmail.com>
Signed-off-by: CMGS <ilskdw@gmail.com>
Signed-off-by: CMGS <ilskdw@gmail.com>
…est RAM Signed-off-by: CMGS <ilskdw@gmail.com>
Inflate ranges never exceed one 256 PFN batch, so they cannot hold an aligned 2 MiB chunk; pass false there and keep the partial page helper as upstream has it. Whole chunks filled by inflate are still remapped by the chunk bitmap, and free page reporting still remaps directly. Issue one MADV_DONTNEED when a range holds no full chunk instead of two adjacent ones, use advise_memory_range for the remap advice, and compare the chunk bitmap as an array. Fold the duplicate remap test into release_cow_restored_remaps_aligned_part. Signed-off-by: CMGS <ilskdw@gmail.com>
Error::MadviseFail displays only "Madvise fail.", so log it with Debug to keep the errno, as the other advise_memory_range callers do. Signed-off-by: CMGS <ilskdw@gmail.com>
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.
Fixes the virtio-balloon refault on copy-on-write restored guest RAM, for free page reporting and for inflated 2 MiB chunks.
memory_restore_mode=copyonwritemaps the snapshot file MAP_PRIVATE over guest RAM, but the region still records itself as anonymous. So the balloon (inflate and free page reporting) released it with MADV_DONTNEED, and every reused page faulted back in from the snapshot file with read-around.cow_restored), andBalloon::newtakes it.release_memory_rangemaps anonymous memory (MAP_FIXED, keeping the region's MAP_NORESERVE) over the 2 MiB-aligned part of the range, then applies MADV_DONTDUMP and MADV_NOHUGEPAGE. The sub-2 MiB head and tail keep MADV_DONTNEED, which bounds the mappings to one per 2 MiB of guest RAM. A failed mmap falls back to MADV_DONTNEED.Gates (node1, b645779): fmt, typos, 4 clippy variants, fuzz check, virtio-devices 173 tests incl. 22 balloon tests. On an earlier revision: the remap test failed with the fix disabled, arm64 clippy and balloon tests passed.
Hardware (testbed, 16 CoW clones under a 16 GiB cgroup cap):
Squash commit message: