-
由 Amit Shah 提交于
Handling balloon hibernate / restore is tricky. If the balloon was inflated before going into the hibernation state, upon resume, the host will not have any memory of that. Any pages that were passed on to the host earlier would most likely be invalid, and the host will have to re-balloon to the previous value to get in the pre-hibernate state. So the only sane thing for the guest to do here is to discard all the pages that were put in the balloon. When to discard the pages is the next question. One solution is to deflate the balloon just before writing the image to the disk (in the freeze() PM callback). However, asking for pages from the host just to discard them immediately after seems wasteful of resources. Hence, it makes sense to do this by just fudging our counters soon after wakeup. This means we don't deflate the balloon before sleep, and also don't put unnecessary pressure on the host. This also helps in the thaw case: if the freeze fails for whatever reason, the balloon should continue to remain in the inflated state. This was tested by issuing 'swapoff -a' and trying to go into the S4 state. That fails, and the balloon stays inflated, as expected. Both the host and the guest are happy. Finally, in the restore() callback, we empty the list of pages that were previously given off to the host, add the appropriate number of pages to the totalram_pages counter, reset the num_pages counter to 0, and all is fine. As a last step, delete the vqs on the freeze callback to prepare for hibernation, and re-create them in the restore and thaw callbacks to resume normal operation. The kthread doesn't race with any operations here, since it's frozen before the freeze() call and is thawed after the thaw() and restore() callbacks, so we're safe with that. Signed-off-by: NAmit Shah <amit.shah@redhat.com> Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
e562966d