LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why Swap=2 x RAM (https://www.linuxquestions.org/questions/linux-newbie-8/why-swap%3D2-x-ram-562877/)

diptanjan 06-19-2007 04:02 AM

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

acid_kewpie 06-19-2007 04:09 AM

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.

carl0ski 06-19-2007 05:10 AM

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

qed2 07-13-2007 08:46 PM

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.

Tinkster 07-13-2007 08:53 PM

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

Quakeboy02 07-13-2007 09:06 PM

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.

phantom_cyph 07-13-2007 09:20 PM

Its tradition. :-D

No, actually, I think it makes the system faster.

sundialsvcs 07-13-2007 09:22 PM

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.

synss 07-16-2007 01:46 AM

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.

theYinYeti 07-16-2007 02:00 AM

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.

IBall 07-16-2007 09:17 PM

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

qed2 07-17-2007 02:28 AM

Suspend-to-disk.
 
Yes, I forgot. I use swap space for suspend-to-disk, too. That's one meaningful use of swap space.

b0uncer 07-17-2007 03:07 AM

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.

dasy2k1 07-18-2007 05:35 AM

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

jlliagre 07-18-2007 05:46 AM

The real formula is:

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

IBall 07-19-2007 02:18 AM

Quote:

Originally Posted by jlliagre
The real formula is:

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

And seeing that the total virtual memory that you may need is always going to be unknown, we need rules of thumb to get a good approximation. :)

Of course, your formula is 100% correct though...

--Ian


All times are GMT -5. The time now is 10:30 PM.