LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-19-2007, 04:02 AM   #1
diptanjan
LQ Newbie
 
Registered: Jun 2007
Distribution: Redhat, Suse
Posts: 8

Rep: Reputation: 0
Why Swap=2 x RAM


Hi Friends,

Why do we use Swap space double the RAM. i.e SWAP = 2 x RAM.

Is this a universal rule for any size of RAM...?

If I install LINUX with 1GB of RAM and then after somedays I want to upgrate my RAM to 2GB. Can I do that without hampering the installation, as in that case I have to provide the SWAP space as 4GB.

I think yes.. now tell me How?

TIA

Diptanjan
 
Old 06-19-2007, 04:09 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
we don't. used to be relevant when you could swap RAM for a kidney in a dark alley way, nowadays really not relevant. having said that with the size of hard disks, it's still often done as 1 or 2gb of 320gb is nothing.
 
Old 06-19-2007, 05:10 AM   #3
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Rep: Reputation: 30
Quote:
Originally Posted by diptanjan
Hi Friends,

Why do we use Swap space double the RAM. i.e SWAP = 2 x RAM.

Is this a universal rule for any size of RAM...?

If I install LINUX with 1GB of RAM and then after somedays I want to upgrate my RAM to 2GB. Can I do that without hampering the installation, as in that case I have to provide the SWAP space as 4GB.

I think yes.. now tell me How?

TIA

Diptanjan

My system no longer has a swap drive with 1GB ram

basically it isnt as important as it used to be

and 1, 2 - 4 GB are all more than sufficient.


The swap is in no way related to the memory so you wont have any troubles
 
Old 07-13-2007, 08:46 PM   #4
qed2
LQ Newbie
 
Registered: Jun 2007
Distribution: slackware
Posts: 2

Rep: Reputation: 0
There is no need to have swap space

It can slow down your computer considerably. I have laptop with 1.25 GB RAM and swap space about 1.5 GB and I never needed to turn it on.
 
Old 07-13-2007, 08:53 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by qed2
It can slow down your computer considerably. I have laptop with 1.25 GB RAM and swap space about 1.5 GB and I never needed to turn it on.
That's an inappropriate generalisation. If you said
"my machine never uses swap" that's fine, but to say
there's no need is not only wrong it's dangerous.

And as for the slowing down: I'd rather have my machine
slow down than randomly shoot a process to be able to
meet another ones needs.

And welcome to LQ, btw :}



And as for the old rule that the original poster was
referring true: it was definitely true in the days
when machines with 64MB were top-notch. Today it all
depends on the machines memory usage patterns (thus
in case of workstation on the users behaviour).





Cheers,
Tink
 
Old 07-13-2007, 09:06 PM   #6
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
If all your processes will run in the amount of memory in your machine then you don't NEED swap. To Be Honest, the fact that you're asking the question implies that you're a long way away from needing to consider the swap question. It's true that if you don't have any swap, then the system will start shooting processes when it runs out of memory. It's also true that the system will start shooting processes when it runs out of swap. So, in the end, there are two things to consider.

1. Total process space needed - If 1GB will do it, then it doesn't matter whether it's 256MB RAM and 756 MB swap, or 1GB of ram.

2. However, you are unlikely to enjoy using a system that is using swap heavily as much as you will a system that doesn't swap at all. Swap can be considered as very slow speed RAM. If you have to run a process that uses an enormous memory footprint, but you don't care how long it takes, then use a lot of swap. If it's important to you how long it takes for that process to run, then you'd probably want to be sure you have enough RAM to run it.

To reinforce what I said above, most people who ask this question do not need to be concerned about it, unless they're running an old decrepit system and have no money, but do have spare disk space. The rest of us run faster machines with lots of RAM, and if the machine slows down due to swappage, we order some more RAM.
 
Old 07-13-2007, 09:20 PM   #7
phantom_cyph
Senior Member
 
Registered: Feb 2007
Location: The Tropics
Distribution: Slackware & Derivatives
Posts: 2,472
Blog Entries: 1

Rep: Reputation: 128Reputation: 128
Its tradition. :-D

No, actually, I think it makes the system faster.
 
Old 07-13-2007, 09:22 PM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
It is simply "a good rule-of-thumb."

When you provide swap-space (and "2x RAM" seems to be a good amount, based on many years of practical experience), you leave your operating-system with plenty of options. It can choose what to keep in RAM, and what to move out to disk, because there's always a place for it to go. Furthermore, since the space available greatly-exceeds the amount of RAM, "running out" of swap space isn't a reasonable possibility.

If your computer finds no reason to swap, of course it never will. It won't slow your system down in any way, one way or the other.
 
