History

virtio: balloon: leak / fill balloon across S4

commit e562966dbaf49e7804097cd991e5d3a8934fc148 added support for S4 to the balloon driver. The freeze function did nothing to free the pages, since reclaiming the pages from the host to immediately give them back (if S4 was successful) seemed wasteful. Also, if S4 wasn't successful, the guest would have to re-fill the balloon. On restore, the pages were supposed to be marked freed and the free page counters were incremented to reflect the balloon was totally deflated. However, this wasn't done right. The pages that were earlier taken away from the guest during a balloon inflation operation were just shown as used pages after a successful restore from S4. Just a fancy way of leaking lots of memory. Instead of trying that, just leak the balloon on freeze and fill it on restore/thaw paths. This works properly now. The optimisation to not leak can be added later on after a bit of refactoring of the code.

Amit Shah committed 14 years ago

Commit 4eb05d51 parent 5ffca281 file · +22 −11Browse files

Unified · Split

drivers/virtio/virtio_balloon.c+22−11
@@ -367,29 +367,45 @@ static void __devexit virtballoon_remove(struct virtio_device *vdev) · 366 unmodified lines
367367 #ifdef CONFIG_PM
368368 static int virtballoon_freeze(struct virtio_device *vdev)
369369 {
370+ struct virtio_balloon *vb = vdev->priv;
371+
370372 /*
371373 * The kthread is already frozen by the PM core before this
372374 * function is called.
373375 */
374376
377+ while (vb->num_pages)
378+ leak_balloon(vb, vb->num_pages);
379+ update_balloon_size(vb);
380+
375381 /* Ensure we don't get any more requests from the host */
376382 vdev->config->reset(vdev);
377383 vdev->config->del_vqs(vdev);
378384 return 0;
379385 }
380386
387+static int restore_common(struct virtio_device *vdev)
388+{
389+ struct virtio_balloon *vb = vdev->priv;
390+ int ret;
391+
392+ ret = init_vqs(vdev->priv);
393+ if (ret)
394+ return ret;
395+
396+ fill_balloon(vb, towards_target(vb));
397+ update_balloon_size(vb);
398+ return 0;
399+}
400+
381401 static int virtballoon_thaw(struct virtio_device *vdev)
382402 {
383− return init_vqs(vdev->priv);
403+ return restore_common(vdev);
384404 }
385405
386406 static int virtballoon_restore(struct virtio_device *vdev)
387407 {
388408 struct virtio_balloon *vb = vdev->priv;
389− struct page *page, *page2;
390−
391− /* We're starting from a clean slate */
392− vb->num_pages = 0;
393409
394410 /*
395411 * If a request wasn't complete at the time of freezing, this
@@ -397,12 +413,7 @@ static int virtballoon_restore(struct virtio_device *vdev) · 1 unmodified line
397413 */
398414 vb->need_stats_update = 0;
399415
400− /* We don't have these pages in the balloon anymore! */
401− list_for_each_entry_safe(page, page2, &vb->pages, lru) {
402− list_del(&page->lru);
403− totalram_pages++;
404− }
405− return init_vqs(vdev->priv);
416+ return restore_common(vdev);
406417 }
407418 #endif
408419