What is the meaning of running out of swap?

10,122

Solution 1

The swap is a secondary (disk-based) storage for your RAM: if your application consumes too much memory, some parts of the RAM are swapped out (moved) onto the hard disk, to make room for new memory requests. (This is happening under the assumption, that the swapped out memory won't be needed in the near future; if an application needs to access it again, the memory will be swapped in again (moved back to the RAM), probably triggering a swap out of another memory area first).

Swapping is usually rather slow, as it involves moving larger data chunks between RAM and hard-disk, and all applications have to wait until it has finished before they can continue. As such, it is meant as a security measure to avoid out-of-memory crashes, but you should try to avoid triggering swapping if possible.

Now the swap-space itself can either be a file or an entire partition, but in any case they have a limited size as well (either defined by the partition size on which they reside, or limited by your OS).

So if you need to swap out a lot of memory (or have a small swap space), you will sooner or later run out of swap.

There are basically two ways to "fix" the problem:

  • make your swap-space bigger
  • make your application consume less memory

extending swap space

  • first, try to add more RAM to your system. The more RAM you have, the less likely it is that the system needs swap out memory.

If this doesn't help (or is not possible), you might need to extend the actual available swap space:

  • first create a new swap area (either a file or a disk partition) using mkswap.
  • then enable the swap space, using swapon.
  • you can also make the changes persistent by adding an entry to your fstab file.

But really this might just make your "running out of swap" problem appear a little later, so read on:

reduce memory consumption

Today's computers have plenty of RAM. Unless you are dealing with very large datasets or are running very many memory hungry applications in parallel, it is highly unlikely that you ever run out of RAM and/or swap space.

Unless, that is, one of your application has a memory leak and consumes an unbound amount of memory.

Try to find out which applications use up all the memory, and check whether they are leaking resources.

Solution 2

Swap space is an area on disk that is used to store processes when they are moved out of memory. In ye olde days before virtual memory, this was the means of making room for multiple users.

A page file is an area on disk that is used to implement virtual memory.

Swapping => Moving entire processes in and out of memory. Paging => Moving individual pages in and out of memory.

Some systems have used both swap and page files but the trend now is just to have a page file.

Page files need to be contiguous for efficiency purposes, something not possible on the historical unix file system. Many unix variants use a disk partition rather than a file. This usually called a "Swap Partition" in unix-land because Unix originally ran on PDPs that did not support virtual memory. Therefore they used swapping rather than paging and the name stayed on.

The problem of running out of swap depends upon whether you are really swapping or paging. In a virtual memory system all user user memory has to be mapped to a file. Often this is a combination of the executable file and the page file. The executable file is used to page static memory (code, data) while the page file pages dynamic memory. The size of the page file is then one of the limitations on the amount of virtual memory a process can have EVEN IF PHYSICAL MEMORY IS AVAILABLE. Virtual memory requires there to be a disk space for all memory pages. Increasing physical memory does not solve running out of paging space.

It is unlikely you are encountering a swapping system these days. There are some page file and swap file systems around. In a swapping system, lack of space is generally a problem of having too many jobs running around. You can increase physical memory but most swapping systems support 1,2, 4, maybe 8 MB (not GB).

Share:
10,122
Bubbles
Author by

Bubbles

Updated on June 15, 2022

Comments

  • Bubbles
    Bubbles almost 2 years

    In linux machines for many scenarios we might get errors Running out of swap. what exactly it means. Is it similar to thrashing ? Are Running out of space and running out of swap are similar terms ? How can we find fix these kind of errors ?