Old 07-16-2007, 01:46 AM   #9
synss
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian, Gentoo, Mac OS X
Posts: 137

Rep: Reputation: 22
At the prompt, issue
free -m
you will see how much RAM you are using right now, and how much swap too. Based on this, you can chose to disable swap completely or increase your swap space or do nothing. Very likely, if you add RAM, you will need less swap. If you suspend to ram, you need a swap space, which is at least half your RAM.

You can tune your usage of swap/ram in /proc/sys/vm/swappiness, depending on what you are doing with your computer.
 
Old 07-16-2007, 02:00 AM   #10
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
On modern PC with 512MB RAM or more, swap is often useless but should be there, in case there's an occasional need for it.

It should be roughtly the same size of your RAM if you intend to use the suspend-to-disk (hibernate) feature. If not, then there's no rule any more.

Yves.
 
Old 07-16-2007, 09:17 PM   #11
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
One useful thing about swap space - if you suspend to disk, the image is normally written to your swap partititon. Therefore, if you intend to suspend to disk, then make sure you have sufficient swap space.

I generally give about 1.5x RAM to swap. One of my machines has 500Gb, the other has 1Tb. Therefore the space taken is not significant in the scheme of things. Having said that, I have 2Gb RAM in one of my boxes, and it never uses Swap. The other one has 1Gb RAM, and only uses swap when re-encoding MythTV recordings.

--Ian
 
Old 07-17-2007, 02:28 AM   #12
qed2
LQ Newbie
 
Registered: Jun 2007
Distribution: slackware
Posts: 2

Rep: Reputation: 0
Suspend-to-disk.

Yes, I forgot. I use swap space for suspend-to-disk, too. That's one meaningful use of swap space.
 
Old 07-17-2007, 03:07 AM   #13
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
RAM is used because it's faster than storing stuff on disk. If you run out of RAM, your machine may start feeling ill unless it can store the stuff somewhere, when RAM is full. This is one place where SWAP comes into the picture.

In the past people had something like 12MB of RAM, and that was a lot. Nowadays a lot of people have 1...2GB. It might not be filled entirely, and as long as it is not, you don't need SWAP. I personally have 1GB SWAP space, but 95% of the time it's not used at all. Why do I need it then? Because I do heavy work at times, process huge image or video files and so on, and when I do, sometimes RAM just isn't enough. It doesn't mean it's 100% filled all the time and makes my life hell, but there are short times when it gets close or up to 100% full, and then it's just convenient to have SWAP. You could of course use a SWAP file too, instead of a partition, but for me it's just less hazzle to have a partition instead of a file.

1 or 2GB out of 250..500GB is like a drop in the ocean. If you start having so little free space that 1GB is "too much consumed for SWAP", you better buy a bigger harddisk - they're not that expensive nowadays. If your SWAP usage is 0%, you can be happy. And when you do one day run into trouble when your memory fills up for some odd reason, you're just thankful if you had that 512MB or 1GB of SWAP - it saves your day and your machine from freezing to death.

SWAP = 2 x RAM is just a thumb rule, like said. In the past, like I said, people had less RAM, so memory-consuming tasks did need more SWAP at times than there was RAM available. It takes time to explain this all for a complete newbie, and that newbie might not want to hear it at all, or might not remember anything about the long explanation. It's just easier done if somebody says "you need twice as much space for SWAP than you have RAM". 256MB was a good size for a SWAP partition when you had 128MB RAM and a disk of few gigabytes or less. If you nowadays have 8GB of RAM, I don't think it's wise to reserve 16GB for SWAP..well, unless you're working with a spacecraft in outer space, where it's Really vital.
 
Old 07-18-2007, 05:35 AM   #14
dasy2k1
Member
 
Registered: Oct 2005
Location: 127.0.0.1
Distribution: Manjaro
Posts: 963

Rep: Reputation: 36
i have 2G ram and 2G swap avalable.
i have only filled my ram once and used about 100M of swap...

if [ram>=1Gb]
then
swap=ram
else
swap=2*ram
fi
 
Old 07-18-2007, 05:46 AM   #15
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
The real formula is:

swap=max(installed RAM, total virtual memory your system will require one day - RAM);

Last edited by jlliagre; 07-18-2007 at 06:58 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need for SWAP with 1 GB RAM? Aleksandersen Linux - Newbie 36 02-26-2007 07:54 PM
Why using swap when RAM is available? MasterOfTheWind Linux - General 3 10-06-2006 12:45 PM
When SWAP and RAM are out syberdave Linux - General 6 01-07-2006 12:13 AM
Not using RAM and Swap much ? ruwach Linux - Hardware 2 06-11-2004 07:26 AM
Swap and RAM ? mikeshn Linux - General 1 09-18-2002 09:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration