Table of Contents

About

When using virsh as a manager for virtual machines with configured memory limits such that the current memory is smaller than the maximal memory available to the virtual machine, you can use the setmem command to add memory to a virtual machine. For example, consider the following memory configuration for a domain:

  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>

the current memory is set to 1048576 KiB (1 GB) and the total available memory to the virtual machine is 2097152 KiB (2 GB). Using the setmem command you can increase or decrease the memory available to the virtual machine within the range of 1 GB to 2 GB.

However, when you have long-time running virtual machines, it is cumbersome at best to always be present in order to manage the available memory - increasing when the virtual machine needs memory and decreasing when it does not, in order to allocate the resources to other virtual machines.

This is where automatic memory ballooning comes in, which is able to detect the memory pressure in the host system and then increase or decrease the memory for the guests when suitable.

A daemon that does this automatically is called mom and it is available from oVirt. We are going to set-up mom to monitor the virtual machines.

Setup

NAME=$1
nslookup $NAME | grep '^Address' | awk '{print $2}' | tail -1

which takes a domain name, looks-up the domain name and grabs the address. This obviously only works if you have named your domain names as the host-names of the virtual machines. If you have not, you can create your own script that returns the correct IP address from the domain name.

update-rc.d mond defaults
/etc/init.d/mond start

in order to start mond (the server/host component) and also have mond started automatically on system startup.

update-rc.d mon-guestd defaults
/etc/init.d/mon-guestd start

to start mon-guestd (the guest/client component) and to also have mon-guestd started automatically on system startup.

Compiling from Source

If you have to compile mom from source, follow the indicated steps:

git clone https://github.com/oVirt/mom.git
cd mom
./autogen.sh
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
make install
...
[guest]
# A comma-separated list of Collector plugins to use for Guest data collection.
collectors: GuestQemuProc, GuestMemory, GuestBalloon, GuestNetworkDaemon
...

[Collector: GuestNetworkDaemon]
# Helper program to convert guest names to IP addresses.  This is only used by
# the GuestNetworkDaemon Collector.  See doc/name-to-ip for an example.
name-to-ip-helper: /usr/sbin/name-to-ip
update-rc.d momd defaults

for the host and:

update-rc.d mom-guestd defaults

for the guests.

Watching Log-Files

You can let momd write to a logfile by enabling the log directive in /etc/mom.conf:

#log: stdio
log: /var/log/mom.log

The log-file will indicate whether the host is able to connect to the guests and whether it has increased or decreased the memory available to a particular domain.

The Default Policy

You will notice that mom has a tendency to increase memory to the guests rather than decreasing it. This is due to the default policy which mom uses which tries to make as much memory available to the guests as possible without hurting the host operating system. In other words, mom will be reluctant to decrease memory for the guests - which, may seem counter-intuitive if you are thinking in terms of memory conservation. On the other hand, in case the host is under pressure, it will start decreasing the memory of the guests.