-
Notifications
You must be signed in to change notification settings - Fork 82
Add replaceable-mmapped bitmap support #206
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
Conversation
|
/cc @XanClic |
05c4efa to
c85634b
Compare
|
This new version adds the bitmap support that was originally intended to be part of for the vm-memory crate: rust-vmm/vm-memory#264 |
|
How is this supposed to be used? Compared to the previous proposal (in vm-memory), if I replace What does compile and apparently also kind of works is to continue to use It’s questionable to me whether It feels like ideally we’d have a trait (maybe The problem with “is trait implemented or not” is that it’s not so easy in Rust and would require a whole new line of pub trait LogBitmap: Sized {
fn new<R: GuestMemoryRegion>(region: &R, logmem: MmapLogReg) -> io::Result<Self>;
}
pub trait LogBitmapRegion: Bitmap {
const CAN_LOG_DIRTY_WRITES: bool; // Can you really use this bitmap type for migration?
type Inner: LogBitmap;
fn replace(&self, bitmap: Self::Inner);
}And then this can be implemented for impl LogBitmap for () {
fn new<R: GuestMemoryRegion>(_region: &R, _logmem: MmapLogReg) -> io::Result<Self> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
"Back-end does not support logging memory modification, cannot migrate",
))
}
}
impl LogBitmapRegion for () {
const CAN_LOG_DIRTY_WRITES: bool = false;
type Inner = ();
fn replace(&self, _bitmap: ()) {}
}(And you just
Alternatively, the quick fix would be to just make |
c85634b to
1d0c045
Compare
|
v2:
|
stefano-garzarella
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about splitting the last commit in two since we are touching both vhost-user-backend and vhost crates?
Since it is a new feature, can you also add an entry on both vhost and vhost-user-backend changelog file?
1d0c045 to
120a04d
Compare
|
v3:
|
|
LGTM. Please, can you add an entry on both vhost and vhost-user-backend changelog for this new feature. Nit: maybe we can remove |
I knew I was forgetting something, sorry, yes I'll do it
Ok |
120a04d to
c76b191
Compare
|
v4:
|
a555ff0 to
ce64985
Compare
|
v5:
|
taking a quick look at qemu's code, I don't see any place where F_LOG_ALL is cleared in any case (there is something in vdpa but is unrelated) |
Yes, there isn’t any real harm, but it will cost a bit of performance after a cancelled migration, so would be nice to look into at some point at least. I think if desired we can introduce bitmap disabling locally here in the vhost-user-backend crate without modifications to vm-memory, just by adding a |
The current draft for virtiofsd does use clearing of F_LOG_ALL to recognize a cancelled migration. Note that qemu will call |
I still think is unnecessary right now, and I'm not sure about the performance gain either, we will need to check an AtomicBool even if we don't have a InnerBitmap. |
Ah... My brain assumed that that's what the replace would trigger :). But it certainly makes a lot more sense now! Do you already have actual starting of the logging implemented somewhere? I tried to look around in https://gitlab.com/virtiofsd-live-migration, but could not immediately spot it there. Would love to see how that works out API wise. Overall, it would have probably helped me if there would have been a more concrete mention that this is only part of the solution and other bits still have to follow (with a rough overview of what those pieces are). |
Sure. |
No, because that is part of vm-memory, it expects the bitmap exists at compile time, as I said before
I think I discussed it in the previous reviews |
Probably, but currently in the most common case (i.e., without a bitmap) we don't access any of that
Ok, I will implement the AtomicBool approach, otherwise I think we also need to take into account that we can receive a SET_FEATURE unrelated to live migration |
As far as I understand, it effectively does. The vm-memory crate calls Specifically,
Because so far I understood that attaching the bitmap to the mem regions would immediately start logging, there is nothing that virtiofsd does except to start aggregating its own internal state. |
but that is only for the internal state, keeping marking dirty pages will not interfere with it |
I was specifically talking about the cancelled migration case, and I did agree (“Sure.”) that we don’t necessarily need to address it now. If you want to implement disabling now, fine with me; if you don’t, also fine with me. I only said I believe this is something that should be looked into at some point, not necessarily now.
I don’t understand. It’s easy to find out whether F_LOG_ALL is being toggled by a SET_FEATURE call or not: We can just store in
I only gave this as an example to show that clearing F_LOG_ALL does occur. To be entirely clear, I still do not have any objection to this PR as-is. But from what I understand, with the PR as-is, logging does start when SET_LOG_BASE is called, and will never stop. Functionally, I don’t see any problem with that, but it is not correct as per spec, and in the case of a cancelled migration, seems like an admittedly most likely absolutely negligible waste of CPU cycles. Therefore, I do believe this should be addressed at some point in time, but not necessarily now. |
Ahh ok, sorry for the confusion (you know Mondays), ok I take note, and I'll work on a solution for a future PR, and do some testing, also I'll measure the performance impact. Thanks |
|
(Just for reference for a future PR, this is how I imagine it without using an atomic: https://czenczek.de/0001-Disable-bitmaps-unless-F_LOG_ALL.patch (github wouldn’t let me attach this file 🙁)) |
99c035f to
492cd28
Compare
|
No objections from my side, looks good to me. |
|
Ah, when skimming the discussion above I assumed that changes were planned. I still do not fully understand where we are and what is missing.
Probably all of this is clear to you being more familiar with the specs and implementations. Chances are that I am also just misunderstanding bits. But if this is not usable as it is yet and we do not have a full understanding of what the API needs will be in the end, then what do we gain by merging now? I expressed my worry about the additional trait complexities and I am happy to merge this if we have a road towards simplifying that, but it would be great to have the plans spelled out somewhere at least in a rough form. |
German knows this better than me, but I assume just because it’s simpler: There currently is no way to attach dirty bitmaps to memory regions (which we must do on SET_LOG_BASE) but keep them disabled. So that would need to be implemented.
Nothing. This MR works as-is for live migration with virtiofsd.
German knows this better, but if anything, the only problem I have with the API is that it requires specifying a bitmap type at all, because vhost-user should always use *State-less migration means it cannot transfer its internal state yet, but that’s a completely separate topic. |
OK. That's where I got confused. Thanks! I looked at https://gitlab.com/virtiofsd-live-migration and could not tell what exactly was missing.
Then let's document that either in a code comment or the commit log and merge? 🤔 |
492cd28 to
7d7697a
Compare
|
V7:
|
The vhost user protocol supports live migration, and during live migration, the vhost-user frontend needs to track the modifications the vhost-user backend makes to the memory mapped regions, marking the dirty pages in a log (i.e., a bitmap). If the backend has the VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol feature it will receive the VHOST_USER_SET_LOG_BASE message with a file descriptor of the dirty-pages log memory region. This log covers all known guest addresses, and must be manipulated atomically. For further info please see https://qemu-project.gitlab.io/qemu/interop/vhost-user.html#migration This commit adds support for creating an atomic-memory-mapped bitmap, and being able to replace it in runtime. The vhost user protocol does not specify whether the previous bitmap is still active after replying to the VHOST_USER_SET_LOG_BASE message, so we use an RwLock to be sure that the in-flight requests are using the new bitmap after the message reply. Signed-off-by: German Maglione <[email protected]>
Any bitmap used in the vhost-user backend must implement the BitmapReplace trait, which provides the functionality to replace the internal bitmap in runtime. This internal bitmap is required because in the vm-memory crate the bitmap is expected to exist at the time of creating the memory regions, and in the case of vhost-user the bitmap is added at runtime, also it could be replaced at a later time. In addition, the vhost user protocol does not specify whether the previous bitmap is still active after replying to the VHOST_USER_SET_LOG_BASE message, so we must be sure that the in-flight requests are using the new bitmap after the message reply. Signed-off-by: German Maglione <[email protected]>
If the backend has the VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol feature it will receive the VHOST_USER_SET_LOG_BASE message with a file descriptor of the dirty-pages log memory region. This log covers all known guest addresses, and must be manipulated atomically. For further info please see https://qemu-project.gitlab.io/qemu/interop/vhost-user.html#migration Signed-off-by: German Maglione <[email protected]>
7d7697a to
83bd2a0
Compare
|
Rebase |
Summary of the PR
The vhost user protocol supports live migration, and during live migration, the vhost-user frontend needs to track the modifications the vhost-user backend makes to the memory mapped regions, marking the dirty pages in a log (i.e., a bitmap).
If the backend has the VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol feature, it will receive the VHOST_USER_SET_LOG_BASE message with a file descriptor of the dirty-pages log memory region. This log covers all known guest addresses, and must be manipulated atomically.
For further info please see
https://qemu-project.gitlab.io/qemu/interop/vhost-user.html#migration
This PR adds support for creating an atomic-memory-mapped bitmap, and being able to replace it in runtime. The vhost user protocol does not specify whether the previous bitmap is still active after replying to the VHOST_USER_SET_LOG_BASE message, so we use an RwLock to be sure that the in-flight requests are using the new bitmap after the message reply.
For further info please see
https://qemu-project.gitlab.io/qemu/interop/vhost-user.html#migration
Note to reviewers
This code is part of the effort to support live migration in virtiofsd and is currently being used in a version of virtiofsd that supports migration: https://gitlab.com/virtiofsd-live-migration