Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

suppose the following scenario: a host with 2 GiB runs a few guests using KVM. Each guest does usually not need much memory, they are given 256 MiB each and run services that mostly twiddle their thumbs. However, occasionally the guests need more memory. Right now, each guest has little RAM but its own swap space. I noticed that a small portion of swap is used. I never had problems with that konfiguration, but just out of curiosity:

What is the optimal swap allocation strategy?

  1. Assign each guest its own swap space from their respective disks, and assign the guests only little memory from the host. (This is what I am doing now.)
  2. Assign the host a larger amount of swap space and none to the guests, and assign more memory to the guests.

Would memory ballooning help to improve memory performance?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

"Occasional guests need more memory" sounds like a good application of overcommitting memory. The idea is you assign each guest a large amount of memory (more than you can actually give out) because they're generally not using it. Then you do the math to ensure you have enough swap space that the guests can actually swap out to disk in the worst-case-scenario where they all actually do use all that memory.

The swap space goes on the host machine, and it needs to obey

host swap space = sum of all guest memory + recommended host swap space

in order for it to be safe.

So if you have 10 guests and 2 GiB of RAM, you could experiment with something like

  • 512 MiB RAM per guest (512 * 10 = 5120 MiB total)
  • 2GiB swap on the host

Meaning your host swap space should be at least 512 * 10 + 2048 = 7168 MiB to handle this safely, assuming you can dedicate 2GiB of swap to the host (for that little host memory, this is recommended).

Always test these kinds of setups first to make sure your machine can handle them. Benchmarking them is even better, and will allow you to experiment with different loadouts and choose the one that works best.

share|improve this answer

@ndt has a good procedure. My scenario is different, so I adopt a different method.

My server has many guests, all of them run a single application, usually web/mail/file server. The data inside is very important, so backups and snapshots are made very often. So the smaller and simpler the disk image is better. So I actually don't create a swap partition, but a swap file. Since I have no guests with high processing or even memory needs, they have a small disk storage and small memory. The swap file goes inside of rootfs.

This setup saves a lot of space and simplify maintenance. As I said, it's different from others situations.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.