Design document and performance evaluation for post-copy live migration
v2 cover Design document and performance evaluation for post-copy live migration
From: Joshua Otto <[email protected]>
Hi,
A little over a year ago, I posted a patch series implementing support for post-copy live migration via xenpaging [1]. Following Andrew and Wei's review of the initial refactoring patches, I promised to follow up with revised patches, a design document and an experimental performance evaluation. It took a lot longer than I thought, but I've finally prepared all of those things now - hopefully better late than never :)
The patches are the v2 of the series from [1], rebased against "3fafdc2 xen/arm:
p2m: Fix incorrect mapping of superpages", the tip of master when I performed the rebase and experiments: late May 2017. They're accessible on GitHub at [2].
Changes from v2:
- addressed the feedback received from the first round
- fixed bugs discovered during performance experiments
- based on results from the performance experiments, added a paging op to populate pages directly into the evicted state
Though I haven't actually tried to do so myself, a quick look at the relevant code indicates that a relatively painless rebase should still be possible.
The body of this mail is the report. It is intended to describe the purpose, design and behaviour of live migration both before and after the patches in sufficient detail to enable a future contributor or academic researcher with only general Xen familiarity to pick them up if they turn out to be useful in the future. I prepared it in plain text for the mailing list, and based its format on Haozhong Zhang's vNVDIMM design document [3].
TL;DR: These (now slightly stale) patches implement post-copy live migration
using xenpaging. They provide a modest downtime reduction when used in hybrid mode with pre-copy, likely because they permit the memory migration to proceed in parallel with guest device model set-up. This benefit probably doesn't outweigh the cost in terms of increased implementation complexity.
Thanks for reading!
- Joshua Otto
[1] https://lists.xenproject.org/archives/html/xen-devel/2017-03/msg03491.html
[2] https://github.com/jtotto/xen/commits/postcopy-v2
[3] https://lists.xenproject.org/archives/html/xen-devel/2016-02/msg00006.html
Note: I've sent this from my personal e-mail account because I'm no longer able to send mail from my old school address, though I'm still able to receive mail sent to it.
Post-Copy Live Migration for Xen - Design and Performance Evaluation
====================================================================
Xen supports live migration of guests between physical hosts. Documentation of this feature can be found at [a] - summarized briefly, it enables system administrators to 'move' a running guest from one physical host running Xen to another.
One of the most difficult sub-problems of live migration is the memory migration. Today, Xen's live memory migration employs an iterative pre-copy algorithm, in which all guest memory is transmitted from the migration sender to receiver _before_ execution is stopped at the sender and resumed at the receiver. This document describes the design, implementation and performance evaluation of an alternative live memory migration algorithm, _post-copy_ live migration, that attempts to address some of the shortcomings of pre-copy migration by deferring the transmission of part or all of the guest's memory until after it is resumed at its destination. The described design adds support for post-copy without altering the existing architecture of the migration feature, taking advantage of the xenpaging mechanism to implement post-copy paging purely in the toolstack. The experimental performance evaluation of the new feature indicates that, for the SQL database workload evaluated, post-copy in combination with some number of pre-copy iterations yields modest downtime-reduction benefits, but that pure post-copy results in unacceptable application-level guest downtime.
Content
=======
1. Background
1.1 Implemented in Xen today: pre-copy memory migration
1.2 Proposed enhancement: post-copy memory migration
2. Design
2.1 Current design
2.1.1 xl migrate <-> xl migrate-receive, Part One
2.1.2 libxl_domain_suspend() <-> libxl_domain_create_restore(), Part One 2.1.3 libxl__stream_write <-> libxl__stream_read, Part One
2.1.4 xc_domain_save() <-> xc_domain_restore()
2.1.5 libxl__stream_write <-> libxl__stream_read, Part Two
2.1.6 libxl_domain_suspend() <-> libxl_domain_create_restore(), Part Two 2.1.7 xl migrate <-> xl migrate-receive, Part Two
2.2 Proposed design changes
2.2.1 xl migrate <-> xl migrate-receive, Part One
2.2.2 libxl_domain_live_migrate() <-> libxl_domain_create_restore(), Part One 2.2.3 libxl__stream_write <-> libxl__stream_read, Part One
2.2.4 xc_domain_save() <-> xc_domain_restore(), Part One
2.2.4.1 Pre-copy policy
2.2.4.2 Post-copy transition
2.2.5 libxl__stream_write <-> libxl__stream_read, Part Two
2.2.6 xc_domain_save() <-> xc_domain_restore(), Part Two: memory post-copy
2.2.6.1 Background: xenpaging
2.2.6.2 Post-copy paging
2.2.6.3 Batch page-out operations
2.2.7 libxl_domain_live_migrate() <-> libxl_domain_create_restore(), Part Two 2.2.8 xl migrate <-> xl migrate-receive, Part Two
3. Performance evaluation
3.1 Prior work and metrics
3.2 Experiment: pgbench
3.2.1 Experiment design
3.2.2 Results
3.2.2.1 Algorithms A vs. E: stop-and-copy vs. post-copy after iterative pre-copy 3.2.2.2 Algorithm C: pure post-copy
3.2.2.3 Algorithm B vs. D: post-copy after a single pre-copy iteration
3.3 Further Experiments
4. Conclusion
5. References
1. Background
1.1 Implemented in Xen today: pre-copy memory migration
Live migration of guest memory in Xen is currently implemented using an iterative pre-copy algorithm with fixed iteration-count and remaining-page thresholds. It can be described at a high level by the following sequence of steps:
1) transmit all of the guest's pages to the migration receiver
2) while more than DIRTY_THRESHOLD pages have been dirtied since they were last transmitted and fewer than ITERATION_THRESHOLD transmission iterations have been performed...
3) transmit all guest pages modified since last transmission, goto 2)
4) pause the guest
5) transmit any remaining dirty pages, along with the guest's virtual hardware configuration and the state of its virtual devices
If the migration process can transmit pages faster than they are dirtied by the guest, the migration loop converges - each successive iteration begins with fewer dirty pages than the last. If it converges sufficiently quickly, the number of dirty pages drops below DIRTY_THRESHOLD pages in fewer than ITERATION_THRESHOLD iterations and the guest experiences minimal downtime. (the current values of DIRTY_THRESHOLD and ITERATION_THRESHOLD are 50 and 5, respectively)
This approach has worked extremely well for the last >10 years, but has some drawbacks:
- The guest's page-dirtying rate is likely non-uniform across its pages. Instead, most guests will dirty a subset of their pages much more frequently than the rest (this subset is often referred to as the Writable Working Set, or WWS). If the WWS is larger than DIRTY_THRESHOLD and its pages are dirtied at a higher rate than the migration transmission rate, the migration will 'get stuck' trying to migrate these pages. In this situation:
- All the time and bandwidth spent attempting pre-copy of these pages is wasted (no further reduction in stop-and-copy downtime can be gained)
- The guest suffers downtime for the full duration required to transmit the WWS at the end of the migration anyway.
- Migrating guests continue to consume CPU and I/O resources at the sending host for the entire duration of the memory migration, which limits the effectiveness of migration for the purpose of load-balancing these resources.
1.2 Proposed enhancement: post-copy memory migration
Post-copy live migration is an alternative memory migration technique that (at least theoretically) addresses these problems. Under post-copy migration, execution of the guest is moved from the sending to receiving host _before_ the memory migration is complete. As the guest executes at the receiver, any attempts to access unmigrated pages are intercepted as page-faults and the guest is paused while the accessed pages are synchronously fetched from the sender. When not servicing faults for specific unmigrated pages, the sender can push the remaining unmigrated pages in the background. The technique can be employed immediately at the start of a migration, or after any amount of pre-copying (including in the middle of a pre-copy iteration).
The post-copy technique exploits the fact that the guest can make some progress at the receiver without access to all of its memory, permitting execution to proceed in parallel with the continuing memory migration and breaking up the single long stop-and-copy downtime into smaller intervals interspersed with periods of execution. Depending on the nature of the application running in the guest, this can be the difference between only degraded performance and observable downtime.
Compared to the existing pre-copy technique, post-copy also has the same total-migration-time and bandwidth consumption advantages as outright
stop-and-copy: each page is migrated exactly once, rather than arbitrarily many times according to the dirtying behaviour of the guest.
2. Design
The live migration feature is implemented almost entirely in the toolstack, by a set of cooperating dom0 processes distributed between both peers whose functionality is split across four layers:
Layer | Sender Process | Receiver Process
--------------+------------------------+------------------------------
xl | `xl migrate` | `xl migrate-receive` libxl | libxl_domain_suspend() | libxl_domain_create_restore() libxl stream | libxl__stream_write | libxl__stream_read
-------- (libxl-save-helper process boundary) -----------------------
libxc | xc_domain_save() | xc_domain_restore()
Section 2.1 describes the flow of control through each of these layers in the existing design for the case of a live migration of an HVM domain. Section 2.2 describes the changes to the existing design required to accommodate the introduction of post-copy memory migration.
2.1 Current design
2.1.1 xl migrate <-> xl migrate-receive, Part One
An administrator (or automation) initiates a live migration with the xl migrate command at the sending host, specifying the domain to be migrated and the receiving host.
xl migrate:
- Gathers the domain's xl.cfg(5)-level configuration.
- Spawns an SSH child process that launches xl migrate-receive at the destination host, thereby establishing a secure, bidirectional stream-oriented communication channel between the remotely cooperating migration processes.
- Waits to receive the migrate_receiver_banner message transmitted by the xl migrate-receive peer, confirming the viability of the link and the readiness of the peer.
- Transmits the domain configuration gathered previously.
- Calls libxl_domain_suspend(). This is the handoff to the libxl API, which handles the migration of the domain's _state_ now that its configuration is taken care of.
Meanwhile, the setup path in the xl migrate-receive peer at the destination:
- Immediately transmits the migrate_receiver_banner.
- Receives the xl.cfg(5) domain configuration in binary format and computes from it a libxl_domain_config structure.
- Calls libxl_domain_create_restore() with the computed configuration and communication streams.
2.1.2 libxl_domain_suspend() <-> libxl_domain_create_restore(), Part One
libxl_domain_send():
- Initializes various mechanisms required to support live migration (e.g. guest suspension and QEMU logdirty support)
- Calls libxl__stream_write_start() to kick off the async stream-writing path.
- Drops into the AO_INPROGRESS async event loop, which drives control flow for the remainder of the migration.
Note: as a first-time reader of libxl when exploring this code path, I found the invocation of the AO_INPROGRESS event loop at [s] to be _extremely_ non-obvious, because the macro isn't function-like - at first I assumed something like '#define AO_INPROGRESS EINPROGRESS', while reality is closer to '#define AO_INPROGRESS do { poll(); dispatch_events(); } while (!done)'
libxl_domain_create_restore(), meanwhile:
- Validates the configuration of the domain for compatibility with the receiving host and the live migration process.
- Creates an 'empty' domain via xc_domain_create(), to be subsequently filled in with the state of the migrating domain.
- Prepares the new domain's XenStore hierarchy.
- Calls libxl__stream_read_start() to kick off the async stream-reading path.
- Drops into the AO_INPROGRESS async event loop.
2.1.3 libxl__stream_write <-> libxl__stream_read, Part One
The stream writer:
- Writes the stream header.
- Writes the LIBXC_CONTEXT record, indicating that control of the stream is to be transferred to libxc for the migration of the guest's virtual architectural state.
- Launches the libxl-save-helper, which exists to permit the synchronous execution of xc_domain_save() while keeping the libxl API asynchronous from the perspective of the library client.
The stream reader:
- Reads the stream header.
- Reads the LIBXC_CONTEXT record, and launches its own libxl-save-helper to run xc_domain_restore().
2.1.4 xc_domain_save() <-> xc_domain_restore()
xc_domain_save():
- Writes the Image and Domain headers.
- Allocates the dirty_bitmap, a bitmap tracking the set of guest pages whose up-to-date contents aren't known at the receiver.
- Enables the 'logdirty' hypervisor and emulator mechanisms.
- Transmits all of the pages of the guest in sequence.
- Guest pages are transmitted in batches of 1024 at a time. Transmitting a batch entails mapping each page in the batch into the process via the xenforeignmemory_map() interface and collecting them into an iovec for consumption by writev(2).
- Iteratively, until either of the conditions for termination are met:
- Refreshes the contents of the dirty_bitmap via XEN_DOMCTL_SHADOW_OP_CLEAN, which atomically records the current state of the dirty bitmap maintained in Xen and clears it (marking all pages as 'clean' again for the next round).
- Re-transmits each of the pages marked in the updated dirty_bitmap.
- Suspends the domain (via IPC to the controlling libxl).
- Obtains the 'final' dirty_bitmap - since the guest is now paused, it can no longer dirty pages, so transmitting the pages marked in this bitamp will ensure that the receiving peer has the up-to-date contents of every page.
- Transmits these pages.
- Collects and transmitting the rest of the HVM state: at present this includes TSC info, the architectural state of each vCPU (encapsulated in a blob of 'HVM context' extracted via domctl), and the HVM_PARAMS (which describe, among other things, a set of 'magic' pages within the guest).
- Transmits the END record.
xc_domain_restore():
- Reads and validates the Image and Domain headers.
- Allocates the populated_pfns bitmap, a bitmap tracking the set of guest pages that have been 'populated' (allocated by the hypervisor for use by the guest).
- Iteratively consumes the stream of PAGE_DATA records transmitted as the sender executes the migration loop.
- Consuming a PAGE_DATA record entails populating each of the pages in the received record that hasn't previously been populated (as recorded in populated_pfns), then mapping all of the pages in the batch and updating their contents with the data in the new record.
- After the suspension of the guest by the sender, receives the final sequence of PAGE_DATA records and the remainder of the state records. This entails installing the received HVM context, TSC info and HVM params into the guest.
- Consumes the END record.
After the sender has transmitted the END record and the receiver has consumed it, control flow passes out of libxc and back into the libxl-save-helper on each side. The result on each side is reported via IPC back to the main libxl process and both helpers terminate. These terminations are observed as asynchronous events in libxl that resume control flow at that level.
2.1.5 libxl__stream_write <-> libxl__stream_read, Part Two
The stream writer next proceeds along an asynchronous chain of record composition and transmission:
- First, emulator data maintained in XenStore is collected and transmitted.
- Next, the state of the emulator itself (the 'emulator context') is collected and transmitted.
- Finally the libxl END record is transmitted. At this point, the libxl stream is complete and the stream completion callback is invoked.
The stream reader executes an asynchronous record receipt loop that consumes each of these records in turn.
- The emulator XenStore data is mirrored into the receiver XenStore.
- The emulator context blob is written to local storage for subsequent consumption during emulator establishment.
- When the END record is received, the completion callback of the stream reader is invoked.
2.1.6 libxl_domain_suspend() <-> libxl_domain_create_restore(), Part Two
Relatively little happens in this phase at the sender side: some teardown is carried out and then the libxl AO is marked as complete, terminating the AO_INPROGRESS event loop of libxl_domain_suspend() and returning control flow back to xl migrate.
In libxl_domain_create_restore(), on the other hand, the work of unpacking the rest of the received guest state and preparing it for resumption ('building it', in the vocabulary of the code) remains. To be completely honest, my understanding of exactly what this entails is a little shaky, but the flow of asynchronous control through this process following completion of the stream follows roughly this path, with the names of each step giving a reasonable hint at the work being performed:
-> domcreate_stream_done() [b]
-> domcreate_rebuild_done() [c]
-> domcreate_launch_dm() [d]
-> domcreate_devmodel_started() [e]
-> domcreate_attach_devices() (re-entered iteratively for each device) [f] -> domcreate_complete() [g]
domcreate_complete() marks the libxl AO as complete, terminating the AO_INPROGRESS loop of libxl_domain_create_restore() and returning control flow to xl migrate-receive.
2.1.7 xl migrate <-> xl migrate-receive, Part Two
At this point, the guest is paused at the sending host and ready to be unpaused at the receiving host. Logic in the xl tools then carries out the following handshake to safely destroy the guest at the sender and actually unpause it at the receiver:
Sender: After the return of libxl_domain_suspend(), the sender waits
synchronously to receive the migrate_receiver_ready message.
Receiver: After libxl_domain_create_restore() returns, the receiver transmits
the migrate_receiver_ready message and synchronously waits to receive the migrate_permission_to_go message.
Sender: After migrate_receiver_ready is received, the sender renames the
domain with the '--migratedaway' suffix, and transmits migrate_permission_to_go.
Receiver: After migrate_permission_to_go is received, the receiver renames
the newly-restored domain to strip its original '--incoming' suffix. It then attempts to unpause it, and reports the success or failure of this operation as the migrate_report.
If all has gone well up to this point, the guest is now live and executing at the receiver.
Sender: If the migrate_report indicates success, the '--migratedaway' domain
is destroyed.
If any of the steps in this sequence prior to the transmission of the migrate_permission_to_go message fail _or_ a positive report of failure from the receiver arrives, the receiver destroys their copy of the domain and the sender recovers by unpausing its (still-valid!) copy of the guest. If, however, the sender transmits migrate_permission_to_go and a positive report of success from the receiver fails to arrive, the migration has fallen into the 'failed badly' scenario where the sender cannot safely recover by resuming its local copy, because the receiver's copy _may_ be executing. This is the most serious possible failure mode of the scheme described here.
2.2 Proposed design changes
The proposed patch series [h] introduces support for a new post-copy phase in the live memory migration. In doing so, it makes no architectural changes to the live migration feature: it is still implemented in the user-space toolstack, and the layering of components within the toolstack is preserved. The most substantial changes are made to the core live memory migration implementation in libxc, with a few supporting changes in the libxl migration stream and even fewer higher up in libxl/xl.
To carry out the transition to the new post-copy phase:
- At the end of the pre-copy phase of the memory migration, the sender now transmits only the _pfns_ of the final set of dirty pages where previously it transmitted their contents.
- The receiving save helper process registers itself as a _pager_ for the domain being restored, and marks each of the pages in the set as 'paged out'. This is the key mechanism by which post-copy's characteristic demand-faulting is implemented.
- The sender next transmits the remaining guest execution context. This includes the libxl context, requiring that control of the stream be _temporarily_ handed up from libxc back to libxl. After all libxl context is transmitted, control of the stream is handed back to libxc.
- The receiver installs this additional context exactly as before (requiring a symmetric temporary handoff to libxl on this side as well).
- At this point, all state except the outstanding post-copy pages has been transmitted, and the guest is ready for resumption. The receiving libxl process (the parent of the receiver migration helper) then initiates the resumption process described in 2.1.6. This completes the transition to the post-copy phase.
Once in the post-copy phase:
- The sender iterates over the set of post-copy pages, transmitting them in batches. Between batches, it checks if any pages have been specifically requested by the receiver, and prioritizes them for transmission.
- The receiver, as the pager of a now-live guest, forwards faulting pages to the sender. When batches arrive from the sender, they are installed via the page-in path.
These loops terminate when all of the post-copy pages have been sent and received, respectively, after which all that remains is teardown (the paused image of the guest at the sender is destroyed, etc.).
The rest of this section presents a more detailed description of the control flow of a live migration with a post-copy phase, focusing on the changes to each corresponding subsection of 2.1.
2.2.1 xl migrate <-> xl migrate-receive, Part One
As before, live migration is initiated with the xl migrate command at the sending host. A new '--postcopy' option is added to the command, which is used to compute the value of a new 'memory_strategy' parameter to libxl_domain_suspend() (or rather, to libxl_domain_live_migrate(), a new libxl API entrypoint like libxl_domain_suspend() but with additional parameters that are only meaningful in the context of live migration). Two values for this parameter are possible:
- STOP_AND_COPY specifies that upon termination of the pre-copy loop the migration should be terminated with a stop-and-copy migration of the final set of dirty pages
- POSTCOPY specifies that upon termination of the pre-copy loop the migration should transition to the post-copy phase
An additional boolean out-parameter, 'postcopy_transitioned', is also passed to libxl_domain_live_migrate(). This bit is set within libxl_domain_send() at the end of the post-copy transition (from the sender's point of view, this is after the libxl POSTCOPY_TRANSITION_END is sent), and is used by the caller to decide whether or not it's safe to attempt to resume the paused guest locally in the event of failure.
A similar boolean out-parameter, 'postcopy_resumed', is now passed to libxl_domain_create_restore(). It is set during the post-copy phase when the domain is (or isn't) successfully unpaused at the end of the domain-building/resumption process, and is used by the caller to determine whether or not the unpause handshake should occur.
2.2.2 libxl_domain_live_migrate() <-> libxl_domain_create_restore(), Part One
This stage is mostly unchanged on both sides. The new memory_strategy parameter of libxl_domain_live_migrate() is stashed in the libxl async request structure for later use by a new 'precopy policy' RPC callback for xc_domain_save(), described in section 2.2.4.
2.2.3 libxl__stream_write <-> libxl__stream_read, Part One
This stage is entirely unchanged on both sides.
2.2.4 xc_domain_save() <-> xc_domain_restore(), Part One
2.2.4.1 Pre-copy policy
The first major change to xc_domain_save() is the generalization of the 'pre-copy policy', i.e. the algorithm used to decide how long the pre-copy phase of the migration should continue before transitioning forward. As described earlier, the historical policy has been to continue until either the ITERATION_THRESHOLD is exceeded or fewer than DIRTY_THRESHOLD pages remain at the end of a round, at which point an unconditional transition to stop-and-copy has occurred.
The generalization of this policy is introduced early in the proposed patch series. It factors the decision-making logic out of the mechanism of the migration loop and into a new save_callbacks function with the following prototype:
struct precopy_stats
{
unsigned int iteration;
unsigned int total_written;
int dirty_count; /* -1 if unknown */
};
/* Policy decision return codes. */
#define XGS_POLICY_ABORT (-1)
#define XGS_POLICY_CONTINUE_PRECOPY 0
#define XGS_POLICY_STOP_AND_COPY 1
#define XGS_POLICY_POSTCOPY 2
int precopy_policy(struct precopy_stats stats, void *data); This new hook is invoked after each _batch_ of pre-copy pages is transmitted, a much finer granularity than the previous policy which was evaluated only at iteration boundaries. This introduces a bit of extra complexity to the problem of computing the 'final' set of dirty pages: where previously it was sufficient to execute one final XEN_DOMCTL_SHADOW_OP_CLEAN after pausing the guest, now the true set of final dirty pages is the union of the results of the final CLEAN and the subset of the last CLEAN result set remaining in the interrupted final pre-copy iteration. To solve this problem, pages are cleared from the dirty_bitmap as they are added to the current migration batch, meaning that the dirty_bitmap at the point of interruption is exactly the subset not yet migrated during the previous iteration. These bits are temporarily transferred to the deferred_pages bitmap while the final CLEAN is executed, and then merged back into dirty_bitmap.
In making this change, my motivation was to permit two new sorts of policies:
1) 'Continue until some budget of network bandwidth/wallclock time is exceeded, then transition to post-copy', which seemed like it would be useful to administrators wishing to take advantage of post-copy to set a hard bound on the amount of time or bandwidth allowed for a migration while still offering the best-effort liveness of post-copy.
2) 'Continue until the live human operator decides to initiate post-copy', which was explicitly to match the equivalent QEMU post-copy feature [i].
In retrospect, I should probably have focused more on making the post-copy mechanism work under the existing policy and left the broader issue for later discussion. It's not really required, and the patches in their current state provide implement in this hook exactly the previous policy, simply returning POSTCOPY rather than STOP_AND_COPY at the old termination point based on the libxl_domain_live_migrate() memory_strategy (which itself simply reflects whether or not the user specified '--postcopy' to xl migrate).
2.2.4.2 Post-copy transition
For the sender, the transition from the pre-copy to the post-copy phase begins by:
1) Suspending the guest and collecting the final dirty bitmap, just as for stop-and-copy.
2) Transmitting to the receiver a new POSTCOPY_BEGIN record, to prime them for subsequent records whose handling differs between stop-and-copy and post-copy.
3) Transmitting the set of 'end-of-checkpoint' records (e.g. TSC_INFO, HVM_CONTEXT and HVM_PARAMS in the case of HVM domains)
4) Transmitting a POSTCOPY_PFNS_BEGIN record, followed by a sequence of POSTCOPY_PFNS records enumerating the set of pfns to post-copy migrated. Post-copy PFNs are transmitted in POSTCOPY_PFNS records, which are like PAGE_DATA records but without the trailing actual page contents. Each batch can hold up to 512k 64-bit pfns while staying within the stream protocol's 4mb record size cap.
At this point, the only state needed to resume the guest not yet available at the receiver is the higher-level libxl context. Control of the stream must therefore be handed back to the libxl stream writer. This is done by:
5) Writing a new POSTCOPY_TRANSITION record, to co-ordinate a symmetric hand-off at the receiver.
6) Executing the synchronous postcopy_transition RPC, to which the libxl parent will reply when the libxl stream is finished.
At the receiver (numbered to match corresponding sender steps):
2) When the POSTCOPY_BEGIN record arrives, only the restore context 'postcopy' bit is set.
3) The end-of-checkpoint records arrive next and are handled as in stop-and-copy, with one exception: when the HVM_PARAMS record arrives, the magic page parameters (HVM_PARAM_*_PFN) are explicitly populated, as they may not yet have been. This is to ensure that the magic pages that must be cleared can be, and in the case of the PAGING_RING so that the immediately following pager setup succeeds.
4) When the POSTCOPY_PFNS_BEGIN record arrives, the receiving helper enables paging on the migrating guest by establishing itself as its pager. As the subsequent POSTCOPY_PFNS records arrive, each of the pages in the post-copy set are marked as 'paged out' (the paging component of the change is described in greater detail in section 2.2.6).
6) When the POSTCOPY_TRANSITION record arrives, the synchronous receive-side postcopy_transition RPC is executed, transferring control of the stream back to the receiving libxl parent.
2.2.5 libxl__stream_write <-> libxl__stream_read, Part Two
The postcopy_transition() RPC from the libxc save helper is plumbed to libxl__stream_write_start_postcopy_transition(), which records in the stream writer context that it's executing a new SWS_PHASE_POSTCOPY_TRANSITION callback chain and then kicks off exactly the same chain as before, starting with the emulator XenStore record. At the end of the chain, a POSTCOPY_TRANSITION_END record is written, indicating to the receiver that control of the migration stream is to be transferred back to libxc in the helpers for the duration of the post-copy memory migration phase. This transfer is then carried out by signalling the completion of the postcopy_transition() RPC to the libxc save helper.
The postcopy_transition RPC from the libxc _receiver_ helper is plumbed to libxl__stream_read_start_postcopy_transition(), which is symmetric in spirit and implementation to its companion at the sender.
At the end of the libxl post-copy transition, two concurrent stages of the migration begin: the libxc post-copy memory migration, and the receiver libxl domain resumption procedure.
2.2.6 xc_domain_save() <-> xc_domain_restore(), Part Two: memory post-copy
This stage implements the key functionality of the post-copy memory migration:
it permits the building, resumption and execution of the migrating guest at the receiver before all of its memory is migrated. To achieve this, the receiver must intercept _all_ accesses to the unmigrated pages of the guest as they occur and fetch their contents from the sender before allowing them to proceed. Fortunately, the fundamental supporting mechanism - guest paging - already exists! It's documented fairly lightly [k] and the description given there doesn't do much to inspire confidence in its stability, but it is completely sufficient in its current state for the purpose of intercepting accesses to unmigrated pages during the post-copy phase.
2.2.6.1 Background: xenpaging
Paging for a given guest is managed by a 'pager', a process in a privileged foreign domain that a) identifies and evicts pages to be paged out and b) services faults for evicted pages. To facilitate this, the hypervisor provides
a) a family of paging operations under the memory_op hypercall and b) an event ring, into which it _produces_ events when paged pages are accessed (pausing the accessing vCPU at the same time) and from which it _consumes_ pager responses indicating that accessed pages were loaded (and correspondingly unpausing the accessing vCPU).
Evicting a page requires the pager to perform two operations:
1) When a page is first selected for eviction by the pager's policy it is marked with the nominate operation, which sets up the page to trap upon writes to detect modifications during page-out. The pager then maps and write the page's contents to its backing store.
2) After the page's contents are saved, the pager tries to complete the process with the evict operation. If the page was not modified since its nomination the eviction succeeds and its memory can be freed. If it was, however, the eviction has failed.
Re-installing a paged page is performed in a single prep operation, which atomically allocates and copies in the content of the paged page.
The protocol for the paging event ring consists of a request and response:
1) The hypervisor emits a request into the event ring when it intercepts an access to a paged page. There are two classes of accesses that can occur, though they are indistinguishable from the point of view of the ring protocol:
a) accesses from within the guest, which result in the accessing vCPU being paused
b) mappings of paged pages by foreign domains, which are made to fail (with the expectation that the mapper retry after some delay)
In either case, the request made to the ring communicates the faulting pfn. In the former case, it also communicates the faulting vCPU.
2) The pager consumes these requests, obtains the contents of the faulting pfns by its own unique means, and after performing the prep operation to install them, emits back into the ring a response containing exactly the information in the original request.
2.2.6.2 Post-copy paging
Post-copy paging setup occurs when the POSTCOPY_PFNS_BEGIN record arrives. The libxc restore helper begins by registering itself as the new guest's pager, enabling paging and setting up the event ring.
As subsequent POSTCOPY_PFNS records arrive, the pfns they contain must all be marked as paged out at the hypervisor level. Doing so naively can be prohibitively costly when the number of post-copy pages is large; this problem, and its solution, are described in 2.2.6.3.
After control of the stream is returned at the end of the post-copy transition, the steady-state of the post-copy phase begins. Crucially, this occurs even while the libxl 'building' of the guest proceeds. This is important because domain building can and does access guest memory - in particular, QEMU maps guest memory.
For the duration of the post-copy phase, the receiver maintains a simple state-machine for each post-copy pfn, described in this source-code comment at the declaration of its storage:
/*
* Prior to the receipt of the first POSTCOPY_PFNS record, all
* pfns are 'invalid', meaning that we don't (yet) believe that
* they need to be migrated as part of the postcopy phase. *
* Pfns received in POSTCOPY_PFNS records become 'outstanding',
* meaning that they must be migrated but haven't yet been
* requested, received or dropped.
*
* A pfn transitions from outstanding to requested when we
* receive a request for it on the paging ring and request it
* from the sender, before having received it. There is at
* least one valid entry in pending_requests for each requested
* pfn.
*
* A pfn transitions from either outstanding or requested to
* ready when its contents are received. Responses to all
* previous pager requests for this pfn are pushed at this time,
* and subsequent pager requests for this pfn can be responded
* to immediately.
*
* A pfn transitions from outstanding to dropped if we're
* notified on the ring of the drop. We track this explicitly
* so that we don't panic upon subsequently receiving the
* contents of this page from the sender.
*
* In summary, the per-pfn postcopy state machine is:
*
* invalid -> outstanding -> requested -> ready
* | ^
* +------------------------+
* |
* +------ -> dropped
*
* The state of each pfn is tracked using these four bitmaps. */
unsigned long *outstanding_pfns;
unsigned long *requested_pfns;
unsigned long *ready_pfns;
unsigned long *dropped_pfns;
A given pfn's state is defined by the set it's in (set memberships are mutually exclusive).
The receiver's post-copy loop can be expressed in pseudo-code as:
outstanding_pfns = { final dirty pages }
requested_pfns = { }
ready_pfns = { }
while (outstanding_pfns is not empty) {
/*
* Wait for a notification on the paging ring event channel, or for
* data to arrive on the migration stream.
*/
wait_for_events();
/*
* Consume any new faults generated by the guest and forward them to
* the sender so that their transmission is prioritized.
*/
faults = {}
while (!empty(paging_ring)) {
fault = take(paging_ring)
if (fault in ready_pfns) {
/*
* It's possible that the faulting page may have arrived and
* been loaded after the fault occurred but before we got
* around to consuming the event from the ring. In this case,
* reply immediately.
*/
notify(paging_ring)
} else {
faults += fault
}
}
outstanding_pfns -= faults
requested_pfns += faults
send(faults)
/*
* Consume incoming page data records by installing their contents into
* the guest. If a guest vCPU is paused waiting for the arrival of a
* given page, unpause it now that it's safe to continue.
*/
while (record = read_record(migration_stream)) {
paging_load(record.pfn, record.data)
if (record.pfn in requested_pfns) {
notify(paging_ring)
}
requested_pfns -= record.pfn
ready_pfns += record.pfn
}
}The sender's companion post-copy loop is simpler:
remaining_pages = { final dirty pages }
while (remaining_pages) {
transmission_batch = {}
/* Service new faults. */
faults = recv_faults()
if (faults) {
transmission_batch += faults
}
/* Fill out the rest of the batch with background pages. */
remainder = take(remaining_pages, BATCH_SIZE - count(faults))
transmission_batch += remainder
remaining_pages -= remainder
send(transmission_batch)
}One interesting problem is in deciding which not-yet-requested pages should be pushed in the next background batch. Ideally, they should be sent in the order they'll be accessed, to minimize the faults at the receiver. In practice, the general problem of predicting the guest's page access stream is _extremely_ difficult - this is the well-known pre-paging problem, which has been explored by decades of academic and industrial research. The current version of the patch series exploits spatial locality in the physical page access stream by starting at the next unsent pfn after the last faulting pfn and proceeding forward.
The sender terminates the libxc stream with a POSTCOPY_COMPLETE record so that the receiver can flush (i.e. consume) all in-flight POSTCOPY_PAGE_DATA records before control of the stream is handed back to libxl on both sides.
2.2.6.3 Batch page-out operations
When a batch of POSTCOPY_PFNS arrives during the post-copy transition, all of the pfns in the batch must be marked paged-out as quickly as possible to minimize the downtime required. Doing so using the existing paging primitives requires:
1) 'Populating' (i.e. allocating a backing physical page for) any pages in the batch that aren't already, because only populated pages can be 'paged out'. In a migration that transitions to post-copy before the end of the first iteration, any pages not sent during the partial first round will be unpopulated during the post-copy transition. In the special case of an instant post-copy migration, this will be _all_ of the guest's pages.
2) Performing the nominate and evict operations individually on each page in turn, because only nominated pages can be evicted.
There are a few obvious inefficiencies here:
- Populating the pages is unnecessary.
- The nominate operation is entirely unnecessary when the page's contents are already available from the pager's backing store and can't be invalidated by modification by the guest or other foreign domains.
- The evict operation acts on a single page at a time even when many pages are known to need eviction up front.
Together, these inefficiencies make the combined operation of 'evicting' many pfns at a time during the critical post-copy transition downtime phase quite costly. Quantitatively, in my experimental set-up (described in detail in section 3.2.1) I measured the time required to evict a batch of 512k pfns at 8.535s, which is _enormous_ for outright downtime.
To solve this problem, the last patches in the series introduce a new memory paging op designed to address specifically this situation, called populate_evicted. This operation takes a _batch_ of pfns and, for each one:
- de-populates it if populated
- transitions it directly to the paged-out state, skipping the nomination step
With a further patch rewriting the POSTCOPY_PFNS handler to use this new primitive, I measured a 512k-pfn eviction time of 1.590s, a 5.4x improvement.
2.2.7 libxl_domain_live_migrate() <-> libxl_domain_create_restore(), Part Two
The sender side of this stage is unchanged: libxl_domain_live_migrate() returns almost immediately back up to xl migrate.
The receiver side becomes more complicated, however, as it now has to manage the completion of two asynchronous operations:
1) its libxc helper, which terminates when all of the outstanding post-copy pages have arrived and been installed
2) the domain-building/resumption process detailed in section 2.1.6 (the functional sequence is unchanged - the fact that some guest memory remains unmigrated is made completely transparent by the libxc pager)
These operations (referred to in code as the 'stream' and 'resume' operations, respectively) can complete in either order, and either can fail. A pair of state machines encoding the progress of each are therefore introduced to the libxl domain create state context structure, with three possible states each:
INPROGRESS --+--> FAILED (rc)
|
+--> SUCCESS (rc == 0) In a healthy migration, the first operation to make the INPROGRESS -> SUCCESS transition simply records its final state as such and waits for the completion of the second. The second operation to complete then finds the other already complete, and calls the overall completion callback to report success. For example, in the case of a long memory post-copy phase, the resume operation is expected to complete first. When it does, it finds that the stream operation is still running, so it simply transitions to SUCCESS. When the post-copy migration is finished and the libxc helper terminates, the new domcreate_postcopy_stream_done() callback finds the resume successfully completed and reports the completion of the entire operation.
The 'resume' operation is initiated from the domcreate_postcopy_transition_callback(), kicking off the same callback sequence as started by domcreate_stream_done() in the non-post-copy case. All termination points along this callback sequence are hooked by the new domcreate_report_result(), which when given a successful result to report also unpauses the guest to begin true post-copy execution. If the resume fails and the stream isn't yet complete, we latch the error, actively abort the stream and then wait for the failure completion of the stream to complete the overall operation.
The 'stream' operation's completion is signalled by domcreate_postcopy_stream_done(), which is wired up to the libxc helper's SIGCHLD in the way that domcreate_stream_done() was previously. If the stream fails, its error is simply stashed (and no other action taken) on the assumption that the resumption will eventually complete one way or another and find it.
2.2.8 xl migrate <-> xl migrate-receive, Part Two
If everything has gone according to plan up to this point, the migration is effectively complete - the guest is now unpaused and executing at the receiver with all of its memory migrated. The cautious final unpause handshake is therefore no longer necessary, so the sender simply destroys its copy of the domain, the receiver strips the migration suffix from the name of its copy and the entire process is complete! The receiver does still send a completion message to the sender, however, simply to signal to an interactive user at the sender exactly when the operation has completed.
If, however, something has gone awry, the penalty of post-copy's extra vulnerability to failure is paid. At the receiver, any failure reported by libxl_domain_create_restore() results in the prompt destruction of the local
copy of the domain, even if it's already executing as part of the post-copy
phase and some of the guest's state exists only in this copy, because no sane recovery mode exists with other parts of its state locally unavailable. At the sender, the new postcopy_transitioned out-parameter of libxl_domain_live_migrate() is examined:
- if the transition record wasn't transmitted (postcopy_transitioned == false), there's no way that the guest could possibly have begun executing at the sender, so it's safe to recover by unpausing the original copy of the domain
- if it was, however (postcopy_transitioned == true), it's _possible_ (though not certain) that the guest may have executed (or may even still _be_ executing) at the destination, so unpausing it locally isn't safe
In the latter case, the policy is essentially the same as in the existing 'failed_badly' scenario of normal pre-copy migration in which the sender fails to receive the migration success report after transmitting the migrate_permission_to_go message: the local copy of the domain is suffixed with --postcopy-inconsistent, and a diagnostic message is printed explaining the failure.
One major possible improvement to this scheme is especially worth noting: at the sender, the current postcopy_transitioned bit is a very conservative indication of whether it's safe to attempt local recovery. There are many ways in which the attempted resumption of the domain at the receiver could fail without rendering the communication stream between the sender and receiver inoperable (e.g. one of the domain's disks might be unavailable at the receiver), and in these scenarios the receiver could send a message explicitly indicating to the sender that it should attempt recovery.
3. Performance evaluation
3.1 Prior work and metrics
"Post-copy live migration of virtual machines" [u] describes an earlier implementation of post-copy live migration in Xen and evaluates its performance. Although the details of their implementation - written nearly a decade ago and requiring in-guest kernel support - are vastly different than what's proposed here, their metrics and approach to performance evaluation are still useful Section 3 of the paper enumerates the following performance metrics:
Quoted 22 lines
1. Preparation Time: This is the time between initiating migration and transferring the VM’s processor state to the target node, during which the VM continues to execute and dirty its memory. For pre-copy, this time includes the entire iterative memory copying phase, whereas it is negligible for post-copy.
2. Downtime: This is time during which the migrating VM’s execution is stopped. At the minimum this includes the transfer of processor state. For pre-copy, this transfer also includes any remaining dirty pages. For post-copy this includes other minimal execution state, if any, needed by the VM to start at the target.
3. Resume Time: This is the time between resuming the VM’s execution at the target and the end of migration altogether, at which point all dependencies on the source must be eliminated. For pre-copy, one needs only to re-schedule the target VM and destroy the source copy. On the other hand, majority of our postcopy approach operates in this period.
4. Pages Transferred: This is the total count of memory pages transferred, including duplicates, across all of the above time periods. Pre-copy transfers most of its pages during preparation time, whereas post-copy transfers most during resume time.
5. Total Migration Time: This is the sum of all the above times from start to finish. Total time is important because it affects the release of resources on both participating nodes as well as within the VMs on both
Quoted 8 lines
nodes. Until the completion of migration, we cannot free the source VM’s memory.
6. Application Degradation: This is the extent to which migration slows down the applications running in the VM. Pre-copy must track dirtied pages by trapping write accesses to each page, which significantly slows down write-intensive workloads. Similarly, postcopy needs to service network faults generated at the target, which also slows down VM workloads.
The performance of a memory migration algorithm with respect to these metrics will vary significantly with the workload running in the guest. More specifically, it will vary according to the behaviour of the memory access stream - the pace, read/write mix, and locality of accesses (within pages and between pages). See "Downtime Analysis of Virtual Machine Live Migration" [v] for a quantitative investigation of the effect of these workload parameters on pre-copy migration in Xen and other hypervisors.
The relative importance of these metrics obviously varies with deployment context, but in my opinion the most common ordering is likely:
- Downtime
- Application Degradation
- Preparation Time
- Total Migration Time
- Resume Time
- Pages Transferred
Stop-and-copy and pure post-copy schemes, which transmit each guest page exactly once, will obviously outperform pre-copy at Preparation Time, Pages Transferred and Total Migration Time, but because of this practical preference ordering it's post-copy's potential to reduce Downtime by trading it for Application Degradation that makes it the most interesting. Because write-heavy workloads with large writable working sets experience the greatest downtime under pre-copy, I decided to investigate them first.
3.2 Experiment: pgbench
When selecting a particular application workload to represent the class of pre-copy-resistant workloads with large writable working sets, I looked for a few other desirable properties:
1) It should involve some amount of I/O, which could help the guest make progress even during synchronous page faults (as the I/O could proceed in parallel to the servicing of a subsequent fault).
2) It should be possible to sample instantaneous application performance for the Application Degradation metric, and to perform such sampling reasonably frequently over the course of the migration.
3) It should be reasonably representative of an interesting real-world application, to avoid being confounded by differences in behaviour between purely-synthetic workloads and the ones we're actually interested in. For example, the 'dirty page generators' commonly found in the live migration literature aren't very useful for evaluating any mechanism that attempts pre-paging based on the memory access stream because their memory access streams are generally nothing like real applications (often being either perfectly sequential or perfectly random).
With these properties and the 'large writable working set' criterion in mind, I eventually decided upon the pgbench [x] benchmark for PostgreSQL:
Quoted 6 lines
pgbench is a simple program for running benchmark tests on PostgreSQL. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, pgbench tests a scenario that is loosely based on TPC-B, involving five SELECT, UPDATE, and INSERT commands per transaction.
<snip>
Quoted 10 lines
The default built-in transaction script (also invoked with -b tpcb-like) issues seven commands per transaction over randomly chosen aid, tid, bid and balance. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.
1. BEGIN;
2. UPDATEpgbench_accountsSET abalance = abalance + :delta WHERE aid = :aid;
3. SELECT abalance FROMpgbench_accountsWHERE aid = :aid;
4. UPDATEpgbench_tellersSET tbalance = tbalance + :delta WHERE tid = :tid;
5. UPDATEpgbench_branchesSET bbalance = bbalance + :delta WHERE bid = :bid;
6. INSERT INTOpgbench_history(tid, bid, aid, delta, mtime)
Quoted 2 lines
VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);7. END;
I evaluated the performance of five live migration algorithm variants:
A) traditional five-iteration pre-copy (the status-quo today)
B) single-iteration pre-copy followed by stop-and-copy
C) direct post-copy
D) single-iteration pre-copy followed by post-copy (often called 'hybrid migration)
E) five-iteration pre-copy followed by post-copy
3.2.1 Experiment design
The physical test-bed was composed of:
- Two Intel NUC5CPYH [z] mini PCs, each with 8GB of RAM and a 120GB SSD (this was the cheapest Intel hardware with EPT support I could easily obtain two identical units of)
- a Cisco Meraki MS220-8P [l] gigabit ethernet switch
- my personal laptop computer
One NUC PC was chosen to be the sender (S), and the other the receiver (R). The test-bed configuration was:
S - Switch - R
|
Laptop I.e. each host had a gigabit link to all the others. See [m] and [n] for the full output of xl info on S and R; the subsets that seem relevant to me are:
S:
release : 3.16.0-4-amd64
version : #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19)
machine : x86_64
nr_cpus : 2
max_cpu_id : 1
nr_nodes : 1
cores_per_socket : 2
threads_per_core : 1
cpu_mhz : 1599
virt_caps : hvm
total_memory : 8112
xen_version : 4.9-rc
xen_scheduler : credit
xen_pagesize : 4096
xen_changeset : Fri May 12 23:17:29 2017 -0400 git:c6ed26e
xen_commandline : placeholder altp2m=1
cc_compiler : gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
cc_compile_by : jtotto
cc_compile_date : Sat May 27 18:29:17 EDT 2017
R:
release : 3.16.0-4-amd64
version : #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07)
machine : x86_64
nr_cpus : 2
max_cpu_id : 1
nr_nodes : 1
cores_per_socket : 2
threads_per_core : 1
cpu_mhz : 1599
virt_caps : hvm
total_memory : 8112
xen_version : 4.9-rc
xen_scheduler : credit
xen_pagesize : 4096
xen_changeset : Fri May 12 23:17:29 2017 -0400 git:c6ed26e
xen_commandline : placeholder no-real-mode edd=off
cc_compiler : gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
cc_compile_by : jtotto
cc_compile_date : Sat May 27 18:29:17 EDT 2017
Particularly noteworthy as a potential experimental confound is the relatively old dom0 kernel - I couldn't get anything newer to boot on the NUC hardware, unfortunately. I'm aware that the privcmd driver has changed since then, and experimented with back-porting a more recent version of the kernel module to the base kernel I was experimenting with when evaluating the performance of the batch page-out operation, but it didn't appear to make any difference.
To evaluate each algorith variant, I migrated a guest running a PostgreSQL from S to R while running the pgbench client against it from my laptop. My laptop was also configured as an NFS server and hosted the guest's storage.
The xl.cfg(5) configuration of the test domain was:
builder='hvm'
vcpus=4
memory=2048
shadow_memory=512
name='debvm'
disk=['file:/mnt/mig/debvm-1.img,xvda,w']
boot="c"
vif=['bridge=xenbr0']
sdl=0
stdvga=1
serial='pty'
usbdevice='tablet'
on_poweroff='destroy'
on_reboot='restart'
on_crash='restart'
vnc=1
vnclisten=""
vncpasswd=""
vfb=['type=vnc']
altp2m="external"The exact experiment shell script can be found inline at [o]. The procedure, executed from my laptop, was basically:
repeat 5 times:
for each algorithm variant:
xl create the test domain at S and wait for it to boot re-initialize the test database
launch the pgbench client
wait for 20 seconds to let the benchmark warm up initiate migration of the test domain to R shut down the test domain from within
To measure Preparation Time, Downtime, Resume Time and Total Migration Time, I added some simple timestamp printf()s at key points in the migration sequence:
Preparation Time (recorded at the sender)
Start: Upon entry to save()
End: In suspend_domain() immediately _before_ the libxl suspension hook
Downtime (recorded at the receiver)
For pre-copy migrations (variants A/B):
Start: Since the end of the downtime period can only be recorded at the
receiver, a way to record the beginning of the period was needed. A new dummy record type, PERF_STOP_AND_COPY, was added for this purpose, which is emitted by the sender immediately after the suspension of the domain. The receiver records the time at which this record is received as the beginning of the period.
End: In xl migrate-receive immediately after libxl_domain_unpause()
For post-copy and hybrid migrations (variants C/D/E):
Start: Upon receipt of the existing POSTCOPY_BEGIN record
End: In domcreate_report_result() immediately after
libxl_domain_unpause()
Resume Time
Start: Exactly where Downtime ends, after libxl_domain_unpause()
End: In postcopy_restore() after all pages have been loaded
All timestamps were recorded via clock_gettime(CLOCK_MONOTONIC). The additional patches implementing this tracing can be found at [p].
To measure instantaneous Application Degradation, I ran pgbench in its --log --aggregate-interval mode with an interval of 1 second, thus each second sampling:
- the total number of transactions committed in that second
- the sum of the latencies of these transactions (with which the mean latency can be computed)
- the minimum and maximum latencies of these transactions
Of these, I think that 'transactions/second' is the easiest to interpret, and is what I'll use throughout my analysis.
3.2.2 Results
A plot of the raw phase duration measurements for each run:
Figure 1:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure1.pdf
Given that the results from run to run for each algorithm variant were relatively stable, they can more easily be considered in aggregate via their arithmetic means:
Figure 2:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure2.pdf
For fun, I re-rendered the above plot using gnuplot's 'dumb' terminal driver:
Migration algorithm variant vs. average phase and total durations
90 +-----------+-----------+-----------+----------+-----------+-----------+
| Preparing * |
| Down # |
| Resuming $ |
| ######## |
| ******** |
80 + * * ######## +
| * * ******** |
| * * $$$$$$$$ * * |
| * * ######## $ $ * * |
| * * # # $ $ * * |
| * * # # $ $ * * |
70 + * * # # $$$$$$$$ $ $ * * +
| * * # # $ $ $ $ * * |
| * * # # $ $ ######## * * |
| * * # # $ $ # # * * |
| * * ******** $ $ ******** * * |
| * * * * $ $ * * * * |
60 + * * * * $ $ * * * * +
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
50 + * * * * $ $ * * * * +
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
40 + * * * * $ $ * * * * +
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
30 + * * * * $ $ * * * * +
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
20 + * * * * $ $ * * * * +
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
10 + * * * * $ $ * * * * +
| * * * * $ $ * * * * |
| * * * * $ $ * * * * |
| * * * * ######## * * * * |
| * * * * # # * * * * |
| * * * * # # * * * * | 0 +-------********----********----********----********----********-------+
A B C D E
Algorithm variant
--
N.B. Before getting into comparisons between the algorithm variants, these results reveal an interesting property of the test-setup common to all of them:
the network is _not_ the bottleneck in the migration page transfer. iperf between S and R measured the bandwidth as roughly the gigabit limit advertised by the switch and NICs, but the effective 'bandwidth' actually observed during the pre-copy iterations can be computed as (524357 pages / 63.47s) ~= 8261 pages/s, or ~271Mbps. I didn't collect timings of the sender batch mapping or receive batch installation routines, but I suspect it must be one of these two that's the limiting factor in this set-up. Interpret all of these timing measurements accordingly.
--
3.2.2.1 Algorithms A vs. E: stop-and-copy vs. post-copy after iterative pre-copy
I'm going to focus first on the two multi-iteration pre-copy variants, A and E (the current five-iteration pre-copy algorithm and five-iteration pre-copy + post-copy, respectively). We can see that they:
a) Require the longest preparation time, as expected.
b) Actually still achieve the best downtime, despite my expectation that the workload would be write-heavy enough to cause problems. A's downtime is only slightly worse than D's, and is almost twice as good a C's! More on this shortly.
Most interestingly, we can see that E required 30% less downtime than A on average, and always completed its post-copy phase _before_ the guest unpaused (recall that the post-copy phase proceeds in parallel with libxl domain creation and can complete before the guest is ready to unpause). Why?
Focusing first on Algorithm A, we can plot the number of pages transmitted during each pre-copy iteration:
Figure 3:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure3.pdf
We can see that the migration made substantial progress toward convergence, with strong successive decreases between iterations and an average final dirty set of ~7.5k pages (30.1 MiB). The downtime period during which these pages are transferred can be divided into two interesting sub-phases: the phase during which the memory migration and libxc stream are completed (ending with the termination of the libxc helper), and the phase during which the higher level libxl domain establishment occurs (ending with the unpausing of the domain). Plotting the measurements of these phases:
Figure 4:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure4.pdf
This shows that around 2/3 of the total downtime is incurred _after_ the memory migration is complete.
We can make similar plots for Algorithm E. Here are the number of pages transmitted during each iteration:
Figure 5:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure5.pdf
We can see that the E-runs transmitted slightly fewer pages on average during the pre-copy iterations than the A-runs. This is presumably experimental noise - there's no reason to expect them to be different. Significantly, however, the E-runs actually needed to post-copy slightly _more_ pages on average than the A-runs needed to stop-and-copy. This means the 30% downtime reduction isn't just experimental noise in favour of E, but evidence of an algorithmic advantage.
I think the explanation for this advantage is clear: because the post-copy phase can proceed in parallel with the libxl domain set-up procedure, the downtime duration is reduced to the _minimum_ of the durations of these processes, rather than their sum.
This effect can be seen clearly in the corresponding plot for the libxc/libxl sub-phase breakdown:
Figure 6:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure6.pdf
As further evidence in support of this explanation, on average only 9 faults were incurred during each brief post-copy phase, indicating that the pages required by QEMU/etc. to proceed with domain creation most weren't in the working set.
Another important question is: what impact do the two approaches have on the Application Degradation metric? This plot shows the number of benchmark transactions committed each second over the course of each of the Algorithm A migrations:
Figure 7:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure7.pdf
The dotted line at the 20-second mark indicates roughly where the migration was initiated. We can see that:
- Throughout each phase of the migration, there are occasional severe single-second degradations in tps. I'm not sure what caused these, but they appear to be distributed roughly evenly and occur during every phase, so I think they can safely be ignored for the rest of the discussion.
- During the 20-second warmup period at host S, the benchmark measures a relatively consistent ~325tps.
- Once the migration starts, benchmark performance quickly degrades to roughly 200tps. This clearly indicates an interaction of some kind between the application and the migration process, though which resource they're contending for isn't clear. CPU or network seem like the most likely candidates.
- At roughly the 80-second mark, performance 'degrades' to 0tps as the domain is suspended for the stop-and-copy phase of the migration. This is where things get interesting: although the internal measurements from the previous set of plots indicate that the guest is only truly paused for around 2.5s, from a network observer's point of view the actual application is completely unavailable for around 9s. Not great.
- When the application recovers and begins to make progress, it rebounds to only 275tps rather than 325, indicating some kind of asymmetry between S and R that I can't entirely account for.
How do these measurements look for Algorithm E? Here's the plot:
Figure 8:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure8.pdf
The behaviour appears to be much the same, with a slight improvement in average application-visible downtime because of particularly good results in rounds 2 and 3 with 4s and 5s application downtime measurements, respectively.
3.2.2.2 Algorithm C: pure post-copy
Turning our attention next to pure post-copy, we can make a few interesting observations directly from the Figure 2 phase-timing measurements:
- At 4.9s, C's average Downtime is almost twice that of A! For an algorithm intended to trade outright Downtime for Application Degradation, that's not great.
- At 69.2s, C's Total Migration Time is the lowest of any of the algorithms and ~17% lower than A's.
- C's post-copy phase takes roughly as long as a single pre-copy iteration.
What's ballooning C's downtime? Figure 9 breaks down the sub-phases:
Figure 9:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure9.pdf
There are three major contributors to the Downtime here:
1) It takes ~0.7s for the sender to gather and transmit the set of all post-copy pfns. This makes some sense, as the sender needs to check the _type_ of every pfn in the guest's addressable range to see which ones are unpopulated and which must actually be migrated.
2) It takes ~1.7s to populate-and-evict all of these pages, even with the batching hypercall introduced at the end of the patch series.
3) It takes ~2.4s to complete all of the libxl-level domain set-up after the libxc stream helper is ready to enter the post-copy phase. I think this is really interesting - recall that this step took only ~1.8s for algorithm A. The explanation for this is that the device model (i.e. QEMU) needs to map guest pages immediately during its set-up, and these mappings immediately cause post-copy faults! Algorithm E didn't encounter this because these pages apparently aren't in the working set and so were covered by earlier pre-copy iterations.
What application degradation do we observe during the post-copy phase:
Figure 10:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure10.pdf
Ouch! The actual application-observed downtime is frankly horrific. Round 3 has what appears to be the closest thing to degraded execution at around the 40 second mark, but only briefly. In general, the application suffers around _50_ seconds of observable downtime before recovering to a state of reasonable (but still degraded) performance. This recovery occurs at the ~75 second mark, where performance recovers to ~175tps. The migration finishes and the application recovers to ~275tps at roughly 90 seconds.
To get a clearer picture of why the migration behaves this way, we can plot the faulting behaviour of the resuming guest during the post-copy phase.
Figure 11:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure11.pdf
Figure 12:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure12.pdf
Figure 13:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure13.pdf
Looking first at the fault counts, we can see that the first ~5-10 seconds are relatively quiet. Then, there's a sudden burst to ~100-200 faults/s for a few seconds, followed by a decline to a stable rate of ~50 faults/s until the 50 second mark where they essentially stop. Latencies are high during the initial period, averaging 50-100ms per fault, and decline to 10-20ms per fault during the later steady-state.
I'm not really sure how to account for the burst around the 10 second mark, or the comparatively lower steady-state rate. Because it occurs so long after the first observed fault I don't think it can be bulk device model mappings - the guest is already unpaused at this point. But, if the vCPUs were capable of generating faults this rapidly (i.e. if the post-copy stack was capable of servicing faults quickly enough to _let_ them be generated this quickly), why the subsequent decline to a lower rate for the rest of the phase?
One possible explanation is that the guest actually isn't generating faults at its maximum possible rate at steady-state. Instead, it could be alternating between faulting and making non-trivial progress. If the post-copy background push scheme consistently selected the wrong background pages to push, the time required to commit the first application transaction of the post-copy phase would then be the _sum_ of the time spent executing this non-trivial work and the time required to synchronously fault each of the non-predicted pages in sequence.
Since the guest transitions relatively suddenly from 0tps to 175tps (65% of the full 275tps after recovery), I infer that this set of poorly-predicted necessary pages is common between transactions. As a result, once it has been faulted over from the first transaction or two, all subsequent transactions can proceed quickly.
This discussion raises several questions:
1) Does it make sense that the background pre-paging scheme made poor predictions in the context of the application's actual memory access stream?
2) Would alternative pre-paging schemes have made better predictions?
3) How much would those better predictions improve application performance?
To answer 1), I conducted a further experiment: I prepared a more invasive additional tracing patch that disabled the background push logic for the first 90 seconds of the post-copy phase and logged every individual faulting pfn to visualize the guest memory access stream over time. I obtained these traces:
Figure 14 (i-v):
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure14-1.pdf
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure14-2.pdf
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure14-3.pdf
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure14-4.pdf
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure14-5.pdf
These traces permit a number of observations:
a) Over the first ~5 seconds we can very clearly see a large number of physically-clustered high PFNs faulting in rapid succession. I believe this is the device model establishment.
b) For the next ~10 seconds, we can see lots of faults in three physical PFN
regions: very low memory, 150000-250000, and 475000-525000, with the latter seeing the most faults.
c) At the ~15 second mark, the pattern then shifts: the 475000-525000 continues to fill in, and a long, descending physical page scan begins, either starting from 500000 or from 175000 and 'wrapping around' at the bottom.
This reveals that there _is_ reasonable physical locality in the access stream available for exploitation. In particular, I speculate that the long descending scan corresponds to a database table scan. However, the scheme implemented in the current version of the patch, simply scanning _forward_ from the last physical pfn to fault, is perhaps not clever enough to fully take advantage of it.
In "Post-Copy Live Migration of Virtual Machines", a number of more clever 'bubbling' pre-paging strategies are discussed that I imagine would have done better. The approach described in "A Novel Hybrid-Copy Algorithm for Live Migration of Virtual Machines" [q] also seems like it might have worked well (though it's not as easy to eyeball). In principle, I think this answers question 2) in the affirmative.
However, although, I didn't have time to implement and experimentally evaluate these alternatives, I think it's fairly safe to say that even with perfect prediction the application-level downtime entailed by this approach would still be worse than for Algorithm A, since such a large set of pages appears to be necesssary to permit the application to make even increment of externally-visible progress.
-- Aside:
Having collected all of the same timing data in this further experiment as I did in the first set, I decided to take a look at the fault stats and application performance plots and was able to make some interesting observations:
Figure 15:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure15.pdf
Figure 16:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure16.pdf
Figure 17:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure17.pdf
It may not be obvious unless you line it up next to the corresponding plots from the first experiment, but:
- all of the per-fault latencies are reduced by an order of magnitude, with the mean falling from ~10ms to ~3ms
- the fault service rate is increased massively, by a factor from 4 to as much
as 24
This makes some sense: in disabling all background pushing, I also disabled the logic that 'filled out' the remainder of a batch servicing a fault with other pages in its locality, so I'd expect each individual fault request to be serviced more quickly and consequently that the guest would be able to generate subsequent ones faster. However, neither of these translate into better application performance:
Figure 18:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure18.pdf
So, the batching and weak prediction logic implemented in the patch in its current state are clearly worth _something_.
--
3.2.2.3 Algorithm B vs. D: post-copy after a single pre-copy iteration
The final post-copy variant, Algorithm D, appears to have performed reasonably according to its phase timings in Figure 2:
- At 2.45s, its raw Downtime is slightly less than that of A
- At 63.47s, its Preparation Time is ~20% less than A's
- With 10.26s of Resume Time, its Total Migration Time is a slight ~6% less than A's
Algorithm B, its pre-copy-only counterpart, fared less well, with the same Preparation Time as D but with the worst outright Downtime of any variant at 11s.
Judging by Figures 3 and 5, they both ended their single pre-copy iteration with ~90k pages (~351 MiB) dirty.
The real question, of course, is how their Application Degradation results compare to those of A and E:
Figure 19:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure19.pdf
Figure 20:
https://github.com/jtotto/xen-postcopy-figures/blob/master/figure20.pdf
These results show that Algorithm D's Application Degradation is only moderately worse than A's, while B's is almost twice as bad. Algorithm D therefore seems like a potentially useful alternative to A in situations where it would be useful to trade a moderate increase in Application Degradation for a more significant decrease in Preparation Time.
3.3 Further Experiments
I only had time to conduct the experiment described in the previous section, but there are a number of further experiments that I think would be worth conducting if I had time.
Collecting the same data as in the previous experiment against workloads other than pgbench would be my first priority. Although I tried to choose the workload to be as write-heavy as possible while still being realistic, the results clearly demonstrated it was fairly amenable to pre-copy anyway. If a non-synthetic workload with an even heavier write-mix were evaluated, post-copy might enjoy a more clear advantage.
Identifying a workload with a more granular increment of progress might also demonstrate the ability of post-copy to trade outright Downtime for Application Degradation. As the experiment showed, in the case of pgbench even a single transaction required a large subset of all guest pages to complete.
Moving beyond evaluating the patch in its current state, there are many possible post-copy pre-paging schemes in the literature that it could be augmented to implement, and it would be interesting evaluate each of them in the same way.
For all of the above experiments, as well as the pgbench one, it would also _very_ interesting to conduct them on more production-realistic hardware, to see how shifting the bottleneck to the network as opposed to the CPU of the migrating machines would affect the results.
4. Conclusion
In this document, I've described the design and implementation of a proposed change to introduce post-copy memory migration support for Xen. I then presented and interpreted the results of performance measurements I collected during experiments testing the change.
In my opinion, the data so far suggest that:
1) Pure post-copy is probably only useful in situations where you would be okay with performing an outright stop-and-copy, but would like to try to do a little better if possible.
2) Hybrid post-copy does seem to perform marginally better than pre-copy alone, but this comes at the cost of both additional code complexity and worse reliability characteristics. The costs of the latter seem to me like they probably outweigh the former benefit...
I think it would be very interesting to further investigate how much downtime is spent on device model establishment in production set-ups. If it turns out to be as significant as it was in my experiments, a very limited form of post-copy that only permits the memory migration to proceed in parallel with the device model/etc. setup without actually unpausing the guest until it completes could be worth investigating, as it could reduce downtime without adversely affecting reliability.
5. References
[a] migration.pandoc
https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=docs/features/migration.pandoc
[b] domcreate_stream_done()
https://github.com/xen-project/xen/blob/0a0dcdcd20e9711cbfb08db5b21af5299ee1eb8b/tools/libxl/libxl_create.c#L1127-L1204
[c] domcreate_rebuild_done()
https://github.com/xen-project/xen/blob/0a0dcdcd20e9711cbfb08db5b21af5299ee1eb8b/tools/libxl/libxl_create.c#L1206-L1234
[d] domcreate_launch_dm()
https://github.com/xen-project/xen/blob/0a0dcdcd20e9711cbfb08db5b21af5299ee1eb8b/tools/libxl/libxl_create.c#L1236-L1405
[e] domcreate_devmodel_started()
https://github.com/xen-project/xen/blob/0a0dcdcd20e9711cbfb08db5b21af5299ee1eb8b/tools/libxl/libxl_create.c#L1489-L1519
[f] domcreate_attach_devices()
https://github.com/xen-project/xen/blob/0a0dcdcd20e9711cbfb08db5b21af5299ee1eb8b/tools/libxl/libxl_create.c#L1446-L1487
[g] domcreate_complete()
https://github.com/xen-project/xen/blob/0a0dcdcd20e9711cbfb08db5b21af5299ee1eb8b/tools/libxl/libxl_create.c#L1521-L1569
[h] Post-copy patches v2
https://github.com/jtotto/xen/commits/postcopy-v2
[i] QEMU Post-Copy Live Migration
https://wiki.qemu.org/Features/PostCopyLiveMigration
[k] xenpaging
https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=docs/misc/xenpaging.txt
[s] AO_INPROGRESS
https://github.com/xen-project/xen/blob/0a0dcdcd20e9711cbfb08db5b21af5299ee1eb8b/tools/libxl/libxl_domain.c#L520
[t] Live Migration of Virtual Machines
http://www.cl.cam.ac.uk/research/srg/netos/papers/2005-migration-nsdi-pre.pdf
[u] Post-Copy Live Migration of Virtual Machines
https://kartikgopalan.github.io/publications/hines09postcopy_osr.pdf
[v] Downtime Analysis of Virtual Machine Live Migration
https://citemaster.net/get/e61b2d78-b400-11e3-91be-00163e009cc7/salfner11downtime.pdf
[x] pgbench
https://www.postgresql.org/docs/10/static/pgbench.html
[z] Intel NUC Kit NUC5CPYH
https://ark.intel.com/products/85254/Intel-NUC-Kit-NUC5CPYH
[l] Cisco Meraki MS220-8P
https://meraki.cisco.com/products/switches/ms220-8
[q] A Novel Hybrid-Copy Algorithm for Live Migration of Virtual Machine
http://www.mdpi.com/1999-5903/9/3/37
[m]
$ sudo xl info
[sudo] password for fydp:
host : fydp
release : 3.16.0-4-amd64
version : #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19)
machine : x86_64
nr_cpus : 2
max_cpu_id : 1
nr_nodes : 1
cores_per_socket : 2
threads_per_core : 1
cpu_mhz : 1599
hw_caps : bfebfbff:43d8e3bf:28100800:00000101:00000000:00002282:00000000:00000100
virt_caps : hvm
total_memory : 8112
free_memory : 2066
sharing_freed_memory : 0
sharing_used_memory : 0
outstanding_claims : 0
free_cpus : 0
xen_major : 4
xen_minor : 9
xen_extra : -rc
xen_version : 4.9-rc
xen_caps : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64
xen_scheduler : credit
xen_pagesize : 4096
platform_params : virt_start=0xffff800000000000
xen_changeset : Fri May 12 23:17:29 2017 -0400 git:c6ed26e
xen_commandline : placeholder altp2m=1
cc_compiler : gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
cc_compile_by : jtotto
cc_compile_domain :
cc_compile_date : Sat May 27 18:29:17 EDT 2017
build_id : fc017c8cf375bbe7464c5be8fff2d3fd2e08cbaa
xend_config_format : 4[n]
$ sudo xl info
[sudo] password for fydp:
host : fydp
release : 3.16.0-4-amd64
version : #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07)
machine : x86_64
nr_cpus : 2
max_cpu_id : 1
nr_nodes : 1
cores_per_socket : 2
threads_per_core : 1
cpu_mhz : 1599
hw_caps : bfebfbff:43d8e3bf:28100800:00000101:00000000:00002282:00000000:00000100
virt_caps : hvm
total_memory : 8112
free_memory : 128
sharing_freed_memory : 0
sharing_used_memory : 0
outstanding_claims : 0
free_cpus : 0
xen_major : 4
xen_minor : 9
xen_extra : -rc
xen_version : 4.9-rc
xen_caps : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64
xen_scheduler : credit
xen_pagesize : 4096
platform_params : virt_start=0xffff800000000000
xen_changeset : Fri May 12 23:17:29 2017 -0400 git:c6ed26e
xen_commandline : placeholder no-real-mode edd=off
cc_compiler : gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
cc_compile_by : jtotto
cc_compile_domain :
cc_compile_date : Sat May 27 18:29:17 EDT 2017
build_id : fc017c8cf375bbe7464c5be8fff2d3fd2e08cbaa
xend_config_format : 4 [o] experiment.sh
# Repeat each experiment 5 times.
for i in {1..5};
do
echo "Experiment iteration $i"
for experiment in a b c d e
do
echo "Conducting experiment $experiment"
# First, spin up the test VM to be migrated.
while true
do
ssh -p 1337 -i ~/.ssh/waterloo [email protected] \
'xl create /home/fydp/vms/multideb.cfg' && break
sleep 5
done
# Wait for the test VM to become accessible.
echo 'Booting test VM...'
while true
do
ssh -i ~/.ssh/waterloo [email protected] echo && break
sleep 1
done
# Initialize the test database.
pgbench -h 192.168.2.67 -U postgres -i bench -s 70
# Begin running the test in the background.
pgbench -h 192.168.2.67 -U postgres -c 4 -j 1 -T 180 -l \
--aggregate-interval 1 bench &
# After 20 seconds...
sleep 20
# Initiate the migration.
echo "Starting the migration..."
case $experiment in
a)
ssh -p 1337 -i ~/.ssh/waterloo [email protected] \
'xl migrate debvm 192.168.2.63' \
> pgbench-$experiment-$i.log 2>&1
;;
b)
ssh -p 1337 -i ~/.ssh/waterloo [email protected] \
'xl migrate --precopy-iterations 1 debvm 192.168.2.63' \
> pgbench-$experiment-$i.log 2>&1
;;
c)
ssh -p 1337 -i ~/.ssh/waterloo [email protected] \
'xl migrate --precopy-iterations 0 --postcopy debvm 192.168.2.63' \
> pgbench-$experiment-$i.log 2>&1
;;
d)
ssh -p 1337 -i ~/.ssh/waterloo [email protected] \
'xl migrate --precopy-iterations 1 --postcopy debvm 192.168.2.63' \
> pgbench-$experiment-$i.log 2>&1
;;
e)
ssh -p 1337 -i ~/.ssh/waterloo [email protected] \
'xl migrate --precopy-iterations 5 --postcopy debvm 192.168.2.63' \
> pgbench-$experiment-$i.log 2>&1
;;
esac
# Wait for the benchmark to complete.
echo "Migration complete."
wait
# Rename the benchmark log to something more useful.
mv pgbench_log.* pgbench-perf-$experiment-$i.log
# Shut down the test VM.
echo "Cleaning up..."
ssh -i ~/.ssh/waterloo [email protected] \
'(sleep 10 && shutdown -h now) < /dev/null > /dev/null 2>&1 &'
# Wait for it to really be down.
sleep 20
donedone
echo 'All done'
[p] Post-copy tracing patches
https://github.com/jtotto/xen/commits/postcopy-tracing
Joshua Otto (23):
tools: rename COLO 'postcopy' to 'aftercopy'
libxc/xc_sr: parameterise write_record() on fd libxc/xc_sr_restore.c: use write_record() in
send_checkpoint_dirty_pfn_list()
libxc/xc_sr: naming correction: mfns -> gfns libxc/xc_sr_restore: introduce generic 'pages' records libxc/xc_sr_restore: factor helpers out of handle_page_data() libxc/migration: tidy the xc_domain_save()/restore() interface libxc/migration: defer precopy policy to a callback libxl/migration: wire up the precopy policy RPC callback libxc/xc_sr_save: introduce save batch types libxc/migration: correct hvm record ordering specification libxc/migration: specify postcopy live migration libxc/migration: add try_read_record()
libxc/migration: implement the sender side of postcopy live migration libxc/migration: implement the receiver side of postcopy live
migration
libxl/libxl_stream_write.c: track callback chains with an explicit
phase
libxl/libxl_stream_read.c: track callback chains with an explicit
phase
libxl/migration: implement the sender side of postcopy live migration libxl/migration: implement the receiver side of postcopy live
migration
tools: expose postcopy live migration support in libxl and xl xen/mem_paging: move paging op arguments into a union xen/mem_paging: add a populate_evicted paging op libxc/xc_sr_restore.c: use populate_evicted()
docs/specs/libxc-migration-stream.pandoc | 182 +++- docs/specs/libxl-migration-stream.pandoc | 19 +- tools/libxc/include/xenctrl.h | 2 + tools/libxc/include/xenguest.h | 237 +++--- tools/libxc/xc_mem_paging.c | 39 +- tools/libxc/xc_nomigrate.c | 16 +- tools/libxc/xc_private.c | 21 +- tools/libxc/xc_private.h | 2 + tools/libxc/xc_sr_common.c | 116 ++- tools/libxc/xc_sr_common.h | 170 +++- tools/libxc/xc_sr_common_x86.c | 2 +- tools/libxc/xc_sr_restore.c | 1321 +++++++++++++++++++++++++----- tools/libxc/xc_sr_restore_x86_hvm.c | 41 +- tools/libxc/xc_sr_save.c | 903 ++++++++++++++++---- tools/libxc/xc_sr_save_x86_hvm.c | 18 +- tools/libxc/xc_sr_save_x86_pv.c | 17 +- tools/libxc/xc_sr_stream_format.h | 15 +- tools/libxc/xg_save_restore.h | 16 +- tools/libxl/libxl.h | 40 +- tools/libxl/libxl_colo_restore.c | 2 +- tools/libxl/libxl_colo_save.c | 2 +- tools/libxl/libxl_create.c | 191 ++++- tools/libxl/libxl_dom_save.c | 71 +- tools/libxl/libxl_domain.c | 33 +- tools/libxl/libxl_internal.h | 80 +- tools/libxl/libxl_remus.c | 2 +- tools/libxl/libxl_save_callout.c | 12 +- tools/libxl/libxl_save_helper.c | 60 +- tools/libxl/libxl_save_msgs_gen.pl | 10 +- tools/libxl/libxl_sr_stream_format.h | 13 +- tools/libxl/libxl_stream_read.c | 136 ++- tools/libxl/libxl_stream_write.c | 161 ++-- tools/ocaml/libs/xl/xenlight_stubs.c | 2 +- tools/xl/xl.h | 7 +- tools/xl/xl_cmdtable.c | 3 + tools/xl/xl_migrate.c | 65 +- tools/xl/xl_vmcontrol.c | 8 +- xen/arch/x86/mm.c | 5 +- xen/arch/x86/mm/mem_paging.c | 40 +- xen/arch/x86/mm/p2m.c | 101 +++ xen/arch/x86/x86_64/compat/mm.c | 6 +- xen/arch/x86/x86_64/mm.c | 6 +- xen/include/asm-x86/mem_paging.h | 3 +- xen/include/asm-x86/p2m.h | 2 + xen/include/public/memory.h | 25 +- 45 files changed, 3489 insertions(+), 734 deletions(-)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 1/23 tools: rename COLO 'postcopy' to 'aftercopy'
From: Joshua Otto <[email protected]>
The COLO xc domain save and restore procedures both make use of a 'postcopy' callback to defer part of each checkpoint operation to xl. In this context, the name 'postcopy' is meant as "the callback invoked immediately after this checkpoint's memory callback." This is an unfortunate name collision with the other common use of 'postcopy' in the context of live migration, where it is used to mean "a memory migration that permits the guest to execute at the destination before all of its memory is migrated by servicing accesses to unmigrated memory via a network page-fault."
Mechanically rename 'postcopy' -> 'aftercopy' to free up the postcopy namespace while preserving the original intent of the name in the COLO context.
No functional change.
--- tools/libxc/include/xenguest.h | 4 ++-- tools/libxc/xc_sr_restore.c | 4 ++-- tools/libxc/xc_sr_save.c | 4 ++-- tools/libxl/libxl_colo_restore.c | 2 +- tools/libxl/libxl_colo_save.c | 2 +- tools/libxl/libxl_remus.c | 2 +- tools/libxl/libxl_save_msgs_gen.pl | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)
tools/libxc/include/xenguest.h +2 -2
@@ -53,7 +53,7 @@ struct save_callbacks {* xc_domain_save then flushes the output buffer, while the * guest continues to run. */ -int (*postcopy)(void * data); +int (*aftercopy)(void * data);/* Called after the memory checkpoint has been flushed * out into the network. Typical actions performed in this
@@ -115,7 +115,7 @@ struct restore_callbacks {* Callback function resumes the guest & the device model, * returns to xc_domain_restore. */ -int (*postcopy)(void * data); +int (*aftercopy)(void * data);/* A checkpoint record has been found in the stream. * returns: */
tools/libxc/xc_sr_restore.c +2 -2
@@ -576,7 +576,7 @@ static int handle_checkpoint(struct xc_sr_context *ctx) ctx->restore.callbacks->data);/* Resume secondary vm */ - ret = ctx->restore.callbacks->postcopy (ctx->restore.callbacks->data); + ret = ctx->restore.callbacks->aftercopy (ctx->restore.callbacks->data);HANDLE_CALLBACK_RETURN_VALUE (ret);/* Wait for a new checkpoint */
@@ -855,7 +855,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, {/* this is COLO restore */ assert (callbacks->suspend && - callbacks->postcopy && + callbacks->aftercopy && callbacks->wait_checkpoint && callbacks->restore_results); }
tools/libxc/xc_sr_save.c +2 -2
@@ -863,7 +863,7 @@ static int save(struct xc_sr_context *ctx, uint16_t guest_type) } } - rc = ctx->save.callbacks->postcopy (ctx->save.callbacks->data); + rc = ctx->save.callbacks->aftercopy (ctx->save.callbacks->data);if ( rc <=0 ) goto err;
@@ -951,7 +951,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,if ( hvm )assert (callbacks->switch_qemu_logdirty);if ( ctx.save.checkpointed ) -assert (callbacks->checkpoint && callbacks->postcopy); +assert (callbacks->checkpoint && callbacks->aftercopy);if ( ctx.save.checkpointed ==XC_MIG_STREAM_COLO )assert (callbacks->wait_checkpoint);
tools/libxl/libxl_colo_restore.c +1 -1
@@ -246,7 +246,7 @@ void libxl__colo_restore_setup(libxl__egc *egc,if (init_dsps (&crcs->dsps)) goto out; - callbacks->postcopy = libxl__colo_restore_domain_resume_callback; + callbacks->aftercopy = libxl__colo_restore_domain_resume_callback; callbacks->wait_checkpoint = libxl__colo_restore_domain_wait_checkpoint_callback; callbacks->suspend = libxl__colo_restore_domain_suspend_callback; callbacks->checkpoint = libxl__colo_restore_domain_checkpoint_callback;
tools/libxl/libxl_colo_save.c +1 -1
@@ -145,7 +145,7 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css) callbacks->suspend = libxl__colo_save_domain_suspend_callback; callbacks->checkpoint = libxl__colo_save_domain_checkpoint_callback; - callbacks->postcopy = libxl__colo_save_domain_resume_callback; + callbacks->aftercopy = libxl__colo_save_domain_resume_callback; callbacks->wait_checkpoint = libxl__colo_save_domain_wait_checkpoint_callback;libxl__checkpoint_devices_setup (egc, &dss->cds);
tools/libxl/libxl_remus.c +1 -1
@@ -110,7 +110,7 @@ void libxl__remus_setup(libxl__egc *egc, libxl__remus_state *rs) dss->sws.checkpoint_callback = remus_checkpoint_stream_written; callbacks->suspend = libxl__remus_domain_suspend_callback; - callbacks->postcopy = libxl__remus_domain_resume_callback; + callbacks->aftercopy = libxl__remus_domain_resume_callback; callbacks->checkpoint = libxl__remus_domain_save_checkpoint_callback;libxl__checkpoint_devices_setup (egc, cds);
tools/libxl/libxl_save_msgs_gen.pl +1 -1
@@ -24,7 +24,7 @@ our @msgs = ( 'unsigned long', 'done', 'unsigned long', 'total'] ], [ 3, 'srcxA', "suspend", [] ], - [ 4, 'srcxA', "postcopy", [] ], + [ 4, 'srcxA', "aftercopy", [] ], [ 5, 'srcxA', "checkpoint", [] ], [ 6, 'srcxA', "wait_checkpoint", [] ], [ 7, 'scxA', "switch_qemu_logdirty", [qw(int domid
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 2/23 libxc/xc_sr: parameterise write_record() on fd
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
Right now, write_split_record() - which is delegated to by write_record() - implicitly writes to ctx->fd. This means it can't be used with the restore context's send_back_fd, which is inconvenient.
Add an 'fd' parameter to both write_record() and write_split_record(), and mechanically update all existing callsites to pass ctx->fd for it.
No functional change.
--- tools/libxc/xc_sr_common.c | 6 +++--- tools/libxc/xc_sr_common.h | 8 ++++---- tools/libxc/xc_sr_common_x86.c | 2 +- tools/libxc/xc_sr_save.c | 6 +++--- tools/libxc/xc_sr_save_x86_hvm.c | 5 +++-- tools/libxc/xc_sr_save_x86_pv.c | 17 +++++++++-------- 6 files changed, 23 insertions(+), 21 deletions(-)
tools/libxc/xc_sr_common.c +3 -3
@@ -52,8 +52,8 @@ const char *rec_type_to_str(uint32_t type)return "Reserved" ; } -int write_split_record (struct xc_sr_context *ctx,struct xc_sr_record *rec, -void *buf,size_t sz) +int write_split_record (struct xc_sr_context *ctx,int fd, +struct xc_sr_record *rec,void *buf,size_t sz) {static const char zeroes[(1u <<REC_ALIGN_ORDER ) -1 ] = {0 };
@@ -81,7 +81,7 @@ int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,if ( sz )assert (buf); -if (writev_exact (ctx->fd, parts,ARRAY_SIZE (parts)) ) +if (writev_exact (fd, parts,ARRAY_SIZE (parts)) ) goto err;return 0 ;
tools/libxc/xc_sr_common.h +4 -4
@@ -361,8 +361,8 @@ struct xc_sr_record* * Returns 0 on success and non0 on failure. */ -int write_split_record (struct xc_sr_context *ctx,struct xc_sr_record *rec, -void *buf,size_t sz); +int write_split_record (struct xc_sr_context *ctx,int fd, +struct xc_sr_record *rec,void *buf,size_t sz);/* * Writes a record to the stream, applying correct padding where appropriate.
@@ -371,10 +371,10 @@ int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,* * Returns 0 on success and non0 on failure. */ -static inline int write_record (struct xc_sr_context *ctx, +static inline int write_record (struct xc_sr_context *ctx,int fd,struct xc_sr_record *rec) { -return write_split_record (ctx, rec,NULL ,0 ); +return write_split_record (ctx, fd, rec,NULL ,0 ); }/*
tools/libxc/xc_sr_common_x86.c +1 -1
@@ -18,7 +18,7 @@ int write_tsc_info(struct xc_sr_context *ctx)return -1 ; } -return write_record (ctx, &rec); +return write_record (ctx, ctx->fd, &rec); }int handle_tsc_info (struct xc_sr_context *ctx,struct xc_sr_record *rec)
tools/libxc/xc_sr_save.c +3 -3
@@ -53,7 +53,7 @@ static int write_end_record(struct xc_sr_context *ctx) {struct xc_sr_record end = {REC_TYPE_END ,0 ,NULL }; -return write_record (ctx, &end); +return write_record (ctx, ctx->fd, &end); }/*
@@ -63,7 +63,7 @@ static int write_checkpoint_record(struct xc_sr_context *ctx) {struct xc_sr_record checkpoint = {REC_TYPE_CHECKPOINT ,0 ,NULL }; -return write_record (ctx, &checkpoint); +return write_record (ctx, ctx->fd, &checkpoint); }/*
@@ -646,7 +646,7 @@ static int verify_frames(struct xc_sr_context *ctx)DPRINTF ("Enabling verify mode" ); - rc =write_record (ctx, &rec); + rc =write_record (ctx, ctx->fd, &rec);if ( rc ) goto out;
tools/libxc/xc_sr_save_x86_hvm.c +3 -2
@@ -42,7 +42,7 @@ static int write_hvm_context(struct xc_sr_context *ctx) } hvm_rec.length = hvm_buf_size; - rc =write_record (ctx, &hvm_rec); + rc =write_record (ctx, ctx->fd, &hvm_rec);if ( rc <0 ) {PERROR ("error write HVM_CONTEXT record" );
@@ -116,7 +116,8 @@ static int write_hvm_params(struct xc_sr_context *ctx)if ( hdr.count ==0 )return 0 ; - rc =write_split_record (ctx, &rec, entries, hdr.count *sizeof (*entries)); + rc =write_split_record (ctx, ctx->fd, &rec, entries, + hdr.count *sizeof (*entries));if ( rc )PERROR ("Failed to write HVM_PARAMS record" );
tools/libxc/xc_sr_save_x86_pv.c +9 -8
@@ -571,9 +571,9 @@ static int write_one_vcpu_basic(struct xc_sr_context *ctx, uint32_t id) }if ( ctx->x86_pv.width ==8 ) - rc =write_split_record (ctx, &rec, &vcpu,sizeof (vcpu.x64)); + rc =write_split_record (ctx, ctx->fd, &rec, &vcpu,sizeof (vcpu.x64));else - rc =write_split_record (ctx, &rec, &vcpu,sizeof (vcpu.x32)); + rc =write_split_record (ctx, ctx->fd, &rec, &vcpu,sizeof (vcpu.x32)); err:return rc;
@@ -613,7 +613,7 @@ static int write_one_vcpu_extended(struct xc_sr_context *ctx, uint32_t id)if ( domctl.u.ext_vcpucontext.size ==0 )return 0 ; -return write_split_record (ctx, &rec, &domctl.u.ext_vcpucontext, +return write_split_record (ctx, ctx->fd, &rec, &domctl.u.ext_vcpucontext, domctl.u.ext_vcpucontext.size); }
@@ -672,7 +672,8 @@ static int write_one_vcpu_xsave(struct xc_sr_context *ctx, uint32_t id)if ( domctl.u.vcpuextstate.size ==0 ) goto out; - rc =write_split_record (ctx, &rec, buffer, domctl.u.vcpuextstate.size); + rc =write_split_record (ctx, ctx->fd, &rec, buffer, + domctl.u.vcpuextstate.size);if ( rc ) goto err;
@@ -742,7 +743,7 @@ static int write_one_vcpu_msrs(struct xc_sr_context *ctx, uint32_t id)if ( domctl.u.vcpu_msrs.msr_count ==0 ) goto out; - rc =write_split_record (ctx, &rec, buffer, + rc =write_split_record (ctx, ctx->fd, &rec, buffer, domctl.u.vcpu_msrs.msr_count *sizeof (xen_domctl_vcpu_msr_t));if ( rc )
@@ -817,7 +818,7 @@ static int write_x86_pv_info(struct xc_sr_context *ctx) .data = &info }; -return write_record (ctx, &rec); +return write_record (ctx, ctx->fd, &rec); }/*
@@ -858,7 +859,7 @@ static int write_x86_pv_p2m_frames(struct xc_sr_context *ctx)else data = (uint64_t *)ctx->x86_pv.p2m_pfns; - rc =write_split_record (ctx, &rec, data, datasz); + rc =write_split_record (ctx, ctx->fd, &rec, data, datasz);if ( data != (uint64_t *)ctx->x86_pv.p2m_pfns )free (data);
@@ -878,7 +879,7 @@ static int write_shared_info(struct xc_sr_context *ctx) .data = ctx->x86_pv.shinfo, }; -return write_record (ctx, &rec); +return write_record (ctx, ctx->fd, &rec); }/*
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 3/23 libxc/xc_sr_restore.c: use write_record() in send_checkpoint_dirty_pfn_list()
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
Teach send_checkpoint_dirty_pfn_list() to use write_record()'s new fd parameter, avoiding the need for a manual writev().
No functional change.
--- tools/libxc/xc_sr_restore.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-)
tools/libxc/xc_sr_restore.c +4 -23
@@ -420,7 +420,6 @@ static int send_checkpoint_dirty_pfn_list(struct xc_sr_context *ctx)int rc =-1 ;unsigned count, written;uint64_t i, *pfns =NULL ; -struct iovec *iov =NULL ;xc_shadow_op_stats_t stats = {0 , ctx->restore.p2m_size };struct xc_sr_record rec = {
@@ -467,35 +466,17 @@ static int send_checkpoint_dirty_pfn_list(struct xc_sr_context *ctx) pfns[written++] = i; } -/* iovec[] for writev(). */ - iov =malloc (3 *sizeof (*iov)); -if ( !iov ) - { -ERROR ("Unable to allocate memory for sending dirty bitmap" ); - goto err; - } - + rec.data = pfns; rec.length = count *sizeof (*pfns); - iov[0 ].iov_base = &rec.type; - iov[0 ].iov_len =sizeof (rec.type); - - iov[1 ].iov_base = &rec.length; - iov[1 ].iov_len =sizeof (rec.length); - - iov[2 ].iov_base = pfns; - iov[2 ].iov_len = count *sizeof (*pfns); - -if (writev_exact (ctx->restore.send_back_fd, iov,3 ) ) - { -PERROR ("Failed to write dirty bitmap to stream" ); + rc =write_record (ctx, ctx->restore.send_back_fd, &rec); +if ( rc ) goto err; - } rc =0 ; + err:free (pfns); -free (iov);return rc; }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 4/23 libxc/xc_sr: naming correction: mfns -> gfns
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
In write_batch() on the migration save side and in process_page_data() on the corresponding path on the restore side, a local variable named 'mfns' is used to refer to an array of what are actually gfns. Rename both to 'gfns' to address this.
No functional change.
--- tools/libxc/xc_sr_restore.c | 16 ++++++++-------- tools/libxc/xc_sr_save.c | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-)
tools/libxc/xc_sr_restore.c +8 -8
@@ -203,7 +203,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, xen_pfn_t *pfns, uint32_t *types, void *page_data) {xc_interface *xch = ctx->xch; -xen_pfn_t *mfns =malloc (count *sizeof (*mfns)); +xen_pfn_t *gfns =malloc (count *sizeof (*gfns));int *map_errs =malloc (count *sizeof (*map_errs));int rc;void *mapping =NULL , *guest_page =NULL ;
@@ -211,11 +211,11 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, j,/* j indexes the subset of pfns we decide to map. */ nr_pages =0 ; -if ( !mfns || !map_errs ) +if ( !gfns || !map_errs ) { rc =-1 ;ERROR ("Failed to allocate %zu bytes to process page data" , - count * (sizeof (*mfns) +sizeof (*map_errs))); + count * (sizeof (*gfns) +sizeof (*map_errs))); goto err; }
@@ -246,7 +246,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,case XEN_DOMCTL_PFINFO_L4TAB :case XEN_DOMCTL_PFINFO_L4TAB |XEN_DOMCTL_PFINFO_LPINTAB : - mfns[nr_pages++] = ctx->restore.ops.pfn_to_gfn (ctx, pfns[i]); + gfns[nr_pages++] = ctx->restore.ops.pfn_to_gfn (ctx, pfns[i]);break ; } }
@@ -257,11 +257,11 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, mapping = guest_page =xenforeignmemory_map (xch->fmem, ctx->domid,PROT_READ |PROT_WRITE , - nr_pages, mfns, map_errs); + nr_pages, gfns, map_errs);if ( !mapping ) { rc =-1 ; -PERROR ("Unable to map %u mfns for %u pages of data" , +PERROR ("Unable to map %u gfns for %u pages of data" , nr_pages, count); goto err; }
@@ -281,7 +281,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, { rc =-1 ;ERROR ("Mapping pfn %#" PRIpfn" (mfn %#" PRIpfn", type %#" PRIx32") failed with %d" , - pfns[i], mfns[j], types[i], map_errs[j]); + pfns[i], gfns[j], types[i], map_errs[j]); goto err; }
@@ -320,7 +320,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,xenforeignmemory_unmap (xch->fmem, mapping, nr_pages);free (map_errs); -free (mfns); +free (gfns);return rc; }
tools/libxc/xc_sr_save.c +10 -10
@@ -79,7 +79,7 @@ static int write_checkpoint_record(struct xc_sr_context *ctx)static int write_batch (struct xc_sr_context *ctx) {xc_interface *xch = ctx->xch; -xen_pfn_t *mfns =NULL , *types =NULL ; +xen_pfn_t *gfns =NULL , *types =NULL ;void *guest_mapping =NULL ;void **guest_data =NULL ;void **local_pages =NULL ;
@@ -98,7 +98,7 @@ static int write_batch(struct xc_sr_context *ctx)assert (nr_pfns !=0 );/* Mfns of the batch pfns. */ - mfns =malloc (nr_pfns *sizeof (*mfns)); + gfns =malloc (nr_pfns *sizeof (*gfns));/* Types of the batch pfns. */ types =malloc (nr_pfns *sizeof (*types));/* Errors from attempting to map the gfns. */
@@ -110,7 +110,7 @@ static int write_batch(struct xc_sr_context *ctx)/* iovec[] for writev(). */ iov =malloc ((nr_pfns +4 ) *sizeof (*iov)); -if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov ) +if ( !gfns || !types || !errors || !guest_data || !local_pages || !iov ) {ERROR ("Unable to allocate arrays for a batch of %u pages" , nr_pfns);
@@ -119,11 +119,11 @@ static int write_batch(struct xc_sr_context *ctx)for ( i =0 ; i < nr_pfns; ++i ) { - types[i] = mfns[i] = ctx->save.ops.pfn_to_gfn (ctx, + types[i] = gfns[i] = ctx->save.ops.pfn_to_gfn (ctx, ctx->save.batch_pfns[i]);/* Likely a ballooned page. */ -if ( mfns[i] ==INVALID_MFN ) +if ( gfns[i] ==INVALID_MFN ) {set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); ++ctx->save.nr_deferred_pages;
@@ -148,13 +148,13 @@ static int write_batch(struct xc_sr_context *ctx)continue ; } - mfns[nr_pages++] = mfns[i]; + gfns[nr_pages++] = gfns[i]; }if ( nr_pages >0 ) { guest_mapping =xenforeignmemory_map (xch->fmem, - ctx->domid,PROT_READ , nr_pages, mfns, errors); + ctx->domid,PROT_READ , nr_pages, gfns, errors);if ( !guest_mapping ) {PERROR ("Failed to map guest pages" );
@@ -174,8 +174,8 @@ static int write_batch(struct xc_sr_context *ctx)if ( errors[p] ) { -ERROR ("Mapping of pfn %#" PRIpfn" (mfn %#" PRIpfn") failed %d" , - ctx->save.batch_pfns[i], mfns[p], errors[p]); +ERROR ("Mapping of pfn %#" PRIpfn" (gfn %#" PRIpfn") failed %d" , + ctx->save.batch_pfns[i], gfns[p], errors[p]); goto err; }
@@ -271,7 +271,7 @@ static int write_batch(struct xc_sr_context *ctx)free (guest_data);free (errors);free (types); -free (mfns); +free (gfns);return rc; }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH RFC v2 04/23] libxc/xc_sr: naming correction: mfns -> gfns
Quoted 11 lines · Joshua Otto
From: Joshua Otto <[email protected]>
In
write_batch()on the migration save side and inprocess_page_data()on the corresponding path on the restore side, a local variable named 'mfns' is used to refer to an array of what are actually gfns. Rename both to 'gfns' to address this.No functional change.
Signed-off-by Joshua Otto <[email protected]>Suggested-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 5/23 libxc/xc_sr_restore: introduce generic 'pages' records
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
The PAGE_DATA migration record type is specified as an array of uint64_ts encoding pfns and their types, followed by an array of page contents. Postcopy live migration specifies a number of records with similar or the same format, and it would be convenient to be able to re-use the code that validates and unpacks such records for each type. To facilitate this, introduce the generic 'pages' name for such records and rename the PAGE_DATA stream format struct and pfn encoding masks accordingly.
No functional change.
--- tools/libxc/xc_sr_common.c | 2 +- tools/libxc/xc_sr_restore.c | 6 +++--- tools/libxc/xc_sr_save.c | 2 +- tools/libxc/xc_sr_stream_format.h | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-)
tools/libxc/xc_sr_common.c +1 -1
@@ -146,7 +146,7 @@ static void __attribute__((unused)) build_assertions(void)BUILD_BUG_ON (sizeof (struct xc_sr_dhdr ) !=16 );BUILD_BUG_ON (sizeof (struct xc_sr_rhdr ) !=8 ); -BUILD_BUG_ON (sizeof (struct xc_sr_rec_page_data_header ) !=8 ); +BUILD_BUG_ON (sizeof (struct xc_sr_rec_pages_header ) !=8 );BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_info ) !=8 );BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_p2m_frames ) !=8 );BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_vcpu_hdr ) !=8 );
tools/libxc/xc_sr_restore.c +3 -3
@@ -332,7 +332,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,static int handle_page_data (struct xc_sr_context *ctx,struct xc_sr_record *rec) {xc_interface *xch = ctx->xch; -struct xc_sr_rec_page_data_header *pages = rec->data; +struct xc_sr_rec_pages_header *pages = rec->data;unsigned i, pages_of_data =0 ;int rc =-1 ;
@@ -368,14 +368,14 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)for ( i =0 ; i < pages->count; ++i ) { - pfn = pages->pfn[i] &PAGE_DATA_PFN_MASK ; + pfn = pages->pfn[i] &REC_PFINFO_PFN_MASK ;if ( !ctx->restore.ops.pfn_is_valid (ctx, pfn) ) {ERROR ("pfn %#" PRIpfn" (index %u) outside domain maximum" , pfn, i); goto err; } - type = (pages->pfn[i] &PAGE_DATA_TYPE_MASK ) >>32 ; + type = (pages->pfn[i] &REC_PFINFO_TYPE_MASK ) >>32 ;if ( ((type >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ) >=5 ) && ((type >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ) <=8 ) ) {
tools/libxc/xc_sr_save.c +1 -1
@@ -89,7 +89,7 @@ static int write_batch(struct xc_sr_context *ctx)void *page, *orig_page;uint64_t *rec_pfns =NULL ;struct iovec *iov =NULL ;int iovcnt =0 ; -struct xc_sr_rec_page_data_header hdr = {0 }; +struct xc_sr_rec_pages_header hdr = {0 };struct xc_sr_record rec = { .type =REC_TYPE_PAGE_DATA ,
tools/libxc/xc_sr_stream_format.h +3 -3
@@ -80,15 +80,15 @@ struct xc_sr_rhdr#define REC_TYPE_OPTIONAL 0x80000000U/* PAGE_DATA */ -struct xc_sr_rec_page_data_header +struct xc_sr_rec_pages_header {uint32_t count;uint32_t _res1;uint64_t pfn[0 ]; }; -#define PAGE_DATA_PFN_MASK 0x000fffffffffffffULL -#define PAGE_DATA_TYPE_MASK 0xf000000000000000ULL +#define REC_PFINFO_PFN_MASK 0x000fffffffffffffULL +#define REC_PFINFO_TYPE_MASK 0xf000000000000000ULL/* X86_PV_INFO */ struct xc_sr_rec_x86_pv_info
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 6/23 libxc/xc_sr_restore: factor helpers out of handle_page_data()
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
When processing a PAGE_DATA record, the restore code:
1) applies a number of sanity checks on the record's headers and size
2) decodes the list of packed page info into pfns and their types
3) using the pfn and type info, populates and fills the pages into the guest using process_page_data()
Steps 1) and 2) are also useful for other types of pages records introduced by postcopy live migration, so factor them into reusable helper routines.
No functional change.
--- tools/libxc/xc_sr_common.c | 36 ++++++++++++++++++ tools/libxc/xc_sr_common.h | 10 +++++ tools/libxc/xc_sr_restore.c | 89 ++++++++++++++++++++++++++------------------- 3 files changed, 97 insertions(+), 38 deletions(-)
tools/libxc/xc_sr_common.c +36 -0
@@ -140,6 +140,42 @@ int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec)return 0 ; }; +int validate_pages_record (struct xc_sr_context *ctx,struct xc_sr_record *rec, +uint32_t expected_type) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_rec_pages_header *pages = rec->data; + +if ( rec->type != expected_type ) + { +ERROR ("%s record type expected, instead received record of type " +"%08x (%s)" ,rec_type_to_str (expected_type), rec->type, +rec_type_to_str (rec->type)); +return -1 ; + } +else if ( rec->length <sizeof (*pages) ) + { +ERROR ("%s record truncated: length %u, min %zu" , +rec_type_to_str (rec->type), rec->length,sizeof (*pages)); +return -1 ; + } +else if ( pages->count <1 ) + { +ERROR ("Expected at least 1 pfn in %s record" , +rec_type_to_str (rec->type)); +return -1 ; + } +else if ( rec->length <sizeof (*pages) + (pages->count *sizeof (uint64_t )) ) + { +ERROR ("%s record (length %u) too short to contain %u" +" pfns worth of information" ,rec_type_to_str (rec->type), + rec->length, pages->count); +return -1 ; + } + +return 0 ; +} +static void __attribute__((unused))build_assertions (void ) {BUILD_BUG_ON (sizeof (struct xc_sr_ihdr ) !=24 );
tools/libxc/xc_sr_common.h +10 -0
@@ -392,6 +392,16 @@ static inline int write_record(struct xc_sr_context *ctx, int fd,int read_record (struct xc_sr_context *ctx,int fd,struct xc_sr_record *rec);/* +* Given a record of one of the page data types, validate it by: +* - checking its actual type against its specific expected type +* - sanity checking its actual length against its claimed length +* +* Returns 0 on success and non-0 on failure. +*/ +int validate_pages_record (struct xc_sr_context *ctx,struct xc_sr_record *rec, +uint32_t expected_type); + +/* * This would ideally be private in restore.c, but is needed by * x86_pv_localise_page() if we receive pagetables frames ahead of the * contents of the frames they point at.
tools/libxc/xc_sr_restore.c +51 -38
110 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 7/23 libxc/migration: tidy the xc_domain_save()/restore() interface
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
Both xc_domain_save() and xc_domain_restore() have a high number of parameters, including a number of boolean parameters that are split between a bitfield flags argument and separate individual boolean arguments. Further, many of these arguments are dead/ignored.
Tidy the interface to these functions by collecting the parameters into a structure assembled by the caller and passed by pointer, and drop the dead parameters.
No functional change.
--- tools/libxc/include/xenguest.h | 68 ++++++++++++++++++++-------------------- tools/libxc/xc_nomigrate.c | 16 +++------- tools/libxc/xc_sr_common.h | 4 +-- tools/libxc/xc_sr_restore.c | 47 +++++++++++++-------------- tools/libxc/xc_sr_save.c | 54 +++++++++++++++---------------- tools/libxl/libxl_dom_save.c | 11 ------- tools/libxl/libxl_internal.h | 1 - tools/libxl/libxl_save_callout.c | 12 +++---- tools/libxl/libxl_save_helper.c | 61 ++++++++++++++++------------------- 9 files changed, 122 insertions(+), 152 deletions(-)
tools/libxc/include/xenguest.h +34 -34
@@ -22,16 +22,9 @@#ifndef XENGUEST_H #define XENGUEST_H -#define XC_NUMA_NO_NODE (~0U) - -#define XCFLAGS_LIVE (1 << 0) -#define XCFLAGS_DEBUG (1 << 1) -#define XCFLAGS_HVM (1 << 2) -#define XCFLAGS_STDVGA (1 << 3) -#define XCFLAGS_CHECKPOINT_COMPRESS (1 << 4) +#include <stdbool.h> -#define X86_64_B_SIZE 64 -#define X86_32_B_SIZE 32 +#define XC_NUMA_NO_NODE (~0U)/* * User not using xc_suspend_* / xc_await_suspent may not want to
@@ -90,20 +83,26 @@ typedef enum {XC_MIG_STREAM_COLO , } xc_migration_stream_t; +struct domain_save_params { +uint32_t dom;/* the id of the domain */ +int save_fd;/* the fd to save the domain to */ +int recv_fd;/* the fd to receive live protocol responses */ +uint32_t max_iters;/* how many precopy iterations before we give up? */ +bool live;/* is this a live migration? */ +bool debug;/* are we in debug mode? */ +xc_migration_stream_t stream_type;/* is there checkpointing involved? */ +}; +/** * This function will save a running domain. * * @parm xch a handle to an open hypervisor interface -* @parm fd the file descriptor to save a domain to -* @parm dom the id of the domain -* @param stream_type XC_MIG_STREAM_NONE if the far end of the stream -* doesn't use checkpointing +* @parm params a description of the requested save/migration +* @parm callbacks hooks for delegated steps of the save procedure * @return 0 on success, -1 on failure */ -int xc_domain_save (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters, -uint32_t max_factor,uint32_t flags/* XCFLAGS_xxx */ , -struct save_callbacks * callbacks,int hvm, -xc_migration_stream_t stream_type,int recv_fd); +int xc_domain_save (xc_interface *xch,const struct domain_save_params *params, +const struct save_callbacks *callbacks);/* callbacks provided by xc_domain_restore */ struct restore_callbacks {
@@ -145,31 +144,32 @@ struct restore_callbacks {void * data; }; +struct domain_restore_params { +uint32_t dom;/* the id of the domain */ +int recv_fd;/* the fd to restore the domain from */ +int send_back_fd;/* the fd to send live protocol responses */ +unsigned int store_evtchn;/* the store event channel */ +xen_pfn_t *store_gfn;/* OUT - the gfn of the store page */ +domid_t store_domid;/* the store domain id */ +unsigned int console_evtchn;/* the console event channel */ +xen_pfn_t *console_gfn;/* OUT - the gfn of the console page */ +domid_t console_domid;/* the console domain id */ +xc_migration_stream_t stream_type;/* is there checkpointing involved? */ +}; +/** * This function will restore a saved domain. * * Domain is restored in a suspended state ready to be unpaused. * * @parm xch a handle to an open hypervisor interface -* @parm fd the file descriptor to restore a domain from -* @parm dom the id of the domain -* @parm store_evtchn the store event channel for this domain to use -* @parm store_mfn returned with the mfn of the store page -* @parm hvm non-zero if this is a HVM restore -* @parm pae non-zero if this HVM domain has PAE support enabled -* @parm superpages non-zero to allocate guest memory with superpages -* @parm stream_type non-zero if the far end of the stream is using checkpointing -* @parm callbacks non-NULL to receive a callback to restore toolstack -* specific data +* @parm params a description of the requested restore operation +* @parm callbacks hooks for delegated steps of the restore procedure * @return 0 on success, -1 on failure */ -int xc_domain_restore (xc_interface *xch,int io_fd,uint32_t dom, -unsigned int store_evtchn,unsigned long *store_mfn, -domid_t store_domid,unsigned int console_evtchn, -unsigned long *console_mfn,domid_t console_domid, -unsigned int hvm,unsigned int pae,int superpages, -xc_migration_stream_t stream_type, -struct restore_callbacks *callbacks,int send_back_fd); +int xc_domain_restore (xc_interface *xch, +const struct domain_restore_params *params, +const struct restore_callbacks *callbacks);/** * This function will create a domain for a paravirtualized Linux
tools/libxc/xc_nomigrate.c +5 -11
@@ -20,22 +20,16 @@#include <xenctrl.h> #include <xenguest.h> -int xc_domain_save (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters, -uint32_t max_factor,uint32_t flags, -struct save_callbacks * callbacks,int hvm, -xc_migration_stream_t stream_type,int recv_fd) +int xc_domain_save (xc_interface *xch,const struct domain_save_params *params, +const struct save_callbacks *callbacks) { errno =ENOSYS ;return -1 ; } -int xc_domain_restore (xc_interface *xch,int io_fd,uint32_t dom, -unsigned int store_evtchn,unsigned long *store_mfn, -domid_t store_domid,unsigned int console_evtchn, -unsigned long *console_mfn,domid_t console_domid, -unsigned int hvm,unsigned int pae,int superpages, -xc_migration_stream_t stream_type, -struct restore_callbacks *callbacks,int send_back_fd) +int xc_domain_restore (xc_interface *xch, +const struct domain_restore_params *params, +const struct restore_callbacks *callbacks) { errno =ENOSYS ;return -1 ;
tools/libxc/xc_sr_common.h +2 -2
@@ -187,7 +187,7 @@ struct xc_sr_contextint recv_fd;struct xc_sr_save_ops ops; -struct save_callbacks *callbacks; +const struct save_callbacks *callbacks;/* Live migrate vs non live suspend. */ bool live;
@@ -214,7 +214,7 @@ struct xc_sr_contextstruct /* Restore data. */ {struct xc_sr_restore_ops ops; -struct restore_callbacks *callbacks; +const struct restore_callbacks *callbacks;int send_back_fd;unsigned long p2m_size;
tools/libxc/xc_sr_restore.c +21 -26
89 lines not on this page · raw message
tools/libxc/xc_sr_save.c +27 -27
85 lines not on this page · raw message
tools/libxl/libxl_dom_save.c +0 -11
@@ -338,8 +338,6 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss)/* Convenience aliases */ const uint32_t domid = dss->domid;const libxl_domain_type type = dss->type; -const int live = dss->live; -const int debug = dss->debug;const libxl_domain_remus_info *const r_info = dss->remus;libxl__srm_save_autogen_callbacks *const callbacks = &dss->sws.shs.callbacks.save.a;
@@ -374,10 +372,6 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss)abort (); } - dss->xcflags = (live ?XCFLAGS_LIVE :0 ) - | (debug ?XCFLAGS_DEBUG :0 ) - | (dss->hvm ?XCFLAGS_HVM :0 ); -/* Disallow saving a guest with vNUMA configured because migration * stream does not preserve node information. *
@@ -393,11 +387,6 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss) goto out; } -if (dss->checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_REMUS ) { -if (libxl_defbool_val (r_info->compression)) - dss->xcflags |=XCFLAGS_CHECKPOINT_COMPRESS ; - } -if (dss->checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_NONE ) callbacks->suspend = libxl__domain_suspend_callback;
tools/libxl/libxl_internal.h +0 -1
@@ -3306,7 +3306,6 @@ struct libxl__domain_save_state {/* private */ int rc;int hvm; -int xcflags;libxl__domain_suspend_state dsps;union {/* for Remus */
tools/libxl/libxl_save_callout.c +6 -6
@@ -59,10 +59,11 @@ void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs,const unsigned long argnums[] = { domid, state->store_port, - state->store_domid, state->console_port, + state->store_domid, + state->console_port, state->console_domid, - hvm, pae, superpages, - cbflags, dcs->restore_params.checkpointed_stream, + dcs->restore_params.checkpointed_stream, + cbflags }; shs->ao = ao;
@@ -76,7 +77,7 @@ void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs, shs->caller_state = dcs; shs->need_results =1 ; -run_helper (egc, shs,"--restore-domain" , restore_fd, send_back_fd,0 ,0 , +run_helper (egc, shs,"--restore-domain" , restore_fd, send_back_fd,NULL ,0 , argnums,ARRAY_SIZE (argnums)); }
@@ -89,8 +90,7 @@ void libxl__xc_domain_save(libxl__egc *egc, libxl__domain_save_state *dss,libxl__srm_callout_enumcallbacks_save (&shs->callbacks.save.a);const unsigned long argnums[] = { - dss->domid,0 ,0 , dss->xcflags, dss->hvm, - cbflags, dss->checkpointed_stream, + dss->domid,0 , dss->live, dss->debug, dss->checkpointed_stream, cbflags }; shs->ao = ao;
tools/libxl/libxl_save_helper.c +27 -34
90 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 8/23 libxc/migration: defer precopy policy to a callback
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
The precopy phase of the xc_domain_save() live migration algorithm has historically been implemented to run until either a) (almost) no pages are dirty or b) some fixed, hard-coded maximum number of precopy iterations has been exceeded. This policy and its implementation are less than ideal for a few reasons:
- the logic of the policy is intertwined with the control flow of the mechanism of the precopy stage
- it can't take into account facts external to the immediate migration context, such as interactive user input or the passage of wall-clock time
To permit users to implement arbitrary higher-level policies governing when the live migration precopy phase should end, and what should be done next:
- add a precopy_policy() callback to the xc_domain_save() user-supplied callbacks
- during the precopy phase of live migrations, consult this policy after each batch of pages transmitted and take the dictated action, which may be to a) abort the migration entirely, b) continue with the precopy, or c) proceed to the stop-and-copy phase.
For now a simple callback implementing the old policy is hard-coded in place (to be replaced in a subsequent patch).
--- tools/libxc/include/xenguest.h | 20 +++- tools/libxc/xc_sr_common.h | 12 ++- tools/libxc/xc_sr_save.c | 193 ++++++++++++++++++++++++++++----------- tools/libxl/libxl_save_callout.c | 2 +- tools/libxl/libxl_save_helper.c | 1 - 5 files changed, 170 insertions(+), 58 deletions(-)
tools/libxc/include/xenguest.h +19 -1
@@ -32,6 +32,14 @@*/ struct xenevtchn_handle ; +/* For save's precopy_policy(). */ +struct precopy_stats +{ +unsigned int iteration; +unsigned int total_written; +int dirty_count;/* -1 if unknown */ +}; +/* callbacks provided by xc_domain_save */ struct save_callbacks {/* Called after expiration of checkpoint interval,
@@ -39,6 +47,17 @@ struct save_callbacks {*/ int (*suspend)(void * data); +/* Called after every batch of page data sent during the precopy phase of a +* live migration to ask the caller what to do next based on the current +* state of the precopy migration. +*/ +#define XGS_POLICY_ABORT (-1)/* Abandon the migration entirely and +* tidy up. */ +#define XGS_POLICY_CONTINUE_PRECOPY 0/* Remain in the precopy phase. */ +#define XGS_POLICY_STOP_AND_COPY 1/* Immediately suspend and transmit the +* remaining dirty pages. */ +int (*precopy_policy)(struct precopy_stats stats,void *data); +/* Called after the guest's dirty pages have been * copied into an output buffer. * Callback function resumes the guest & the device model,
@@ -87,7 +106,6 @@ struct domain_save_params {uint32_t dom;/* the id of the domain */ int save_fd;/* the fd to save the domain to */ int recv_fd;/* the fd to receive live protocol responses */ -uint32_t max_iters;/* how many precopy iterations before we give up? */ bool live;/* is this a live migration? */ bool debug;/* are we in debug mode? */ xc_migration_stream_t stream_type;/* is there checkpointing involved? */
tools/libxc/xc_sr_common.h +8 -4
@@ -198,12 +198,16 @@ struct xc_sr_context/* Further debugging information in the stream. */ bool debug; -/* Parameters for tweaking live migration. */ -unsigned max_iterations; -unsigned dirty_threshold; -unsigned long p2m_size; +enum { +XC_SAVE_PHASE_PRECOPY , +XC_SAVE_PHASE_STOP_AND_COPY + } phase; + +struct precopy_stats stats; +int policy_decision; +xen_pfn_t *batch_pfns;unsigned nr_batch_pfns;unsigned long *deferred_pages;
tools/libxc/xc_sr_save.c +142 -51
313 lines not on this page · raw message
tools/libxl/libxl_save_callout.c +1 -1
@@ -90,7 +90,7 @@ void libxl__xc_domain_save(libxl__egc *egc, libxl__domain_save_state *dss,libxl__srm_callout_enumcallbacks_save (&shs->callbacks.save.a);const unsigned long argnums[] = { - dss->domid,0 , dss->live, dss->debug, dss->checkpointed_stream, cbflags + dss->domid, dss->live, dss->debug, dss->checkpointed_stream, cbflags }; shs->ao = ao;
tools/libxl/libxl_save_helper.c +0 -1
@@ -251,7 +251,6 @@ int main(int argc, char **argv) params.save_fd = io_fd =atoi (NEXTARG ); params.recv_fd =atoi (NEXTARG ); params.dom =strtoul (NEXTARG ,0 ,10 ); - params.max_iters =strtoul (NEXTARG ,0 ,10 ); params.live =strtoul (NEXTARG ,0 ,10 ); params.debug =strtoul (NEXTARG ,0 ,10 ); params.stream_type =strtoul (NEXTARG ,0 ,10 );
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 9/23 libxl/migration: wire up the precopy policy RPC callback
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
Permit libxl to implement the xc_domain_save() precopy_policy callback by adding it to the RPC generation machinery and implementing a policy in libxl with the same semantics as the old one.
No functional change.
--- tools/libxc/xc_sr_save.c | 17 +---------------- tools/libxl/libxl_dom_save.c | 23 +++++++++++++++++++++++ tools/libxl/libxl_save_msgs_gen.pl | 4 +++- 3 files changed, 27 insertions(+), 17 deletions(-)
tools/libxc/xc_sr_save.c +1 -16
@@ -1001,17 +1001,6 @@ static int save(struct xc_sr_context *ctx, uint16_t guest_type)return rc; }; -static int simple_precopy_policy (struct precopy_stats stats,void *user) -{ -if (stats.dirty_count >=0 && stats.dirty_count <50 ) -return XGS_POLICY_STOP_AND_COPY ; - -if (stats.iteration >=5 ) -return XGS_POLICY_STOP_AND_COPY ; - -return XGS_POLICY_CONTINUE_PRECOPY ; -} -int xc_domain_save (xc_interface *xch,const struct domain_save_params *params,const struct save_callbacks * callbacks) {
@@ -1021,12 +1010,8 @@ int xc_domain_save(xc_interface *xch, const struct domain_save_params *params, .fd = params->save_fd, }; -/* XXX use this to shim our precopy_policy in before moving it to libxl */ -struct save_callbacks overridden_callbacks = *callbacks; - overridden_callbacks.precopy_policy = simple_precopy_policy; -/* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions. */ - ctx.save.callbacks = &overridden_callbacks; + ctx.save.callbacks = callbacks; ctx.save.live = params->live; ctx.save.debug = params->debug; ctx.save.checkpointed = params->stream_type;
tools/libxl/libxl_dom_save.c +23 -0
@@ -328,6 +328,28 @@ int libxl__save_emulator_xenstore_data(libxl__domain_save_state *dss,return rc; } +/* +* This is the live migration precopy policy - it's called periodically during +* the precopy phase of live migrations, and is responsible for deciding when +* the precopy phase should terminate and what should be done next. +* +* The policy implemented here behaves identically to the policy previously +* hard-coded into xc_domain_save() - it proceeds to the stop-and-copy phase of +* the live migration when there are either fewer than 50 dirty pages, or more +* than 5 precopy rounds have completed. +*/ +static int libxl__save_live_migration_precopy_policy ( +struct precopy_stats stats,void *user) +{ +if (stats.dirty_count >=0 && stats.dirty_count <50 ) +return XGS_POLICY_STOP_AND_COPY ; + +if (stats.iteration >=5 ) +return XGS_POLICY_STOP_AND_COPY ; + +return XGS_POLICY_CONTINUE_PRECOPY ; +} +/*----- main code for saving, in order of execution -----*/ void libxl__domain_save (libxl__egc *egc,libxl__domain_save_state *dss)
@@ -390,6 +412,7 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss)if (dss->checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_NONE ) callbacks->suspend = libxl__domain_suspend_callback; + callbacks->precopy_policy = libxl__save_live_migration_precopy_policy; callbacks->switch_qemu_logdirty = libxl__domain_suspend_common_switch_qemu_logdirty; dss->sws.ao = dss->ao;
tools/libxl/libxl_save_msgs_gen.pl +3 -1
@@ -33,6 +33,7 @@ our @msgs = ( 'xen_pfn_t', 'console_gfn'] ], [ 9, 'srW', "complete", [qw(int retval int errnoval)] ], + [ 10, 'scxW', "precopy_policy", ['struct precopy_stats', 'stats'] ] ); #----------------------------------------
@@ -141,7 +142,8 @@ static void bytes_put(unsigned char *const buf, int *len, END -foreach my $simpletype (qw(int uint16_t uint32_t unsigned), 'unsigned long', 'xen_pfn_t') { +foreach my $simpletype (qw(int uint16_t uint32_t unsigned), + 'unsigned long', 'xen_pfn_t', 'struct precopy_stats') { my $typeid = typeid($simpletype); $out_body{'callout'} .= <<END; static int ${typeid}_get(const unsigned char **msg,
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 10/23 libxc/xc_sr_save: introduce save batch types
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
To write guest pages into the stream, the save logic builds up batches of pfns to be written and performs all of the work necessary to write them whenever a full batch has been accumulated. Writing a PAGE_DATA batch entails determining the types of all pfns in the batch, mapping the subset of pfns that are backed by real memory constructing a PAGE_DATA record describing the batch and writing everything into the stream.
Postcopy live migration introduces several new types of batches. To enable the postcopy logic to re-use the bulk of the code used to manage and write PAGE_DATA records, introduce a batch_type member to the save context (which for now can take on only a single value), and refactor write_batch() to take the batch_type into account when preparing and writing each record.
While refactoring write_batch(), factor the operation of querying the page types of a batch into a subroutine that is useable independently of write_batch().
No functional change.
--- tools/libxc/xc_sr_common.h | 3 + tools/libxc/xc_sr_save.c | 207 +++++++++++++++++++++++++++--------------- tools/libxc/xg_save_restore.h | 2 +- 3 files changed, 140 insertions(+), 72 deletions(-)
tools/libxc/xc_sr_common.h +3 -0
@@ -208,6 +208,9 @@ struct xc_sr_contextstruct precopy_stats stats;int policy_decision; +enum { +XC_SR_SAVE_BATCH_PRECOPY_PAGE + } batch_type;xen_pfn_t *batch_pfns;unsigned nr_batch_pfns;unsigned long *deferred_pages;
tools/libxc/xc_sr_save.c +136 -71
318 lines not on this page · raw message
tools/libxc/xg_save_restore.h +1 -1
@@ -24,7 +24,7 @@** We process save/restore/migrate in batches of pages; the below ** determines how many pages we (at maximum) deal with in each batch. */ -#define MAX_BATCH_SIZE 1024/* up to 1024 pages (4MB) at a time */ +#define MAX_PRECOPY_BATCH_SIZE 1024/* up to 1024 pages (4MB) at a time */ /* When pinning page tables at the end of restore, we also use batching. */ #define MAX_PIN_BATCH 1024
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 11/23 libxc/migration: correct hvm record ordering specification
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
The libxc migration stream specification document asserts that, within an hvm migration stream, "HVM_PARAMS must precede HVM_CONTEXT, as certain parameters can affect the validity of architectural state in the context." This sounds reasonable, but the in-tree implementation of hvm domain save actually writes these records in the _reverse_ order, with HVM_CONTEXT first and HVM_PARAMS next. This has been the case for the entire history of that implementation, seemingly to no ill effect, so update the spec to reflect this.
--- docs/specs/libxc-migration-stream.pandoc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
docs/specs/libxc-migration-stream.pandoc +2 -5
@@ -673,11 +673,8 @@ A typical save record for an x86 HVM guest image would look like: 2. Domain header 3. Many PAGE\_DATA records 4. TSC\_INFO -5. HVM\_PARAMS -6. HVM\_CONTEXT - -HVM\_PARAMS must precede HVM\_CONTEXT, as certain parameters can affect -the validity of architectural state in the context. +5. HVM\_CONTEXT +6. HVM\_PARAMS Legacy Images (x86 only)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 12/23 libxc/migration: specify postcopy live migration
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
- allocate the new postcopy record type numbers
- augment the stream format specification to include these new types and their role in the protocol
--- docs/specs/libxc-migration-stream.pandoc | 175 +++++++++++++++++++++++++++++++ tools/libxc/xc_sr_common.c | 7 ++ tools/libxc/xc_sr_stream_format.h | 9 +- 3 files changed, 190 insertions(+), 1 deletion(-)
docs/specs/libxc-migration-stream.pandoc +175 -0
@@ -3,6 +3,7 @@ Andrew Cooper <<[email protected]>> Wen Congyang <<[email protected]>> Yang Hongyang <<[email protected]>> + Joshua Otto <<[email protected]>> % Revision 2 Introduction
@@ -231,6 +232,20 @@ type 0x00000000: END 0x0000000F: CHECKPOINT_DIRTY_PFN_LIST (Secondary -> Primary) + 0x00000010: POSTCOPY_BEGIN + + 0x00000011: POSTCOPY_PFNS_BEGIN + + 0x00000012: POSTCOPY_PFNS + + 0x00000013: POSTCOPY_TRANSITION + + 0x00000014: POSTCOPY_PAGE_DATA + + 0x00000015: POSTCOPY_FAULT + + 0x00000016: POSTCOPY_COMPLETE + 0x00000010 - 0x7FFFFFFF: Reserved for future _mandatory_ records.
@@ -624,6 +639,142 @@ The count of pfns is: record->length/sizeof(uint64_t). \clearpage +POSTCOPY_BEGIN +-------------- + +This record must only appear in a truly _live_ migration stream, and is +transmitted by the migration sender to signal to the destination that +the migration will (as soon as possible) transition from the memory +pre-copy phase to the post-copy phase, during which remaining unmigrated +domain memory is paged over the network on-demand _after_ the guest has +resumed. + +This record _must_ be followed immediately by the domain CPU context +records (e.g. TSC_INFO, HVM_CONTEXT and HVM_PARAMS for HVM domains). +This is for practical reasons: in the HVM case, the PAGING_RING_PFN +parameter must be known at the destination before preparation for paging +can begin. + +This record contains no fields; its body_length is 0. + +\clearpage + +POSTCOPY_PFNS_BEGIN +------------------- + +During the initiation sequence of a postcopy live migration, this record +immediately follows the final domain CPU context record and indicates +the beginning of a sequence of 0 or more POSTCOPY_PFNS records. The +destination uses this record as a cue to prepare for postcopy paging. + +This record contains no fields; its body_length is 0. + +\clearpage + +POSTCOPY_PFNS +------------- + +Each POSTCOPY_PFNS record contains an unordered list of 'postcopy PFNS' +- i.e. pfns that are dirty at the sender and require migration during +the postcopy phase. The structure of the record is identical that of +the PAGE_DATA record type, but omitting any actual trailing page +contents. + + 0 1 2 3 4 5 6 7 octet + +-----------------------+-------------------------+ + | count (C) | (reserved) | + +-----------------------+-------------------------+ + | pfn[0] | + +-------------------------------------------------+ + ... + +-------------------------------------------------+ + | pfn[C-1] | + +-------------------------------------------------+ + +\clearpage + +POSTCOPY_TRANSITION +------------------- + +This record is transmitted by a postcopy live migration sender after the +final POSTCOPY_PFNS record, and indicates that the embedded libxc stream +will be interrupted by content in the higher-layer stream necessary to +permit resumption of the domain at the destination, and further than +when the higher-layer content is complete the domain should be resumed +in postcopy mode at the destination. + +This record contains no fields; its body_length is 0. + +\clearpage + +POSTCOPY_PAGE_DATA +------------------ + +This record is identical in meaning and format to the PAGE_DATA record +type, and is transmitted during live migration by the sender during the +postcopy phase to transfer batches of outstanding domain memory. + + 0 1 2 3 4 5 6 7 octet + +-----------------------+-------------------------+ + | count (C) | (reserved) | + +-----------------------+-------------------------+ + | pfn[0] | + +-------------------------------------------------+ + ... + +-------------------------------------------------+ + | pfn[C-1] | + +-------------------------------------------------+ + | page_data[0]... | + ... + +-------------------------------------------------+ + | page_data[C-1]... | + ... + +-------------------------------------------------+ + +It is an error for an XTAB, BROKEN or XALLOC pfn to be transmitted in a +record of this type, so all pfns must be accompanied by backing data. +It is an error for a pfn not previously included in a POSTCOPY_PFNS +record to be included in a record of this type. + +\clearpage + +POSTCOPY_FAULT +-------------- + +A POSTCOPY_FAULT record is transmitted by a postcopy live migration +_destination_ to communicate an urgent need for a batch of pfns. It is +identical in format to the POSTCOPY_PFNS record type, _except_ that the +type of each page is not encoded in the transmitted pfns. + + 0 1 2 3 4 5 6 7 octet + +-----------------------+-------------------------+ + | count (C) | (reserved) | + +-----------------------+-------------------------+ + | pfn[0] | + +-------------------------------------------------+ + ... + +-------------------------------------------------+ + | pfn[C-1] | + +-------------------------------------------------+ + +\clearpage + +POSTCOPY_COMPLETE +----------------- + +A postcopy live migration _destination_ transmits a POSTCOPY_COMPLETE +record when the postcopy phase of a migration is complete, if one was +entered. + +This record contains no fields; its body_length is 0. + +In addition to reporting the phase completion to the sender, this record +also enables the migration sender to flush its receive stream of +in-flight POSTCOPY_FAULT records before handing control of the stream +back to a higher layer. + +\clearpage + Layout ======
@@ -676,6 +827,30 @@ A typical save record for an x86 HVM guest image would look like: 5. HVM\_CONTEXT 6. HVM\_PARAMS +x86 HVM Postcopy Live Migration +------------------------------- + +The bi-directional migration stream for postcopy live migration of an +x86 HVM guest image would look like: + + 1. Image header + 2. Domain header + 3. Many (or few!) PAGE\_DATA records + 4. POSTCOPY\_BEGIN + 5. TSC\_INFO + 6. HVM\_CONTEXT + 7. HVM\_PARAMS + 8. POSTCOPY\_PFNS\_BEGIN + 9. Many POSTCOPY\_PFNS records +10. POSTCOPY\_TRANSITION +... higher layer stream content ... +11. Many POSTCOPY\_PAGE\_DATA records + +During 11, the destination would reply with (hopefully not too) many +POSTCOPY\_FAULT records. + +After 11, the destination would transmit a final POSTCOPY\_COMPLETE. + Legacy Images (x86 only) ========================
tools/libxc/xc_sr_common.c +7 -0
@@ -38,6 +38,13 @@ static const char *mandatory_rec_types[] = [REC_TYPE_VERIFY] = "Verify", [REC_TYPE_CHECKPOINT] = "Checkpoint", [REC_TYPE_CHECKPOINT_DIRTY_PFN_LIST] = "Checkpoint dirty pfn list", + [REC_TYPE_POSTCOPY_BEGIN] = "Postcopy begin", + [REC_TYPE_POSTCOPY_PFNS_BEGIN] = "Postcopy pfns begin", + [REC_TYPE_POSTCOPY_PFNS] = "Postcopy pfns", + [REC_TYPE_POSTCOPY_TRANSITION] = "Postcopy transition", + [REC_TYPE_POSTCOPY_PAGE_DATA] = "Postcopy page data", + [REC_TYPE_POSTCOPY_FAULT] = "Postcopy fault", + [REC_TYPE_POSTCOPY_COMPLETE] = "Postcopy complete", };const char *rec_type_to_str (uint32_t type)
tools/libxc/xc_sr_stream_format.h +8 -1
@@ -76,10 +76,17 @@ struct xc_sr_rhdr#define REC_TYPE_VERIFY 0x0000000dU#define REC_TYPE_CHECKPOINT 0x0000000eU#define REC_TYPE_CHECKPOINT_DIRTY_PFN_LIST 0x0000000fU +#define REC_TYPE_POSTCOPY_BEGIN 0x00000010U +#define REC_TYPE_POSTCOPY_PFNS_BEGIN 0x00000011U +#define REC_TYPE_POSTCOPY_PFNS 0x00000012U +#define REC_TYPE_POSTCOPY_TRANSITION 0x00000013U +#define REC_TYPE_POSTCOPY_PAGE_DATA 0x00000014U +#define REC_TYPE_POSTCOPY_FAULT 0x00000015U +#define REC_TYPE_POSTCOPY_COMPLETE 0x00000016U#define REC_TYPE_OPTIONAL 0x80000000U -/* PAGE_DATA */ +/* PAGE_DATA/POSTCOPY_PFNS/POSTCOPY_PAGE_DATA/POSTCOPY_FAULT */ struct xc_sr_rec_pages_header {uint32_t count;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 13/23 libxc/migration: add try_read_record()
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
Enable non-blocking migration record reads by adding a helper routine that manages the context of a record read across multiple invocations as the record's data becomes available over time.
--- tools/libxc/xc_private.c | 21 +++++++++++---- tools/libxc/xc_private.h | 2 ++ tools/libxc/xc_sr_common.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_common.h | 39 ++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 5 deletions(-)
tools/libxc/xc_private.c +16 -5
@@ -633,26 +633,37 @@ void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits) } } -int read_exact (int fd,void *data,size_t size) +int try_read_exact (int fd,void *data,size_t size,size_t *offset) { -size_t offset =0 ;ssize_t len; -while ( offset < size ) +assert (offset); + *offset =0 ; +while ( *offset < size ) { - len =read (fd, (char *)data + offset, size - offset); + len =read (fd, (char *)data + *offset, size - *offset);if ( (len ==-1 ) && (errno ==EINTR ) )continue ;if ( len ==0 ) errno =0 ;if ( len <=0 )return -1 ; - offset += len; + *offset += len; }return 0 ; } +int read_exact (int fd,void *data,size_t size) +{ +size_t offset; +int rc; + + rc =try_read_exact (fd, data, size, &offset); +assert (rc ==-1 || offset == size); +return rc; +} +int write_exact (int fd,const void *data,size_t size) {size_t offset =0 ;
tools/libxc/xc_private.h +2 -0
@@ -384,6 +384,8 @@ int xc_flush_mmu_updates(xc_interface *xch, struct xc_mmu *mmu);/* Return 0 on success; -1 on error setting errno. */ int read_exact (int fd,void *data,size_t size);/* EOF => -1, errno=0 */ +/* Like read_exact(), but stores the length read before error to *offset. */ +int try_read_exact (int fd,void *data,size_t size,size_t *offset);int write_exact (int fd,const void *data,size_t size);int writev_exact (int fd,const struct iovec *iov,int iovcnt);
tools/libxc/xc_sr_common.c +65 -0
71 lines not on this page · raw message
tools/libxc/xc_sr_common.h +39 -0
@@ -399,6 +399,45 @@ static inline int write_record(struct xc_sr_context *ctx, int fd,int read_record (struct xc_sr_context *ctx,int fd,struct xc_sr_record *rec);/* +* try_read_record() (prototype below) reads a record from a _non-blocking_ +* stream over the course of one or more invocations. Context for the record +* read is maintained in an xc_sr_read_record_context. +* +* The protocol is: +* - call read_record_init() on an uninitialized or previously-destroyed +* read-record context prior to using it to read a record +* - call try_read_record() with this initialized context one or more times +* - rc < 0 and errno == EAGAIN/EWOULDBLOCK => try again +* - rc < 0 otherwise => failure +* - rc == 0 => a complete record has been read, and is filled into +* try_read_record()'s rec argument +* - after either failure or completion of a record, destroy the context with +* read_record_destroy() +*/ +struct xc_sr_read_record_context +{ +struct xc_sr_context *ctx; +size_t offset; +struct xc_sr_rhdr rhdr; +void *data; +}; + +static inline void read_record_init (struct xc_sr_read_record_context *rrctx, +struct xc_sr_context *ctx) +{ + *rrctx = (struct xc_sr_read_record_context ) { .ctx = ctx }; +} + +int try_read_record (struct xc_sr_read_record_context *rrctx,int fd, +struct xc_sr_record *rec); + +static inline void read_record_destroy (struct xc_sr_read_record_context *rrctx) +{ +free (rrctx->data); + rrctx->data =NULL ; +} + +/* * Given a record of one of the page data types, validate it by: * - checking its actual type against its specific expected type * - sanity checking its actual length against its claimed length
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 14/23 libxc/migration: implement the sender side of postcopy live migration
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
Add a new 'postcopy' phase to the live migration algorithm, during which unmigrated domain memory is paged over the network on-demand _after_ the guest has been resumed at the destination.
To do so:
- Add a new precopy policy option, XGS_POLICY_POSTCOPY, that policies can use to request a transition to the postcopy live migration phase rather than a stop-and-copy of the remaining dirty pages.
- Add support to xc_domain_save() for this policy option by breaking out of the precopy loop early, transmitting the final set of dirty pfns and all remaining domain state (including higher-layer state) except memory, and entering a postcopy loop during which the remaining page data is pushed in the background. Remote requests for specific pages in response to faults in the domain are serviced with priority in this loop.
The new save callbacks required for this migration phase are stubbed in libxl for now, to be replaced in a subsequent patch that adds libxl support for this migration phase. Support for this phase on the migration receiver side follows immediately in the next patch.
--- tools/libxc/include/xenguest.h | 84 ++++--- tools/libxc/xc_sr_common.h | 8 +- tools/libxc/xc_sr_save.c | 488 ++++++++++++++++++++++++++++++++++--- tools/libxc/xc_sr_save_x86_hvm.c | 13 + tools/libxc/xg_save_restore.h | 16 +- tools/libxl/libxl_dom_save.c | 11 +- tools/libxl/libxl_save_msgs_gen.pl | 6 +- 7 files changed, 558 insertions(+), 68 deletions(-)
tools/libxc/include/xenguest.h +51 -33
@@ -56,41 +56,59 @@ struct save_callbacks {#define XGS_POLICY_CONTINUE_PRECOPY 0/* Remain in the precopy phase. */ #define XGS_POLICY_STOP_AND_COPY 1/* Immediately suspend and transmit the * remaining dirty pages. */ +#define XGS_POLICY_POSTCOPY 2/* Suspend the guest and transition into +* the postcopy phase of the migration. */ int (*precopy_policy)(struct precopy_stats stats,void *data); -/* Called after the guest's dirty pages have been -* copied into an output buffer. -* Callback function resumes the guest & the device model, -* returns to xc_domain_save. -* xc_domain_save then flushes the output buffer, while the -* guest continues to run. -*/ -int (*aftercopy)(void * data); - -/* Called after the memory checkpoint has been flushed -* out into the network. Typical actions performed in this -* callback include: -* (a) send the saved device model state (for HVM guests), -* (b) wait for checkpoint ack -* (c) release the network output buffer pertaining to the acked checkpoint. -* (c) sleep for the checkpoint interval. -* -* returns: -* 0: terminate checkpointing gracefully -* 1: take another checkpoint */ -int (*checkpoint)(void * data); - -/* -* Called after the checkpoint callback. -* -* returns: -* 0: terminate checkpointing gracefully -* 1: take another checkpoint -*/ -int (*wait_checkpoint)(void * data); - -/* Enable qemu-dm logging dirty pages to xen */ -int (*switch_qemu_logdirty)(int domid,unsigned enable,void *data);/* HVM only */ +/* Checkpointing and postcopy live migration are mutually exclusive. */ +union { +struct { +/* +* Called during a live migration's transition to the postcopy phase +* to yield control of the stream back to a higher layer so it can +* transmit records needed for resumption of the guest at the +* destination (e.g. device model state, xenstore context) +*/ +int (*postcopy_transition)(void *data); + }; + +struct { +/* Called after the guest's dirty pages have been +* copied into an output buffer. +* Callback function resumes the guest & the device model, +* returns to xc_domain_save. +* xc_domain_save then flushes the output buffer, while the +* guest continues to run. +*/ +int (*aftercopy)(void * data); + +/* Called after the memory checkpoint has been flushed +* out into the network. Typical actions performed in this +* callback include: +* (a) send the saved device model state (for HVM guests), +* (b) wait for checkpoint ack +* (c) release the network output buffer pertaining to the acked +* checkpoint. +* (c) sleep for the checkpoint interval. +* +* returns: +* 0: terminate checkpointing gracefully +* 1: take another checkpoint */ +int (*checkpoint)(void * data); + +/* +* Called after the checkpoint callback. +* +* returns: +* 0: terminate checkpointing gracefully +* 1: take another checkpoint +*/ +int (*wait_checkpoint)(void * data); + +/* Enable qemu-dm logging dirty pages to xen */ +int (*switch_qemu_logdirty)(int domid,unsigned enable,void *data);/* HVM only */ + }; + };/* to be provided as the last argument to each callback function */ void * data;
tools/libxc/xc_sr_common.h +6 -2
@@ -202,20 +202,24 @@ struct xc_sr_contextenum {XC_SAVE_PHASE_PRECOPY , -XC_SAVE_PHASE_STOP_AND_COPY +XC_SAVE_PHASE_STOP_AND_COPY , +XC_SAVE_PHASE_POSTCOPY } phase;struct precopy_stats stats;int policy_decision;enum { -XC_SR_SAVE_BATCH_PRECOPY_PAGE +XC_SR_SAVE_BATCH_PRECOPY_PAGE , +XC_SR_SAVE_BATCH_POSTCOPY_PFN , +XC_SR_SAVE_BATCH_POSTCOPY_PAGE } batch_type;xen_pfn_t *batch_pfns;unsigned nr_batch_pfns;unsigned long *deferred_pages;unsigned long nr_deferred_pages;xc_hypercall_buffer_t dirty_bitmap_hbuf; +unsigned long nr_final_dirty_pages; } save; struct /* Restore data. */
tools/libxc/xc_sr_save.c +459 -29
591 lines not on this page · raw message
tools/libxc/xc_sr_save_x86_hvm.c +13 -0
@@ -92,6 +92,9 @@ static int write_hvm_params(struct xc_sr_context *ctx)unsigned int i;int rc; + DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, + &ctx->save.dirty_bitmap_hbuf); +for ( i =0 ; i <ARRAY_SIZE (params); i++ ) {uint32_t index = params[i];
@@ -106,6 +109,16 @@ static int write_hvm_params(struct xc_sr_context *ctx)if ( value !=0 ) { +if ( ctx->save.live && + ctx->save.policy_decision ==XGS_POLICY_POSTCOPY && + ( index ==HVM_PARAM_CONSOLE_PFN || + index ==HVM_PARAM_STORE_PFN || + index ==HVM_PARAM_IOREQ_PFN || + index ==HVM_PARAM_BUFIOREQ_PFN || + index ==HVM_PARAM_PAGING_RING_PFN ) && +test_and_clear_bit (value, dirty_bitmap) ) + --ctx->save.nr_final_dirty_pages; + entries[hdr.count].index = index; entries[hdr.count].value = value; hdr.count++;
tools/libxc/xg_save_restore.h +15 -1
@@ -24,7 +24,21 @@** We process save/restore/migrate in batches of pages; the below ** determines how many pages we (at maximum) deal with in each batch. */ -#define MAX_PRECOPY_BATCH_SIZE 1024/* up to 1024 pages (4MB) at a time */ +#define MAX_PRECOPY_BATCH_SIZE ((size_t)1024U)/* up to 1024 pages (4MB) */ + +/* +** We process the migration postcopy transition in batches of pfns to ensure +** that we stay within the record size bound. Because these records contain +** only pfns (and _not_ their contents), we can accomodate many more of them +** in a batch. +*/ +#define MAX_PFN_BATCH_SIZE ((4U << 20) / sizeof(uint64_t))/* up to 512k pfns */ + +/* +** The postcopy background copy uses a smaller batch size to ensure it can +** quickly respond to remote faults. +*/ +#define MAX_POSTCOPY_BATCH_SIZE ((size_t)64U)/* When pinning page tables at the end of restore, we also use batching. */ #define MAX_PIN_BATCH 1024
tools/libxl/libxl_dom_save.c +10 -1
@@ -350,6 +350,12 @@ static int libxl__save_live_migration_precopy_policy(return XGS_POLICY_CONTINUE_PRECOPY ; } +static void libxl__save_live_migration_postcopy_transition_callback (void *user) +{ +/* XXX we're not yet ready to deal with this */ +assert (0 ); +} +/*----- main code for saving, in order of execution -----*/ void libxl__domain_save (libxl__egc *egc,libxl__domain_save_state *dss)
@@ -409,8 +415,11 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss) goto out; } -if (dss->checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_NONE ) +if (dss->checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_NONE ) { callbacks->suspend = libxl__domain_suspend_callback; + callbacks->postcopy_transition = + libxl__save_live_migration_postcopy_transition_callback; + } callbacks->precopy_policy = libxl__save_live_migration_precopy_policy; callbacks->switch_qemu_logdirty = libxl__domain_suspend_common_switch_qemu_logdirty;
tools/libxl/libxl_save_msgs_gen.pl +4 -2
@@ -33,7 +33,8 @@ our @msgs = ( 'xen_pfn_t', 'console_gfn'] ], [ 9, 'srW', "complete", [qw(int retval int errnoval)] ], - [ 10, 'scxW', "precopy_policy", ['struct precopy_stats', 'stats'] ] + [ 10, 'scxW', "precopy_policy", ['struct precopy_stats', 'stats'] ], + [ 11, 'scxA', "postcopy_transition", [] ] ); #----------------------------------------
@@ -225,6 +226,7 @@ foreach my $sr (qw(save restore)) { f_decl("${setcallbacks}_${sr}", 'helper', 'void', "(struct ${sr}_callbacks *cbs, unsigned cbflags)"); + f_more("${setcallbacks}_${sr}", " memset(cbs, 0, sizeof(*cbs));\n"); f_more("${receiveds}_${sr}", <<END_ALWAYS.($debug ? <<END_DEBUG : '').<<END_ALWAYS);
@@ -335,7 +337,7 @@ END_ALWAYS my $c_v = "(1u<<$msgnum)"; my $c_cb = "cbs->$name"; $f_more_sr->(" if ($c_cb) cbflags |= $c_v;\n", $enumcallbacks); - $f_more_sr->(" $c_cb = (cbflags & $c_v) ? ${encode}_${name} : 0;\n", + $f_more_sr->(" if (cbflags & $c_v) $c_cb = ${encode}_${name};\n", $setcallbacks); } $f_more_sr->(" return 1;\n }\n\n");
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 15/23 libxc/migration: implement the receiver side of postcopy live migration
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
Add the receive-side logic for a new 'postcopy' phase in the live migration algorithm.
To support this migration phase:
- Augment the main restore record-processing logic to recognize and handle the postcopy-initiation records.
- Add the core logic for the phase, postcopy_restore(), which marks as paged-out all pfns reported by the sender as outstanding at the beginning of the phase, and subsequently serves as a pager for this subset of memory by forwarding paging requests to the migration sender and filling the outstanding domain memory as it is received.
The new restore callbacks required for this migration phase are stubbed in libxl for now, to be replaced in a subsequent patch that adds libxl support for this migration phase.
--- tools/libxc/include/xenguest.h | 65 ++- tools/libxc/xc_sr_common.h | 90 +++- tools/libxc/xc_sr_restore.c | 957 ++++++++++++++++++++++++++++++++++-- tools/libxc/xc_sr_restore_x86_hvm.c | 41 +- tools/libxl/libxl_create.c | 17 + tools/libxl/libxl_save_msgs_gen.pl | 2 +- 6 files changed, 1113 insertions(+), 59 deletions(-)
tools/libxc/include/xenguest.h +41 -24
@@ -146,35 +146,52 @@ struct restore_callbacks {*/ int (*suspend)(void * data); -/* Called after the secondary vm is ready to resume. -* Callback function resumes the guest & the device model, -* returns to xc_domain_restore. -*/ -int (*aftercopy)(void * data); +union { +struct { +/* +* Called upon receipt of the POSTCOPY_TRANSITION record in the +* stream to yield control of the stream to the higher layer so that +* the remaining data needed to resume the domain in the postcopy +* phase can be obtained. Returns as soon as the higher layer is +* finished with the stream. +* +* Returns 1 on success, 0 on failure. +*/ +int (*postcopy_transition)(void *data); + }; -/* A checkpoint record has been found in the stream. -* returns: */ +struct { +/* Called after the secondary vm is ready to resume. +* Callback function resumes the guest & the device model, +* returns to xc_domain_restore. +*/ +int (*aftercopy)(void * data); + +/* A checkpoint record has been found in the stream. +* returns: */ #define XGR_CHECKPOINT_ERROR 0/* Terminate processing */ #define XGR_CHECKPOINT_SUCCESS 1/* Continue reading more data from the stream */ #define XGR_CHECKPOINT_FAILOVER 2/* Failover and resume VM */ -int (*checkpoint)(void * data); - -/* -* Called after the checkpoint callback. -* -* returns: -* 0: terminate checkpointing gracefully -* 1: take another checkpoint -*/ -int (*wait_checkpoint)(void * data); +int (*checkpoint)(void * data); -/* -* callback to send store gfn and console gfn to xl -* if we want to resume vm before xc_domain_save() -* exits. -*/ -void (*restore_results)(xen_pfn_t store_gfn,xen_pfn_t console_gfn, -void *data); +/* +* Called after the checkpoint callback. +* +* returns: +* 0: terminate checkpointing gracefully +* 1: take another checkpoint +*/ +int (*wait_checkpoint)(void * data); + +/* +* callback to send store gfn and console gfn to xl +* if we want to resume vm before xc_domain_save() +* exits. +*/ +void (*restore_results)(xen_pfn_t store_gfn,xen_pfn_t console_gfn, +void *data); + }; + };/* to be provided as the last argument to each callback function */ void * data;
tools/libxc/xc_sr_common.h +89 -1
108 lines not on this page · raw message
tools/libxc/xc_sr_restore.c +927 -30
1,025 lines not on this page · raw message
tools/libxc/xc_sr_restore_x86_hvm.c +38 -3
62 lines not on this page · raw message
tools/libxl/libxl_create.c +17 -0
@@ -748,6 +748,8 @@ static void domcreate_bootloader_done(libxl__egc *egc,libxl__bootloader_state *bl, int rc); +static void domcreate_postcopy_transition_callback (void *user); +static void domcreate_launch_dm (libxl__egc *egc,libxl__multidev *aodevs,int ret);
@@ -1102,6 +1104,13 @@ static void domcreate_bootloader_done(libxl__egc *egc,libxl__remus_restore_setup (egc, dcs);/* fall through */ case LIBXL_CHECKPOINTED_STREAM_NONE : +/* +* When the restore helper initiates the postcopy transition, pick +* up in domcreate_postcopy_transition_callback() +*/ + callbacks->postcopy_transition = + domcreate_postcopy_transition_callback; +libxl__stream_read_start (egc, &dcs->srs); }return ;
@@ -1111,6 +1120,14 @@ static void domcreate_bootloader_done(libxl__egc *egc,domcreate_stream_done (egc, &dcs->srs, rc); } +/* ----- postcopy live migration ----- */ + +static void domcreate_postcopy_transition_callback (void *user) +{ +/* XXX we're not ready to deal with this yet */ +assert (0 ); +} +void libxl__srm_callout_callback_restore_results (xen_pfn_t store_mfn,xen_pfn_t console_mfn,void *user) {
tools/libxl/libxl_save_msgs_gen.pl +1 -1
@@ -34,7 +34,7 @@ our @msgs = ( [ 9, 'srW', "complete", [qw(int retval int errnoval)] ], [ 10, 'scxW', "precopy_policy", ['struct precopy_stats', 'stats'] ], - [ 11, 'scxA', "postcopy_transition", [] ] + [ 11, 'srcxA', "postcopy_transition", [] ] ); #----------------------------------------
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 16/23 libxl/libxl_stream_write.c: track callback chains with an explicit phase
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
There are three callback chains through libxl_stream_write: the 'normal' straight-through save path initiated by libxl__stream_write_start(), the iterated checkpoint path initiated each time by libxl__stream_write_start_checkpoint(), and the (short) back-channel checkpoint path initiated by libxl__stream_write_checkpoint_state(). These paths share significant common code but handle failure and completion slightly differently, so it is necessary to keep track of the callback chain currently in progress and act accordingly at various points.
Until now, a collection of booleans in the stream write state has been used to indicate the current callback chain. However, the set of callback chains is really better described by an enum, since only one callback chain can actually be active at one time. In anticipation of the addition of a new chain for postcopy live migration, refactor the existing logic to use an enum rather than booleans for callback chain tracking.
No functional change.
--- tools/libxl/libxl_internal.h | 7 ++- tools/libxl/libxl_stream_write.c | 96 ++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 55 deletions(-)
tools/libxl/libxl_internal.h +5 -2
@@ -3211,9 +3211,12 @@ struct libxl__stream_write_state {/* Private */ int rc;bool running; -bool in_checkpoint; +enum { +SWS_PHASE_NORMAL , +SWS_PHASE_CHECKPOINT , +SWS_PHASE_CHECKPOINT_STATE + } phase;bool sync_teardown;/* Only used to coordinate shutdown on error path. */ -bool in_checkpoint_state;libxl__save_helper_state shs;/* Main stream-writing data. */
tools/libxl/libxl_stream_write.c +43 -53
181 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 17/23 libxl/libxl_stream_read.c: track callback chains with an explicit phase
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
As the previous patch did for libxl_stream_write, do for libxl_stream_read. libxl_stream_read already has a notion of phase for its record-buffering behaviour - this is combined with the callback chain phase. Again, this is done to support the addition of a new callback chain for postcopy live migration.
No functional change.
--- tools/libxl/libxl_internal.h | 7 ++-- tools/libxl/libxl_stream_read.c | 83 +++++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 45 deletions(-)
tools/libxl/libxl_internal.h +3 -4
@@ -3133,9 +3133,7 @@ struct libxl__stream_read_state {/* Private */ int rc;bool running; -bool in_checkpoint;bool sync_teardown;/* Only used to coordinate shutdown on error path. */ -bool in_checkpoint_state;libxl__save_helper_state shs;libxl__conversion_helper_state chs;
@@ -3145,8 +3143,9 @@ struct libxl__stream_read_state { LIBXL_STAILQ_HEAD(, libxl__sr_record_buf) record_queue; /* NOGC */enum {SRS_PHASE_NORMAL , -SRS_PHASE_BUFFERING , -SRS_PHASE_UNBUFFERING , +SRS_PHASE_CHECKPOINT_BUFFERING , +SRS_PHASE_CHECKPOINT_UNBUFFERING , +SRS_PHASE_CHECKPOINT_STATE } phase;bool recursion_guard;
tools/libxl/libxl_stream_read.c +42 -41
217 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 18/23 libxl/migration: implement the sender side of postcopy live migration
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
To make the libxl sender capable of supporting postcopy live migration:
- Add a postcopy transition callback chain through the stream writer (this callback chain is nearly identical to the checkpoint callback chain, and differs meaningfully only in its failure/completion behaviour)
- Wire this callback chain up to the xc postcopy callback entries in the domain save logic.
- Introduce a new libxl API function, libxl_domain_live_migrate(), taking the same parameters as libxl_domain_suspend() as well as a recv_fd to enable bi-directional communication between the sender and receiver and a boolean out-parameter to enable the caller to reason about the safety of recovery from a postcopy failure. (the live_migrate() and domain_suspend() parameter lists will likely only continue to diverge over time, so it makes good sense to split them now)
No mechanism is introduced yet to enable library clients to induce a postcopy live migration - this will follow after the libxl postcopy receiver logic.
--- docs/specs/libxl-migration-stream.pandoc | 19 ++++++++- tools/libxl/libxl.h | 7 ++++ tools/libxl/libxl_dom_save.c | 25 +++++++++++- tools/libxl/libxl_domain.c | 29 +++++++++++++- tools/libxl/libxl_internal.h | 21 ++++++++-- tools/libxl/libxl_sr_stream_format.h | 13 +++--- tools/libxl/libxl_stream_write.c | 69 ++++++++++++++++++++++++++++++-- tools/xl/xl_migrate.c | 6 ++- 8 files changed, 169 insertions(+), 20 deletions(-)
docs/specs/libxl-migration-stream.pandoc +17 -2
@@ -2,7 +2,8 @@ % Andrew Cooper <<[email protected]>> Wen Congyang <<[email protected]>> Yang Hongyang <<[email protected]>> -% Revision 2 + Joshua Otto <<[email protected]>> +% Revision 3 Introduction ============
@@ -123,7 +124,9 @@ type 0x00000000: END 0x00000005: CHECKPOINT_STATE - 0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_ + 0x00000006: POSTCOPY_TRANSITION_END + + 0x00000007 - 0x7FFFFFFF: Reserved for future _mandatory_ records. 0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -304,6 +307,18 @@ While Secondary is running in below loop: b. Send _CHECKPOINT\_SVM\_SUSPENDED_ to primary 4. Checkpoint +POSTCOPY\_TRANSITION\_END +------------------------- + +A postcopy transition end record marks the end of a postcopy transition in a +libxl live migration stream. It indicates that control of the stream should be +returned to libxc for the postcopy memory migration phase. + + 0 1 2 3 4 5 6 7 octet + +-------------------------------------------------+ + +The postcopy transition end record contains no fields; its body_length is 0. + Future Extensions =================
tools/libxl/libxl.h +7 -0
@@ -1387,6 +1387,13 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd,#define LIBXL_SUSPEND_DEBUG 1#define LIBXL_SUSPEND_LIVE 2 +int libxl_domain_live_migrate(libxl_ctx *ctx, uint32_t domid, int send_fd, + int flags, /* LIBXL_SUSPEND_* */ + int recv_fd, + bool *postcopy_transitioned, /* OUT */ + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +/* @param suspend_cancel [from xenctrl.h:xc_domain_resume( @param fast )] * If this parameter is true, use co-operative resume. The guest * must support this.
tools/libxl/libxl_dom_save.c +23 -2
@@ -350,10 +350,31 @@ static int libxl__save_live_migration_precopy_policy(return XGS_POLICY_CONTINUE_PRECOPY ; } +static void postcopy_transition_done (libxl__egc *egc, +libxl__stream_write_state *sws,int rc); +static void libxl__save_live_migration_postcopy_transition_callback (void *user) { -/* XXX we're not yet ready to deal with this */ -assert (0 ); +libxl__save_helper_state *shs = user; +libxl__stream_write_state *sws =CONTAINER_OF (shs, *sws, shs); + sws->postcopy_transition_callback = postcopy_transition_done; +libxl__stream_write_start_postcopy_transition (shs->egc, sws); +} + +static void postcopy_transition_done (libxl__egc *egc, +libxl__stream_write_state *sws, +int rc) +{ +libxl__domain_save_state *dss = sws->dss; + +/* Past here, it's _possible_ that the domain may execute at the +* destination, so - unless we're given positive confirmation by the +* destination that it failed to resume there - we must assume it has. */ +assert (dss->postcopy_transitioned); + *dss->postcopy_transitioned = !rc; + +/* Return control to libxc. */ +libxl__xc_domain_saverestore_async_callback_done (egc, &sws->shs, !rc); }/*----- main code for saving, in order of execution -----*/
tools/libxl/libxl_domain.c +27 -2
@@ -486,8 +486,9 @@ static void domain_suspend_cb(libxl__egc *egc, } -int libxl_domain_suspend (libxl_ctx *ctx,uint32_t domid,int fd,int flags, -const libxl_asyncop_how *ao_how) +static int do_domain_suspend (libxl_ctx *ctx,uint32_t domid,int fd,int flags, +int recv_fd,bool *postcopy_transitioned, +const libxl_asyncop_how *ao_how) {AO_CREATE (ctx, domid, ao_how);int rc;
@@ -506,6 +507,8 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags, dss->domid = domid; dss->fd = fd; + dss->recv_fd = recv_fd; + dss->postcopy_transitioned = postcopy_transitioned; dss->type = type; dss->live = flags &LIBXL_SUSPEND_LIVE ; dss->debug = flags &LIBXL_SUSPEND_DEBUG ;
@@ -523,6 +526,28 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags,return AO_CREATE_FAIL (rc); } +int libxl_domain_suspend (libxl_ctx *ctx,uint32_t domid,int fd,int flags, +const libxl_asyncop_how *ao_how) +{ +return do_domain_suspend (ctx, domid, fd, flags,-1 ,NULL , ao_how); +} + +int libxl_domain_live_migrate (libxl_ctx *ctx,uint32_t domid,int send_fd, +int flags,int recv_fd, +bool *postcopy_transitioned, +const libxl_asyncop_how *ao_how) +{ +if (!postcopy_transitioned) { + errno =EINVAL ; +return -1 ; + } + + flags |=LIBXL_SUSPEND_LIVE ; + +return do_domain_suspend (ctx, domid, send_fd, flags, recv_fd, + postcopy_transitioned, ao_how); +} +int libxl_domain_pause (libxl_ctx *ctx,uint32_t domid) {int ret;
tools/libxl/libxl_internal.h +17 -4
@@ -3204,17 +3204,25 @@ struct libxl__stream_write_state {void (*completion_callback)(libxl__egc *egc,libxl__stream_write_state *sws,int rc); -void (*checkpoint_callback)(libxl__egc *egc, -libxl__stream_write_state *sws, -int rc); +/* Checkpointing and postcopy live migration are mutually exclusive. */ +union { +void (*checkpoint_callback)(libxl__egc *egc, +libxl__stream_write_state *sws, +int rc); +void (*postcopy_transition_callback)(libxl__egc *egc, +libxl__stream_write_state *sws, +int rc); + };/* Private */ int rc;bool running;enum {SWS_PHASE_NORMAL ,SWS_PHASE_CHECKPOINT , -SWS_PHASE_CHECKPOINT_STATE +SWS_PHASE_CHECKPOINT_STATE , +SWS_PHASE_POSTCOPY_TRANSITION } phase; +bool postcopy_transitioned;bool sync_teardown;/* Only used to coordinate shutdown on error path. */ libxl__save_helper_state shs;
@@ -3237,6 +3245,10 @@ _hidden void libxl__stream_write_init(libxl__stream_write_state *stream); _hidden void libxl__stream_write_start(libxl__egc *egc,libxl__stream_write_state *stream); _hidden void +libxl__stream_write_start_postcopy_transition ( +libxl__egc *egc, +libxl__stream_write_state *stream); +_hidden voidlibxl__stream_write_start_checkpoint (libxl__egc *egc,libxl__stream_write_state *stream);_hidden void
@@ -3300,6 +3312,7 @@ struct libxl__domain_save_state {int fd;int fdfl;/* original flags on fd */ int recv_fd; +bool *postcopy_transitioned;libxl_domain_type type;int live;int debug;
tools/libxl/libxl_sr_stream_format.h +7 -6
@@ -31,12 +31,13 @@ typedef struct libxl__sr_rec_hdr/* All records must be aligned up to an 8 octet boundary */ #define REC_ALIGN_ORDER 3U -#define REC_TYPE_END 0x00000000U -#define REC_TYPE_LIBXC_CONTEXT 0x00000001U -#define REC_TYPE_EMULATOR_XENSTORE_DATA 0x00000002U -#define REC_TYPE_EMULATOR_CONTEXT 0x00000003U -#define REC_TYPE_CHECKPOINT_END 0x00000004U -#define REC_TYPE_CHECKPOINT_STATE 0x00000005U +#define REC_TYPE_END 0x00000000U +#define REC_TYPE_LIBXC_CONTEXT 0x00000001U +#define REC_TYPE_EMULATOR_XENSTORE_DATA 0x00000002U +#define REC_TYPE_EMULATOR_CONTEXT 0x00000003U +#define REC_TYPE_CHECKPOINT_END 0x00000004U +#define REC_TYPE_CHECKPOINT_STATE 0x00000005U +#define REC_TYPE_POSTCOPY_TRANSITION_END 0x00000006U typedef struct libxl__sr_emulator_hdr {
tools/libxl/libxl_stream_write.c +66 -3
136 lines not on this page · raw message
tools/xl/xl_migrate.c +5 -1
@@ -186,6 +186,7 @@ static void migrate_domain(uint32_t domid, const char *rune, int debug,char rc_buf;uint8_t *config_data;int config_len, flags =LIBXL_SUSPEND_LIVE ; +bool postcopy_transitioned;save_domain_core_begin (domid, override_config_file, &config_data, &config_len);
@@ -205,7 +206,10 @@ static void migrate_domain(uint32_t domid, const char *rune, int debug,if (debug) flags |=LIBXL_SUSPEND_DEBUG ; - rc =libxl_domain_suspend (ctx, domid, send_fd, flags,NULL ); + rc =libxl_domain_live_migrate (ctx, domid, send_fd, flags, + recv_fd, &postcopy_transitioned,NULL ); +assert (!postcopy_transitioned); +if (rc) {fprintf (stderr,"migration sender: libxl_domain_suspend failed" " (rc=%d)\n" , rc);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 19/23 libxl/migration: implement the receiver side of postcopy live migration
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
To make the libxl receiver capable of supporting postcopy live migration:
- As was done for the libxl stream writer, add a symmetric callback chain through the stream reader that reads the sequence of xl records necessary to resume the guest and enter the postcopy phase. This chain is very similar to the checkpoint chain.
- Add a new postcopy path through the domain creation sequence that permits the xc memory postcopy phase to proceed in parallel to the libxl domain creation and resumption sequence.
- Add a out-parameter to libxl_domain_create_restore(), 'postcopy_resumed', that callers can test to determine whether or not further action is required on their-part post-migration to get the guest running.
A subsequent patch will introduce a mechanism by which library clients can _induce_ a postcopy live migration.
--- tools/libxl/libxl.h | 28 +++++- tools/libxl/libxl_create.c | 178 +++++++++++++++++++++++++++++++++-- tools/libxl/libxl_internal.h | 45 ++++++++- tools/libxl/libxl_stream_read.c | 57 +++++++++++ tools/ocaml/libs/xl/xenlight_stubs.c | 2 +- tools/xl/xl_vmcontrol.c | 2 +- 6 files changed, 297 insertions(+), 15 deletions(-)
tools/libxl/libxl.h +25 -3
@@ -1308,6 +1308,7 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,int libxl_domain_create_restore (libxl_ctx *ctx,libxl_domain_config *d_config,uint32_t *domid,int restore_fd,int send_back_fd, +bool *postcopy_resumed,/* OUT */ const libxl_domain_restore_params *params,const libxl_asyncop_how *ao_how,const libxl_asyncprogress_how *aop_console_how)
@@ -1327,8 +1328,9 @@ static inline int libxl_domain_create_restore_0x040200(libxl_domain_restore_params_init (¶ms); - ret =libxl_domain_create_restore ( - ctx, d_config, domid, restore_fd,-1 , ¶ms, ao_how, aop_console_how); + ret =libxl_domain_create_restore (ctx, d_config, domid, restore_fd, +-1 ,NULL , ¶ms, ao_how, + aop_console_how);libxl_domain_restore_params_dispose (¶ms);return ret;
@@ -1348,11 +1350,31 @@ static inline int libxl_domain_create_restore_0x040400( LIBXL_EXTERNAL_CALLERS_ONLY {return libxl_domain_create_restore (ctx, d_config, domid, restore_fd, --1 , params, ao_how, aop_console_how); +-1 ,NULL , params, ao_how, + aop_console_how); }#define libxl_domain_create_restore libxl_domain_create_restore_0x040400 +#elif defined(LIBXL_API_VERSION ) &&LIBXL_API_VERSION >=0x040700 \ + &&LIBXL_API_VERSION <0x040900 + +static inline int libxl_domain_create_restore_0x040700 ( +libxl_ctx *ctx,libxl_domain_config *d_config, +uint32_t *domid,int restore_fd, +int send_back_fd, +const libxl_domain_restore_params *params, +const libxl_asyncop_how *ao_how, +const libxl_asyncprogress_how *aop_console_how) +LIBXL_EXTERNAL_CALLERS_ONLY +{ +return libxl_domain_create_restore (ctx, d_config, domid, restore_fd, +-1 ,NULL , params, ao_how, + aop_console_how); +} + +#define libxl_domain_create_restore libxl_domain_create_restore_0x040700 +#endif int libxl_domain_soft_reset(libxl_ctx *ctx,
tools/libxl/libxl_create.c +171 -7
251 lines not on this page · raw message
tools/libxl/libxl_internal.h +42 -3
75 lines not on this page · raw message
tools/libxl/libxl_stream_read.c +57 -0
111 lines not on this page · raw message
tools/ocaml/libs/xl/xenlight_stubs.c +1 -1
@@ -538,7 +538,7 @@ value stub_libxl_domain_create_restore(value ctx, value domain_config, value parcaml_enter_blocking_section (); ret =libxl_domain_create_restore (CTX , &c_dconfig, &c_domid, restore_fd, --1 , &c_params, ao_how,NULL ); +-1 ,NULL , &c_params, ao_how,NULL );caml_leave_blocking_section ();free (ao_how);
tools/xl/xl_vmcontrol.c +1 -1
@@ -882,7 +882,7 @@ start: ret =libxl_domain_create_restore (ctx, &d_config, &domid, restore_fd, - send_back_fd, ¶ms, + send_back_fd,NULL , ¶ms,0 , autoconnect_console_how);libxl_domain_restore_params_dispose (¶ms);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 20/23 tools: expose postcopy live migration support in libxl and xl
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
- Add a 'memory_strategy' parameter to libxl_domain_live_migrate(), which specifies how the remainder of the memory migration should be approached after the iterative precopy phase is completed.
- Plug this parameter into the libxl migration precopy policy implementation.
- Add --postcopy to xl migrate, and skip the xl-level handshaking at both sides when postcopy migration occurs.
--- tools/libxl/libxl.h | 5 ++++ tools/libxl/libxl_dom_save.c | 17 ++++++++---- tools/libxl/libxl_domain.c | 8 ++++-- tools/libxl/libxl_internal.h | 1 + tools/xl/xl.h | 7 ++++- tools/xl/xl_cmdtable.c | 3 ++ tools/xl/xl_migrate.c | 65 ++++++++++++++++++++++++++++++++++++++++---- tools/xl/xl_vmcontrol.c | 8 ++++-- 8 files changed, 97 insertions(+), 17 deletions(-)
tools/libxl/libxl.h +5 -0
@@ -1413,9 +1413,14 @@ int libxl_domain_live_migrate(libxl_ctx *ctx, uint32_t domid, int send_fd,int flags,/* LIBXL_SUSPEND_* */ int recv_fd, bool *postcopy_transitioned, /* OUT */ + int memory_strategy, const libxl_asyncop_how *ao_how)LIBXL_EXTERNAL_CALLERS_ONLY ; +#define LIBXL_LM_MEMORY_STOP_AND_COPY 0 +#define LIBXL_LM_MEMORY_POSTCOPY 1 +#define LIBXL_LM_MEMORY_DEFAULT LIBXL_LM_MEMORY_STOP_AND_COPY +/* @param suspend_cancel [from xenctrl.h:xc_domain_resume( @param fast )] * If this parameter is true, use co-operative resume. The guest * must support this.
tools/libxl/libxl_dom_save.c +11 -6
@@ -338,14 +338,19 @@ int libxl__save_emulator_xenstore_data(libxl__domain_save_state *dss,* the live migration when there are either fewer than 50 dirty pages, or more * than 5 precopy rounds have completed. */ -static int libxl__save_live_migration_precopy_policy ( -struct precopy_stats stats,void *user) +static int libxl__save_live_migration_precopy_policy (struct precopy_stats stats, +void *user) { -if (stats.dirty_count >=0 && stats.dirty_count <50 ) -return XGS_POLICY_STOP_AND_COPY ; +libxl__save_helper_state *shs = user; +libxl__domain_save_state *dss = shs->caller_state; -if (stats.iteration >=5 ) -return XGS_POLICY_STOP_AND_COPY ; +if ((stats.dirty_count >=0 && + stats.dirty_count <=50 ) || + (stats.iteration >=5 )) { +return (dss->memory_strategy ==LIBXL_LM_MEMORY_POSTCOPY ) + ?XGS_POLICY_POSTCOPY + :XGS_POLICY_STOP_AND_COPY ; + }return XGS_POLICY_CONTINUE_PRECOPY ; }
tools/libxl/libxl_domain.c +6 -2
@@ -488,6 +488,7 @@ static void domain_suspend_cb(libxl__egc *egc,static int do_domain_suspend (libxl_ctx *ctx,uint32_t domid,int fd,int flags,int recv_fd,bool *postcopy_transitioned, +int memory_strategy,const libxl_asyncop_how *ao_how) {AO_CREATE (ctx, domid, ao_how);
@@ -509,6 +510,7 @@ static int do_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags, dss->fd = fd; dss->recv_fd = recv_fd; dss->postcopy_transitioned = postcopy_transitioned; + dss->memory_strategy = memory_strategy; dss->type = type; dss->live = flags &LIBXL_SUSPEND_LIVE ; dss->debug = flags &LIBXL_SUSPEND_DEBUG ;
@@ -529,12 +531,14 @@ static int do_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags,int libxl_domain_suspend (libxl_ctx *ctx,uint32_t domid,int fd,int flags,const libxl_asyncop_how *ao_how) { -return do_domain_suspend (ctx, domid, fd, flags,-1 ,NULL , ao_how); +return do_domain_suspend (ctx, domid, fd, flags,-1 ,NULL , +LIBXL_LM_MEMORY_DEFAULT , ao_how); }int libxl_domain_live_migrate (libxl_ctx *ctx,uint32_t domid,int send_fd,int flags,int recv_fd,bool *postcopy_transitioned, +int memory_strategy,const libxl_asyncop_how *ao_how) {if (!postcopy_transitioned) {
@@ -545,7 +549,7 @@ int libxl_domain_live_migrate(libxl_ctx *ctx, uint32_t domid, int send_fd, flags |=LIBXL_SUSPEND_LIVE ;return do_domain_suspend (ctx, domid, send_fd, flags, recv_fd, - postcopy_transitioned, ao_how); + postcopy_transitioned, memory_strategy, ao_how); }int libxl_domain_pause (libxl_ctx *ctx,uint32_t domid)
tools/libxl/libxl_internal.h +1 -0
@@ -3324,6 +3324,7 @@ struct libxl__domain_save_state {int fdfl;/* original flags on fd */ int recv_fd;bool *postcopy_transitioned; +int memory_strategy;libxl_domain_type type;int live;int debug;
tools/xl/xl.h +6 -1
@@ -48,6 +48,7 @@ struct domain_create {bool userspace_colo_proxy;int migrate_fd;/* -1 means none */ int send_back_fd;/* -1 means none */ +bool *postcopy_resumed;char **migration_domname_r;/* from malloc */ };
@@ -66,7 +67,6 @@ static const char migrate_permission_to_go[]="domain is yours, you are cleared to unpause" ;static const char migrate_report[]="my copy unpause results are as follows" ; -#endif /* followed by one byte: * 0: everything went well, domain is running
@@ -76,6 +76,11 @@ static const char migrate_report[]=* from target to source */ +static const char migrate_postcopy_sync[]= +"postcopy migration completed successfully" ; + +#endif +#define XL_MANDATORY_FLAG_JSON (1U << 0)/* config data is in JSON format */ #define XL_MANDATORY_FLAG_STREAMv2 (1U << 1)/* stream is v2 */ #define XL_MANDATORY_FLAG_ALL (XL_MANDATORY_FLAG_JSON | \
tools/xl/xl_cmdtable.c +3 -0
@@ -166,6 +166,9 @@ struct cmd_spec cmd_table[] = {" of the domain.\n" "--debug Print huge (!) amount of debug during the migration process.\n" "-p Do not unpause domain after migrating it." +"--postcopy At the end of the iterative precopy phase, transition to a\n" +" postcopy memory migration rather than performing a stop-and-copy\n" +" migration of the outstanding dirty pages.\n" }, { "restore", &main_restore, 0, 1,
tools/xl/xl_migrate.c +59 -6
130 lines not on this page · raw message
tools/xl/xl_vmcontrol.c +6 -2
@@ -655,6 +655,7 @@ int create_domain(struct domain_create *dom_info)const char *config_source =NULL ;const char *restore_source =NULL ;int migrate_fd = dom_info->migrate_fd; +bool *postcopy_resumed = dom_info->postcopy_resumed;bool config_in_json;int i;
@@ -675,6 +676,9 @@ int create_domain(struct domain_create *dom_info)int restoring = (restore_file || (migrate_fd >=0 )); +if (postcopy_resumed) + *postcopy_resumed = false; +libxl_domain_config_init (&d_config);if (restoring) {
@@ -882,8 +886,8 @@ start: ret =libxl_domain_create_restore (ctx, &d_config, &domid, restore_fd, - send_back_fd,NULL , ¶ms, -0 , autoconnect_console_how); + send_back_fd, postcopy_resumed, + ¶ms,0 , autoconnect_console_how);libxl_domain_restore_params_dispose (¶ms);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 21/23 xen/mem_paging: move paging op arguments into a union
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
In preparation for the addition of a mem paging op with different arguments than the existing ops, move the op-specific arguments into a union.
No functional change.
--- tools/libxc/xc_mem_paging.c | 8 ++++---- xen/arch/x86/mm/mem_paging.c | 6 +++--- xen/include/public/memory.h | 12 ++++++++---- 3 files changed, 15 insertions(+), 11 deletions(-)
tools/libxc/xc_mem_paging.c +4 -4
@@ -29,10 +29,10 @@ static int xc_mem_paging_memop(xc_interface *xch, domid_t domain_id,memset (&mpo,0 ,sizeof (mpo)); - mpo.op = op; - mpo.domain = domain_id; - mpo.gfn = gfn; - mpo.buffer = (unsigned long ) buffer; + mpo.op = op; + mpo.domain = domain_id; + mpo.u.single.gfn = gfn; + mpo.u.single.buffer = (unsigned long ) buffer;return do_memory_op (xch, XENMEM_paging_op, &mpo,sizeof (mpo)); }
xen/arch/x86/mm/mem_paging.c +3 -3
@@ -49,15 +49,15 @@ int mem_paging_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_paging_op_t) arg)switch ( mpo.op ) {case XENMEM_paging_op_nominate: - rc =p2m_mem_paging_nominate (d, mpo.gfn); + rc =p2m_mem_paging_nominate (d, mpo.u.single.gfn);break ;case XENMEM_paging_op_evict: - rc =p2m_mem_paging_evict (d, mpo.gfn); + rc =p2m_mem_paging_evict (d, mpo.u.single.gfn);break ;case XENMEM_paging_op_prep: - rc =p2m_mem_paging_prep (d, mpo.gfn, mpo.buffer); + rc =p2m_mem_paging_prep (d, mpo.u.single.gfn, mpo.u.single.buffer);if ( !rc ) copyback =1 ;break ;
xen/include/public/memory.h +8 -4
@@ -394,10 +394,14 @@ struct xen_mem_paging_op {uint8_t op;/* XENMEM_paging_op_* */ domid_t domain; -/* PAGING_PREP IN: buffer to immediately fill page in */ -uint64_aligned_t buffer; -/* Other OPs */ -uint64_aligned_t gfn;/* IN: gfn of page being operated on */ +union { +struct { +/* PAGING_PREP IN: buffer to immediately fill page in */ +uint64_aligned_t buffer; +/* Other OPs */ +uint64_aligned_t gfn;/* IN: gfn of page being operated on */ + } single; + } u; };typedef struct xen_mem_paging_op xen_mem_paging_op_t ;DEFINE_XEN_GUEST_HANDLE (xen_mem_paging_op_t);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 22/23 xen/mem_paging: add a populate_evicted paging op
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
The paging API presently permits only individual, populated pages to be evicted, and even then only after a previous nomination op on the candidate page. This works well at steady-state, but is somewhat awkward and inefficient for pagers attempting to implement startup demand-paging for guests: in this case it is necessary to populate all of the holes in the physmap to be demand-paged, only to then nominate and immediately evict each page one-by-one.
To permit more efficient startup demand-paging, introduce a new populate_evicted paging op. Given a batch of gfns, it:
- marks gfns corresponding to phymap holes as paged-out directly
- frees the backing frames of previously-populated gfns, and then marks them as paged-out directly (skipping the nomination step)
The latter behaviour is needed to fully support postcopy live migration:
a page may be populated only to have its contents subsequently invalidated by a write at the sender, requiring it to ultimately be demand-paged anyway.
I measured a reduction in time required to evict a batch of 512k previously-unpopulated pfns from 8.535s to 1.590s (~5.4x speedup).
Note: as a long-running batching memory op, populate_evicted takes advantage of the existing pre-emption/continuation hack (encoding the starting offset into the batch in bits [:6] of the op argument). To make this work, plumb the cmd argument all the way down through do_memory_op() -> arch_memory_op() -> subarch_memory_op() -> mem_paging_memop(), fixing up each switch statement along the way to use only the MEMOP_CMD bits.
--- tools/libxc/include/xenctrl.h | 2 + tools/libxc/xc_mem_paging.c | 31 ++++++++++++ xen/arch/x86/mm.c | 5 +- xen/arch/x86/mm/mem_paging.c | 34 ++++++++++++- xen/arch/x86/mm/p2m.c | 101 +++++++++++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/mm.c | 6 ++- xen/arch/x86/x86_64/mm.c | 6 ++- xen/include/asm-x86/mem_paging.h | 3 +- xen/include/asm-x86/p2m.h | 2 + xen/include/public/memory.h | 13 +++-- 10 files changed, 190 insertions(+), 13 deletions(-)
tools/libxc/include/xenctrl.h +2 -0
@@ -1945,6 +1945,8 @@ int xc_mem_paging_resume(xc_interface *xch, domid_t domain_id);int xc_mem_paging_nominate (xc_interface *xch,domid_t domain_id,uint64_t gfn);int xc_mem_paging_evict (xc_interface *xch,domid_t domain_id,uint64_t gfn); +int xc_mem_paging_populate_evicted (xc_interface *xch,domid_t domain_id, +xen_pfn_t *gfns,uint32_t nr);int xc_mem_paging_prep (xc_interface *xch,domid_t domain_id,uint64_t gfn);int xc_mem_paging_load (xc_interface *xch,domid_t domain_id,uint64_t gfn,void *buffer);
tools/libxc/xc_mem_paging.c +31 -0
@@ -116,6 +116,37 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id,return rc; } +int xc_mem_paging_populate_evicted (xc_interface *xch, +domid_t domain_id, +xen_pfn_t *gfns, +uint32_t nr) +{ +DECLARE_HYPERCALL_BOUNCE (gfns, nr *sizeof (*gfns), +XC_HYPERCALL_BUFFER_BOUNCE_IN ); +int rc; + +xen_mem_paging_op_t mpo = + { + .op = XENMEM_paging_op_populate_evicted, + .domain = domain_id, + .u = { .batch = { .nr = nr } } + }; + +if (xc_hypercall_bounce_pre (xch, gfns) ) + { +PERROR ("Could not bounce memory for XENMEM_paging_op_populate_evicted" ); +return -1 ; + } + +set_xen_guest_handle (mpo.u.batch.gfns, gfns); + + rc =do_memory_op (xch, XENMEM_paging_op, &mpo,sizeof (mpo)); + +xc_hypercall_bounce_post (xch, gfns); + +return rc; +} +/* * Local variables:
xen/arch/x86/mm.c +3 -2
@@ -4955,9 +4955,10 @@ int xenmem_add_to_physmap_one(long arch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { -int rc; +long rc; +int op = cmd &MEMOP_CMD_MASK ; -switch ( cmd ) +switch ( op ) {case XENMEM_set_memory_map: {
xen/arch/x86/mm/mem_paging.c +32 -2
@@ -21,12 +21,17 @@#include <asm/p2m.h> +#include <xen/event.h> #include <xen/guest_access.h> +#include <xen/hypercall.h> #include <xsm/xsm.h> -int mem_paging_memop (XEN_GUEST_HANDLE_PARAM (xen_mem_paging_op_t) arg) +long mem_paging_memop (unsigned long cmd, +XEN_GUEST_HANDLE_PARAM (xen_mem_paging_op_t) arg) { -int rc; +long rc; +unsigned long start_gfn = cmd >>MEMOP_EXTENT_SHIFT ; +xen_pfn_t gfn;xen_mem_paging_op_t mpo;struct domain *d;bool_t copyback =0 ;
@@ -56,6 +61,31 @@ int mem_paging_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_paging_op_t) arg) rc =p2m_mem_paging_evict (d, mpo.u.single.gfn);break ; +case XENMEM_paging_op_populate_evicted: +while ( start_gfn < mpo.u.batch.nr ) + { +if (copy_from_guest_offset (&gfn, mpo.u.batch.gfns, start_gfn,1 ) ) + { + rc = -EFAULT ; + goto out; + } + + rc =p2m_mem_paging_populate_evicted (d, gfn); +if ( rc ) + goto out; + +if ( mpo.u.batch.nr > ++start_gfn &&hypercall_preempt_check () ) + { + cmd = XENMEM_paging_op | (start_gfn <<MEMOP_EXTENT_SHIFT ); + rc =hypercall_create_continuation (__HYPERVISOR_memory_op,"lh" , + cmd, arg); + goto out; + } + } + + rc =0 ; +break ; +case XENMEM_paging_op_prep: rc =p2m_mem_paging_prep (d, mpo.u.single.gfn, mpo.u.single.buffer);if ( !rc )
xen/arch/x86/mm/p2m.c +101 -0
107 lines not on this page · raw message
xen/arch/x86/x86_64/compat/mm.c +4 -2
@@ -53,8 +53,9 @@ int compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)compat_pfn_t mfn;unsigned int i;int rc =0 ; +int op = cmd &MEMOP_CMD_MASK ; -switch ( cmd ) +switch ( op ) {case XENMEM_set_memory_map: {
@@ -187,7 +188,8 @@ int compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return mem_sharing_get_nr_shared_mfns ();case XENMEM_paging_op: -return mem_paging_memop (guest_handle_cast (arg, xen_mem_paging_op_t)); +return mem_paging_memop (cmd, +guest_handle_cast (arg, xen_mem_paging_op_t));case XENMEM_sharing_op:return mem_sharing_memop (guest_handle_cast (arg, xen_mem_sharing_op_t));
xen/arch/x86/x86_64/mm.c +4 -2
@@ -926,8 +926,9 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)xen_pfn_t mfn, last_mfn;unsigned int i;long rc =0 ; +int op = cmd &MEMOP_CMD_MASK ; -switch ( cmd ) +switch ( op ) {case XENMEM_machphys_mfn_list:if (copy_from_guest (&xmml, arg,1 ) )
@@ -1004,7 +1005,8 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return mem_sharing_get_nr_shared_mfns ();case XENMEM_paging_op: -return mem_paging_memop (guest_handle_cast (arg, xen_mem_paging_op_t)); +return mem_paging_memop (cmd, +guest_handle_cast (arg, xen_mem_paging_op_t));case XENMEM_sharing_op:return mem_sharing_memop (guest_handle_cast (arg, xen_mem_sharing_op_t));
xen/include/asm-x86/mem_paging.h +2 -1
@@ -22,7 +22,8 @@#ifndef __ASM_X86_MEM_PAGING_H__#define __ASM_X86_MEM_PAGING_H__ -int mem_paging_memop (XEN_GUEST_HANDLE_PARAM (xen_mem_paging_op_t) arg); +long mem_paging_memop (unsigned long cmd, +XEN_GUEST_HANDLE_PARAM (xen_mem_paging_op_t) arg);#endif /*__ASM_X86_MEM_PAGING_H__ */
xen/include/asm-x86/p2m.h +2 -0
@@ -676,6 +676,8 @@ int set_shared_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);int p2m_mem_paging_nominate (struct domain *d,unsigned long gfn);/* Evict a frame */ int p2m_mem_paging_evict (struct domain *d,unsigned long gfn); +/* If @gfn is populated, evict it. If not, mark it as paged-out directly. */ +int p2m_mem_paging_populate_evicted (struct domain *d,unsigned long gfn);/* Tell xenpaging to drop a paged out frame */ void p2m_mem_paging_drop_page (struct domain *d,unsigned long gfn,p2m_type_t p2mt);
xen/include/public/memory.h +9 -4
@@ -385,10 +385,11 @@ typedef struct xen_pod_target xen_pod_target_t;#define XENMEM_get_sharing_freed_pages 18#define XENMEM_get_sharing_shared_pages 19 -#define XENMEM_paging_op 20 -#define XENMEM_paging_op_nominate 0 -#define XENMEM_paging_op_evict 1 -#define XENMEM_paging_op_prep 2 +#define XENMEM_paging_op 20 +#define XENMEM_paging_op_nominate 0 +#define XENMEM_paging_op_evict 1 +#define XENMEM_paging_op_prep 2 +#define XENMEM_paging_op_populate_evicted 3struct xen_mem_paging_op {uint8_t op;/* XENMEM_paging_op_* */
@@ -401,6 +402,10 @@ struct xen_mem_paging_op {/* Other OPs */ uint64_aligned_t gfn;/* IN: gfn of page being operated on */ } single; +struct { +XEN_GUEST_HANDLE (xen_pfn_t) gfns; +uint32_t nr; + } batch; } u; };typedef struct xen_mem_paging_op xen_mem_paging_op_t ;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v2 23/23 libxc/xc_sr_restore.c: use populate_evicted()
In reply to Joshua OttoFrom: Joshua Otto <[email protected]>
During the transition downtime phase of postcopy live migration, mark batches of dirty pfns as paged-out using the new populate_evicted() paging op rather than populating, nominating and evicting each dirty pfn individually. This significantly reduces downtime during transitions with many dirty pfns.
--- tools/libxc/xc_sr_restore.c | 71 +++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 25 deletions(-)
tools/libxc/xc_sr_restore.c +46 -25
@@ -672,13 +672,15 @@ static int process_postcopy_pfns(struct xc_sr_context *ctx, unsigned int count,xc_interface *xch = ctx->xch;struct xc_sr_restore_paging *paging = &ctx->restore.paging;int rc; -unsigned int i; +unsigned int i, nr_bpfns =0 , nr_xapfns =0 ;xen_pfn_t bpfn; +xen_pfn_t *bpfns =malloc (count *sizeof (*bpfns)), + *xapfns =malloc (count *sizeof (*xapfns)); - rc =populate_pfns (ctx, count, pfns, types); -if ( rc ) +if ( !bpfns || !xapfns ) { -ERROR ("Failed to populate pfns for batch of %u pages" , count); + rc =-1 ; +ERROR ("Failed to allocate %zu bytes pfns" ,2 * count *sizeof (*bpfns)); goto out; }
@@ -686,7 +688,7 @@ static int process_postcopy_pfns(struct xc_sr_context *ctx, unsigned int count, {if ( types[i] <XEN_DOMCTL_PFINFO_BROKEN ) { - bpfn = pfns[i]; + bpfn = bpfns[nr_bpfns++] = pfns[i];/* We should never see the same pfn twice at this stage. */ if ( !postcopy_pfn_invalid (ctx, bpfn) )
@@ -695,6 +697,42 @@ static int process_postcopy_pfns(struct xc_sr_context *ctx, unsigned int count,ERROR ("Duplicate postcopy pfn %" PRI_xen_pfn, bpfn); goto out; } + } +else if ( types[i] ==XEN_DOMCTL_PFINFO_XALLOC ) + { + xapfns[nr_xapfns++] = pfns[i]; + } + } + +/* Follow the normal path to populate XALLOC pfns... */ + rc =populate_pfns (ctx, nr_xapfns, xapfns,NULL ); +if ( rc ) + { +ERROR ("Failed to populate pfns for batch of %u pages" , nr_xapfns); + goto out; + } + +/* ... and 'populate' the backed pfns directly into the evicted state. */ +if ( nr_bpfns ) + { + rc =xc_mem_paging_populate_evicted (xch, ctx->domid, bpfns, nr_bpfns); +if ( rc ) + { +ERROR ("Failed to evict batch of %u pfns" , nr_bpfns); + goto out; + } + +for ( i =0 ; i < nr_bpfns; ++i ) + { + bpfn = bpfns[i]; + +/* If it hasn't yet been populated, mark it as so now. */ +if ( !pfn_is_populated (ctx, bpfn) ) + { + rc =pfn_set_populated (ctx, bpfn); +if ( rc ) + goto out; + }/* * We now consider this pfn 'outstanding' - pending, and not yet
@@ -702,32 +740,15 @@ static int process_postcopy_pfns(struct xc_sr_context *ctx, unsigned int count,*/ mark_postcopy_pfn_outstanding (ctx, bpfn); ++paging->nr_pending_pfns; - -/* -* Neither nomination nor eviction can be permitted to fail - the -* guest isn't yet running, so a failure would imply a foreign or -* hypervisor mapping on the page, and that would be bogus because -* the migration isn't yet complete. -*/ - rc =xc_mem_paging_nominate (xch, ctx->domid, bpfn); -if ( rc <0 ) - { -PERROR ("Error nominating postcopy pfn %" PRI_xen_pfn, bpfn); - goto out; - } - - rc =xc_mem_paging_evict (xch, ctx->domid, bpfn); -if ( rc <0 ) - { -PERROR ("Error evicting postcopy pfn %" PRI_xen_pfn, bpfn); - goto out; - } } } rc =0 ; out: +free (bpfns); +free (xapfns); +return rc; }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Am Sun, 17 Jun 2018 03:18:11 -0700
schrieb Joshua Otto <[email protected]>:
Quoted 2 lines
A little over a year ago, I posted a patch series implementing support for post-copy live migration via xenpaging [1].
That that went anywhere, or was this a wasted effort?
Olaf