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

  • mom can be obtained from the Wizardry and Steamworks Debian repository where you can find instructions on obtaining the package.
  • The package must be installed in both host and on all guests.
  • The /usr/sbin/name-to-ip script may need to be edited manually depending on your situation. It is a script that takes as parameter a domain (a guest name) and returns the IP address of that domain (guest). If you installed our package, then /usr/sbin/name-to-ip should contain the following abbreviated active lines:
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.

  • On the host system, run the command:
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.

  • On the guest system, run the command:
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.

  • Check /var/log/mon.log on the host which should show that mond was able to connect to the guest machines and will most likely start inflating.

Compiling from Source

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

git clone https://github.com/oVirt/mom.git
  • Compile mom:
cd mom
./autogen.sh
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
  • Install mom:
make install
  • Now you will have to copy a few files from the doc/ sub-directory of mom. You will want to copy doc/mom-balloon.conf to /etc/mom.conf and doc/balloon.rules to /etc/mom.rules.
  • Next, you will want to tinker with the doc/name-to-ip script in order to get the names of your virsh domains to resolve to a valid IP address. After that doc/name-to-ip should be copied to /usr/sbin/.
  • Now /etc/mom.conf should be made to point to /usr/sbin/name-to-ip as well as listing GuestNetworkDaemon in the [guest] section. Here is an abbreviated /etc/mom.conf which contains the relevant changes:
...
[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
  • This takes part of the configuration for mom and the only other thing left to do is to create startup scripts for mom for the host and mom-guestd for the guests. You can download the mom-guestd init script and the momd init script if you so wish and place them in /etc/init.d/. After the scripts are placed in /etc/init.d you can start them with /etc/init.d/momd start if you are working on the host or /etc/init.d/mom-guestd start if you are working on the guest. You can also make the scripts start on boot with:
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.


unix/virtual_machines/automatic_memory_ballooning.txt ยท Last modified: 2024/11/02 03:04 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.