4

When i installed ubuntu in my x86 machine, I had to configure some memory as 'swap area'.

What is the use of this memory and what is the importance of this memory in linux file systems?

How can I determine the exact size of 'swap area' in a machine for the safe working of linux inside in it?

Stefan
  • 25,300
Renjith G
  • 5,888

5 Answers5

7

A very "untechnical" explanation:

Swap area is hard drive space that is reserved to act as extra RAM for when your computer needs more RAM than what is available. Note that when this happens your computer might slow down noticably.

The Ubuntu help website recommends that you have double the ammount of RAM as SWAP. So if you have 1GB of RAM, you should have 2GB SWAP, however your computer should work fine with less SWAP.

Stefan
  • 25,300
  • Swap area is hard drive space that acts as extra RAM. HOW? – Renjith G Oct 15 '10 at 20:56
  • You tell your computer to use the SWAP partition ( some hard drive space reserved for this purpose ) when it needs more RAM space than what is installed on your system – Stefan Oct 15 '10 at 21:02
  • I updated my answer to reflect this. – Stefan Oct 15 '10 at 21:07
  • NO man. i mean how the said hard disk space acts like as a RAM ? – Renjith G Oct 15 '10 at 21:08
  • no idea :) my quess is that the system reads and writes to the RAM, so now it just reads and writes to a area on the hard drive and that area is called swap... – Stefan Oct 15 '10 at 21:13
  • That said swap area section in hard disk is accessed as RAM by Virtual memory concept! – Renjith G Oct 15 '10 at 21:37
  • yes, that seems right. – Stefan Oct 15 '10 at 21:42
  • It doesn't act as the RAM per se, it just moves low priority pages to the hard disk, while (trying) to retain active pages on the RAM. The issue is when something is needed that resides on the hard disk, inside SWAP, because the time needed to retrieve it, and change it with some other page in the RAM is very lengthy. At least that's what I know about it. – NlightNFotis Nov 09 '12 at 16:17
4

The swap partition (or file) in linux is equivalent to the page file in Windows. It's used for offloading the RAM. If the RAM gets full, the OS can use the swap partition as extra RAM.

As for how to determine your swap size, the rule of thumb is (used to be) 2x the amount of RAM in your machine. So if you had 512MB of ram, you would have a 1GB swap partition. This rule is largely outdated though. So if you have more than say 2GB of ram, you don't really need 4GB of swap.

I normally make my swap size equal to the ram size + 10%. It has to be equal to the RAM size so that you can use suspend to disk features, and then + 10% for good measure.

Falmarri
  • 13,047
3

The Ubuntu Swap FAQ provides some of the answers you ask for.

There are also a few posts on this very site, that already cover much of the topic:

1

Swap is a type of filesystem and is a virtual memory. Whenever your RAM is full, your operating system will look for further memory in your swap space. For this reason, you reserve some part of the hard disk to create a swap partition.

Mat
  • 52,586
uday
  • 11
0

You probably mean you configured some space on your hard disk for swap.

Swap is part of memory management. It extends the virtual memory space you have, such that it can be more than your physical memory available, i.e. RAM. This allows then to swap pages of memory between RAM and harddisk, however, obviously it will decrease the performance when this happens.

This way applications can allocate more memory that you have as RAM, even it cannot all be used at the same time.

txwikinger
  • 2,226
  • 22
  • 27