Why won't Ubuntu use swap?

7,868

Solution 1

Getting memory from swap is very slow. Linux uses all available memory saving a small amount to run commands quickly. It will swap when memory is needed and not available through other means.

Linux also buffers all the files you read and write in memory in a LRU cache. These buffers can be quickly released if memory is needed by programs. Given the programs you are running you may be running low on buffers, and I/O which is usually normally served out of buffers is being read from disk.

There is a swappiness parameter you can tune, but you may want to examine what is happening first. Try installing the sar utility (package sysstat) and running it in the background. You can then examine the files it generates to see what resource is becoming a bottleneck.

Solution 2

To add to Bill's response:

Swap should be avoided when possible because of the overhead. I believe the newer versions of Ubuntu have a defaulted value of 'swappiness' set to 10 (only start using Swap when <10% of RAM is available). I believe this is pretty consistent with what you are seeing.

If for some reason you want to start using swap earlier (ie. in order to have enough free ram to start a new VM image) then you can consider increasing the 'swappiness' value. The following guide describes how this is done and provides additional information (See section "Why is my swap not being used?").

https://help.ubuntu.com/community/SwapFaq

Share:
7,868

Related videos on Youtube

mtbkrdave
Author by

mtbkrdave

Updated on September 18, 2022

Comments

  • mtbkrdave
    mtbkrdave over 1 year

    I'm running 32-bit Ubuntu 10.04 on a 4-core AMD Phenom machine with 4GB of RAM. With normal use (a dozen or so Chrome tabs, 1 VirtualBox machine, 2 or 3 instances of QtCreator, ) the memory will occasionally fill >95% and the machine will become mostly unresponsive.

    If I look at the System Monitor during these periods, it shows the memory usage at 95%+ but only a few hundred MB of my 9GB swap partition are used! Why isn't more memory shifted into swap to avoid running out?

    See: http://imagebin.org/148884

    • Jjames
      Jjames about 13 years
      You might want to install the pae kernel to get that missing 800MiB of RAM.
    • ctn
      ctn about 9 years
      I have the same problem. I think it's related to old Ubuntu versions, a friend with the same problem seems to have it fixed in latest Ubuntu (14.10).