Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

While running Virtual Box my system is accessing the hard drive a lot and running slowly.

When I checked system resources using System Monitor it shows processor usage at 15%, RAM usage at 65% and Swap usage at about 50%.

My question is why does ubuntu need to use Swap when there is sufficient amount of main memory available?

Edit -

Output of free command -

             total       used       free     shared    buffers     cached
Mem:       4075908    3056931    1018977          0       1944     308408
-/+ buffers/cache:    2746579    1329329
Swap:      4139004    1862551    2276453

Note - Virtual box seemed to work just fine before I upgraded my 12.04 Precise to 12.10 Quantal. Now its so slow its almost useless.

share|improve this question

marked as duplicate by Luis Alvarado Apr 23 '13 at 0:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
How much RAM do you have? –  Uri Herrera Jan 2 '13 at 7:38
    
Could you show the output of the free command? –  Nanne Jan 2 '13 at 8:32
    
(just a thought: could it be that virutal box claims all memory it needs as one chunk, one that is bigger then the amount of memory you have left, so it needs to be put in RAM?) –  Nanne Jan 2 '13 at 8:33
1  
Things are thrown in the swap when it isn't actually used, so there is more free ram to work with. –  Dr_Bunsen Jan 2 '13 at 9:31
    
@Nanne No, application-claimed memory are just memory pages which can be paged out of physical memory individually, independently. –  gertvdijk Jan 2 '13 at 10:33

2 Answers 2

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.

swappiness can have a value of between 0 and 100
swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache 

The default setting in Ubuntu is swappiness=60. Reducing the default value of swappiness will probably improve overall performance for a typical Ubuntu desktop installation.

Source: SwapFaq - Ubuntu Wiki

Open the terminal and paste this in before you start virtualbox:

    sudo sysctl vm.swappiness=10

Start the visualization and check whether the swap usage has decreased, if that's the case then in the terminal do the following command:

    gksu gedit /etc/sysctl.conf

It will ask you for your password, type it in and a text editor will come up on the screen, scroll all the way down and after the last line add:

    vm.swappiness=10

Save the file and restart your computer.

That should do the trick!

share|improve this answer
    
@NikTh What do you mean before you start the virtualization? –  Kshitiz Sharma Jan 2 '13 at 9:17
1  
I guess @zaxcvr means "before you start the virtualbox application". I just edited the answer to add more info about swappiness :-) –  NikTh Jan 2 '13 at 9:20
1  
If a just changing swappiness value had such a dramatic effect, surely Ubuntu and every other distro would ship with a different default? There's a downside of decreased swappiness - unused processes remain in memory at the expense of very small disk caches, which slows down disk access. –  Sergey Jan 2 '13 at 9:46

But you don't have enough memory. In the first column, the amount of total memory available is 4075908. The amount of memory actually in use for programs excluding cache and buffers is 2746579. The amount of RAM in swap is 1862551.

This means that the amount of memory actually in use is 2746579+1862551 which equals 4609130. Generally, complete memory blocks and allocations to programs will be swapped out, these being the most efficient way of doing it.

Bottom line is, you have 4609130-4075908 or a 533222 Mb RAM requirement over what you physically have.

Have a look at how much memory you are allocating to the virtual machines that you are running at the time, and what the RAM requirements of other programmes that you may be running. Sometimes less is more - if you reduce the amount of RAM allocated to the virtual machines then you'll get no swapping, and performance will be much better.

share|improve this answer

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