action #40538
openReset/Clear guest RAM when it reboots in QEMU to reduce RAM snapshot size
0%
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.
Updated by rpalethorpe over 6 years ago
Updated by thehejik over 6 years ago
What about to drop disk caches in VM before taking snapshot? something like:
sync; sync
echo 3 > /proc/sys/vm/drop_caches
Updated by rpalethorpe over 6 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
Updated by rpalethorpe over 6 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.
Updated by rpalethorpe over 6 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.
Updated by okurz about 5 years ago
- Related to action #59109: use ballooning to improve snapshot performance added
Updated by okurz over 4 years ago
- Priority changed from Normal to Low
- Target version set to future
Updated by okurz over 4 years 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"