Skip to content

[v1.14] Expose memory mapping & dirty pages; Make memfile dump optional#8

Draft
bchalios wants to merge 6 commits intofirecracker-v1.14from
firecracker-v1.14-direct-mem
Draft

[v1.14] Expose memory mapping & dirty pages; Make memfile dump optional#8
bchalios wants to merge 6 commits intofirecracker-v1.14from
firecracker-v1.14-direct-mem

Conversation

@bchalios
Copy link

@bchalios bchalios commented Feb 5, 2026

WIP

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 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.

@bchalios bchalios marked this pull request as draft February 5, 2026 19:16
@ValentaTomas ValentaTomas added the wontfix This will not be worked on label Feb 5, 2026
@bchalios bchalios force-pushed the firecracker-v1.14-direct-mem branch from 88151c3 to 89538bc Compare February 5, 2026 20:20
Babis Chalios added 6 commits February 12, 2026 10:24
Add a few APIs to get information about guest memory:

* An endpoint for guest memory mappings (guest physical to host
  virtual).
* An endpoint for resident and empty pages.
* An endpoint for dirty pages.

Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
There are cases where a user might want to snapshot the memoyr of a VM
externally. In these cases, we can ask Firecracker to avoid serializing
the memory file to disk when we create a snapshot.

Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
Implement API /memory/mappings which returns the memory mappings of
guest physical to host virtual memory.

Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
Implement API /memory which returns two bitmaps: resident and empty.
`resident` tracks whether a guest page is in the resident set and `empty`
tracks whether it's actually all 0s.

Both bitmaps are structures as vectors of u64, so their length is:
total_number_of_pages.div_ceil(64).

Pages are ordered in the order of pages as reported by/memory/mappings.

Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
Implement API /memory/dirty which returns a bitmap tracking dirty guest
memory. The bitmap is structured as a vector of u64, so its length is:
total_number_of_pages.div_ceil(64).

Pages are ordered in the order of pages as reported by /memory/mappings.

Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
UFFD provides an API to enable write-protection for memory ranges
tracked by a userfault file descriptor. Detailed information can be
found here: https://docs.kernel.org/admin-guide/mm/userfaultfd.html.

To use the feature, users need to register the memory region with
UFFDIO_REGISTER_MODE_WP. Then, users need to enable explicitly
write-protection for sub-ranges of the registered region.

Writes in pages within write-protected memory ranges can be handled in
one of two ways. In synchronous mode, writes in a protected page will
cause kernel to send a write protection event over the userfaultfd.
In asynchronous mode, the kernel will automatically handle writes to
protected pages by clearing the write-protection bit. Userspace can
later observe the write protection bit by looking into the corresponding
entry of /proc/<pid>/pagemap.

This commit, uncoditionally, enables write protection for guest memory
using the asynchronous mode.

!NOTE!: asynchronous write protection requires (host) kernel version 6.7
or later).

Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
impl PagemapReader {
/// Create a new PagemapReader
pub fn new(_page_size: usize) -> Result<Self, PagemapError> {
let pagemap_fd = File::open("/proc/self/pagemap").map_err(PagemapError::OpenPagemap)?;
Copy link
Member

@ValentaTomas ValentaTomas Feb 13, 2026

Choose a reason for hiding this comment

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

Do we need to close this file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants