Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start dirty page tracking implementation in vm-memory. #2149

Conversation

sandreim
Copy link
Contributor

@sandreim sandreim commented Sep 29, 2020

Reason for This PR

Bootstrap implementation for dirty page tracking in vm-memory - #1997

Thanks @alexandruag for providing insight/PoC on the proxy crate approach.

Description of Changes

Create a "proxy" crate that Firecracker will use as a dependency for all current vm-memory imports. This crate will export local GuestMemoryMmap and GuestRegionMap implementations that will contain dirty page tracking functionality. All other re-exports will be fetched from upstream vm-memory.

  • This functionality can be added in rust-vmm.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any newly added unsafe code is properly documented.
  • Any API changes are reflected in firecracker/swagger.yaml.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

@sandreim sandreim changed the title Start dirty page tracking implementation. Start dirty page tracking implementation in vm-memory. Sep 29, 2020
@sandreim sandreim force-pushed the local_memory_backend branch 2 times, most recently from 0e20ced to d6f1935 Compare September 29, 2020 11:27
src/arch/Cargo.toml Outdated Show resolved Hide resolved
@alxiord
Copy link

alxiord commented Sep 29, 2020

I may have gotten it backwards - I was thinking that Firecracker will continue consuming rust-vmm/vm-memory, but instead of using rust-vmm/vm-memory::GuestMemoryMmap all over the place, Firecracker would add its own struct GuestMemoryMmapWithTracking (or something) and impl rust-vmm/vm-memory::GuestMemory for firecracker::GuestMemoryMmapWithTracking (disregard rustlang blasphemy). That way we don't have to kill the dependency. Did we move away from that? What's the advantage of removing the dependency, other than renaming GuestMemoryMmap everywhere?

@sandreim
Copy link
Contributor Author

I may have gotten it backwards - I was thinking that Firecracker will continue consuming rust-vmm/vm-memory, but instead of using rust-vmm/vm-memory::GuestMemoryMmap all over the place, Firecracker would add its own struct GuestMemoryMmapWithTracking (or something) and impl rust-vmm/vm-memory::GuestMemory for firecracker::GuestMemoryMmapWithTracking (disregard rustlang blasphemy). That way we don't have to kill the dependency. Did we move away from that? What's the advantage of removing the dependency, other than renaming GuestMemoryMmap everywhere?

The dependency to vm-memory from upstream is kept in the local proxy crate vm-memory-proxy and we override only what is needed with a local implementation. The rest of the FC code depends on the proxy crate which re-exports the upstream stuff.

@alxiord
Copy link

alxiord commented Sep 29, 2020

we override only what is needed with a local implementation

Why not create a new implementor for GuestMemory?

@raduweiss
Copy link
Contributor

we override only what is needed with a local implementation

Why not create a new implementor for GuestMemory?

FWIW I also understood the coupling in the way @aghecenco described it above.

@sandreim
Copy link
Contributor Author

sandreim commented Sep 29, 2020

we override only what is needed with a local implementation

Why not create a new implementor for GuestMemory?

FWIW I also understood the coupling in the way @aghecenco described it above.

The goal here is to do as few changes as possible to the interfaces we currently use in Firecracker with the hope that tracking will be available in upstream. The Firecracker code uses both the GuestMemory interface and also the GuestMemoryMmap backend directly. If we implement a new backend like GuestMemoryMmapTracked we would need to do more changes in Firecracker.

The approach in this PR is less invasive and completely transparent to Firecracker as we re-export all the stuff from upstream and we override only what's needed to support our usecase.

src/vm-memory/Cargo.toml Outdated Show resolved Hide resolved
@sandreim sandreim force-pushed the local_memory_backend branch 2 times, most recently from de40fbc to fe74a58 Compare September 30, 2020 06:10
- Import mmap.rs from rust-vmm/vm-memory v0.2.2.
- Added markers where write access needs to mark dirty bits
in bitmap.

Signed-off-by: Andrei Sandu <[email protected]>
@sandreim sandreim force-pushed the local_memory_backend branch from fe74a58 to 919410c Compare September 30, 2020 06:36
@sandreim sandreim requested a review from alxiord September 30, 2020 06:37
@sandreim sandreim force-pushed the local_memory_backend branch from 919410c to ba4635c Compare September 30, 2020 06:39
- update Cargo.toml for all crates
- implement AsSlice interface for GuestRegionMmap.

Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
@sandreim sandreim force-pushed the local_memory_backend branch from 31b92ea to d086a32 Compare September 30, 2020 10:31
@sandreim sandreim self-assigned this Sep 30, 2020
@dianpopa dianpopa added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Oct 1, 2020
Comment on lines +1095 to +1098
// Windows needs a dedicated test where it will retrieve the allocation
// granularity to determine a proper offset (other than 0) that can be
// used for the backing file. Refer to Microsoft docs here:
// https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-mapviewoffile
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should we keep this indication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right.

Comment on lines +4 to +6
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the THIRD-PARTY file.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is this still the case?

Comment on lines +1 to +3
// Copyright (C) 2019 Alibaba Cloud Computing. All rights reserved.
//
// Portions Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: For this local file where we add dirty tracking support, these two might be better reversed.

pub fn new(byte_size: usize, page_size: usize) -> Self {
// Bit size is the number of bits in the bitmap, always at least 1 (to store the state of
// the '0' address).
let bit_size = std::cmp::max(1, byte_size / page_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
let bit_size = std::cmp::max(1, byte_size / page_size);
let num_pages = std::cmp::max(1, byte_size / page_size);

for clarity.

Comment on lines +214 to +215
// TODO: This implementation is temporary.
// We need to return None here once we refactor vsock.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add an issue to track this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #2153

@sandreim sandreim merged commit c468676 into firecracker-microvm:feature/diff-snapshot Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting review Indicates that a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants