Project

General

Profile

action #40538

Reset/Clear guest RAM when it reboots in QEMU to reduce RAM snapshot size

Added by rpalethorpe over 2 years ago. Updated 9 months ago.

Status:
Workable
Priority:
Low
Assignee:
-
Category:
Feature requests
Target version:
Start date:
2018-09-03
Due date:
% Done:

0%

Estimated time:
Difficulty:

Description

During installation 4GB+ of RAM can be used by the guest. Most of the time the RAM usage is much lower than this.

After installation completes the system is rebooted and then a snapshot is taken. In theory the snapshot should be very small because the system has only just booted, however it appears that QEMU thinks all the RAM is still in use and saves it to the snapshot. This might not be unexpected because on bare metal the RAM is preserved between reboots on modern systems. However, assuming that it is not relied upon by the guest OS, we don't need it to happen and can save some time.

Some ideas to solve this:

  • Use the virtio memory balloon
  • Use the -no-reboot switch and restart the QEMU process if it exits unexpectedly.
  • Patch QEMU to clear (some of) the RAM when the guest initiates a reboot.

Related issues

Related to openQA Project - action #59109: use ballooning to improve snapshot performanceNew2019-11-05

History

#2 Updated by thehejik over 2 years ago

What about to drop disk caches in VM before taking snapshot? something like:

sync; sync
echo 3 > /proc/sys/vm/drop_caches

#3 Updated by rpalethorpe over 2 years ago

  • Status changed from New to In Progress

I think the virtio-balloon driver can force the kernel to reclaim that memory. Although I suppose dropping the caches would be quicker.

Anyhoo I have implemented ballooning and it seems to work to some extent, please see the bugzilla entry and https://github.com/os-autoinst/os-autoinst/pull/1020

#4 Updated by rpalethorpe over 2 years ago

Also from the bugzilla thread:

Alexander Graf from comment #19

QEMU's RAM migration code treats all-0 pages special, so maybe it's enough to just make as many pages as we can contain all zeros?

For that, it should be enough to do something like

$ dd if=/dev/zero of=/dev/null bs=4G count=1

and wait for it to crash ;). Or the slightly nicer way might be to run

$ dd if=/dev/zero of=/dev/garbage bs=1M; rm -f /dev/garbage

which however will be limited by the /dev tmpfs size.

#5 Updated by rpalethorpe over 2 years ago

  • Status changed from In Progress to Workable

I am reasonably happy with ballooning for now, although it doesn't seem to work perfectly. However the PR needs reviewing and merging.

#6 Updated by okurz almost 2 years ago

  • Category set to Feature requests

#7 Updated by okurz over 1 year ago

  • Related to action #59109: use ballooning to improve snapshot performance added

#8 Updated by okurz 12 months ago

  • Priority changed from Normal to Low
  • Target version set to future

#9 Updated by okurz 9 months ago

  • Subject changed from [tools] Reset/Clear guest RAM when it reboots in QEMU to reduce RAM snapshot size to Reset/Clear guest RAM when it reboots in QEMU to reduce RAM snapshot size

Not currently on the backlog of "QA tools team"

Also available in: Atom PDF