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.

So I have a problem, I'm managing a server and the swap partition is way too small at the moment. The machine runs KVM with about 24 VM's on it. The problem is that some of them are rather inactive so they get swapped.

However the guy managing it before me only used 4 GB for swap, which is constantly filled. It's not a problem, because my memory usage is only at about 64%, but it would be nice if I could extend the swap.

I know I can make an extra swap volume with lvm. What I was wondering about is if it is possible to mount it to the host and use it without rebooting the server?

share|improve this question
2  
This isn't really an answer to your question, but the kernel doesn't swap out inactive processes because they're inactive. It swaps them out because it needs the memory. Having a swap-happy system is a good indication you need to add more RAM and/or reconfigure the VMs, unless performance and power efficiency aren't priorities at the moment. –  Alexios Mar 13 '12 at 19:13
1  
The VM's are just really inactive, the swappiness is default on 60. However it actually swaps things out when it notices the page hasn't been touched for a while, even if you have enough memory. –  Lucas Kauffman Mar 13 '12 at 19:33
    
I stand corrected. As long as it's the desired behaviour and you're happy with it! Jofel's answer is pretty much the standard way of doing this on a running box. –  Alexios Mar 13 '12 at 19:37
1  
Yea I'll have to do it this way, no budget to buy more memory :( –  Lucas Kauffman Mar 13 '12 at 19:39
    
as @Alexios said VMs need more memory you may look ksm if you aren't using. –  Selman Ulug Mar 13 '12 at 20:32

1 Answer 1

up vote 5 down vote accepted

You can dynamically add or remove swap spaces with swapon and swapoff. If you remove to much memory, running processes could be killed. You can also give priorities between the swap spaces using the -p option.

To format a new partition/lvm volume as swap, use mkswap.

share|improve this answer
2  
You can also ‘format’ regular files as swap. dd if=/dev/zero of=tmp.swap bs=1M count=1024; mkswap tmp.swap; swapon tmp.swap works just fine. Obviously, swap files are slightly slower than swap block devices because they access disk blocks via the VFS layer. But they do work. –  Alexios Mar 13 '12 at 19:09

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.