LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Does the Swap>=RAM rule still hold? (http://www.linuxquestions.org/questions/linux-newbie-8/does-the-swap-%3Dram-rule-still-hold-4175443346/)

educateme 12-29-2012 03:42 AM

Does the Swap>=RAM rule still hold?
 
It's almost 2013, and it's pretty common to get a notebook that comes with 8 GB RAM. Do I still need a Swap space >= amount of RAM, i.e. at least 8 GB of swap space as mentioned in forums of the past? And what exactly is this suspend-to-disk feature that apparently requires the Swap>=RAM rule?

Wim Sturkenboom 12-29-2012 04:41 AM

If your laptop goes to sleep, the whole memory will be stored in swap till you wake up the machine after which it can continue where it was. So yes, for a laptop with 8GB mem, 8GB swap is definitely recommended if you want it to sleep.

It also depends on the type of applications. E.g. video editing seems to be a memory hog so swap might still be a good idea.

educateme 12-29-2012 07:02 AM

OK, 8 GB of swap then. Thanks!

rknichols 12-29-2012 08:32 AM

Quote:

Originally Posted by Wim Sturkenboom (Post 4858922)
If your laptop goes to sleep, the whole memory will be stored in swap till you wake up the machine after which it can continue where it was. So yes, for a laptop with 8GB mem, 8GB swap is definitely recommended if you want it to sleep.

The nomenclature is sometimes inconsistent, but "sleep" mode commonly refers to "suspend to RAM" and keeps the memory powered up and refreshed. It doesn't make use of swap, but does use a small amount of battery power. It's "hibernate" mode, aka "suspend to disk", that needs the swap space.

Resuming from sleep mode is very fast. Recovery from hibernation takes roughly as long as booting (the more memory you have, the longer it takes to load it from disk), but the advantage over booting is that you get your desktop and open applications back in the same state you left them.

jefro 12-29-2012 10:37 AM

There are still a lot of older programs that may use swap. The best choice is to use real ram if available. In most cases it doesn't hurt to have a swap. Many people just have it in case.

DavidMcCann 12-29-2012 11:47 AM

I've run a computer without swap and had no complaints.

As RKN says, hibernating doesn't save time these days. It used to be much quicker than booting, but as memory got bigger so recovery from hibernation got slower; meanwhile, booting got faster, with things like systemd and upstart. (Of course, our CentOS systems still do it the old way.)

jpollard 12-29-2012 01:23 PM

systemd is overrated for start times. Slackware boots just as fast, and more reliably as systemd allows things to happen out of order.

ntubski 12-30-2012 08:31 AM

Quote:

Originally Posted by jefro (Post 4859066)
There are still a lot of older programs that may use swap.

What? Programs don't use swap, they just ask the kernel for memory. The kernel decides when to use swap or RAM.

jefro 12-30-2012 10:25 AM

Search on the subject and discover that swap may be used on some instances even if enough ram existed.

Thad E Ginataom 12-30-2012 10:53 AM

Swap is often used when there is plenty of free memory. It's a place to put stuff that has just been used and might be used again soon, but (despite not being a developer <Blush>) the wheres and hows of memory management, surely, remain a kernel function. The stability of the system depends on this.

This has been my understanding of *nix philosophy ...but hey, if I'm wrong it won't be the first time.

TobiSGD 12-30-2012 12:21 PM

Quote:

Originally Posted by Thad E Ginataom (Post 4859560)
It's a place to put stuff that has just been used and might be used again soon

Exactly that type of stuff does not get into swap. But you are right, sometimes swap is used even if you have plenty of free RAM, for a simple reason. If a program that is running was not used for a long time it may be possible that the memory of this program will be swapped out to make more room for caching. This can speed up the system, but comes with the downside of longer loading times when you want to use that application again.

Also, having swap-space can come in handy if you make excessive use of tmpfs mounts, since tmpfs can be swapped out.

ntubski 12-30-2012 01:40 PM

Quote:

Originally Posted by jefro (Post 4859541)
Search on the subject and discover that swap may be used on some instances even if enough ram existed.

But use of swap doesn't have to do with whether it's an older program or not, right? Unless by "older program" you meant a program that started running a long time ago...

jefro 12-30-2012 06:10 PM

I made a very large assumption that may not be fully correct. From what I have seen, the older programs are more likely to do that. I didn't test every program and situation so I could be wrong.

NyteOwl 12-30-2012 06:17 PM

Note that if you plan on using the machine for development and are at risk of causing a core dump, then making swap at least twice memory is a decent idea as the core dump will not only include the current memory contents but a lot of debugging info as well - and it gets dumped to the swap space. As disk space is relatively cheap, why not leave a safety margin.

Thad E Ginataom 12-31-2012 02:43 AM

Quote:

Originally Posted by TobiSGD (Post 4859610)
Exactly that type of stuff does not get into swap.

It's been quite a while, so with a big If I remember correctly, the system with which I used to earn my living up to a decade ago, AIX, made extensive use of swap for keeping copies of executed programs, in case required again. It's quicker than getting it from the file system again.
Quote:

But you are right, sometimes swap is used even if you have plenty of free RAM, for a simple reason. If a program that is running was not used for a long time it may be possible that the memory of this program will be swapped out to make more room for caching. This can speed up the system, but comes with the downside of longer loading times when you want to use that application again.
And you are right that this is the more standard reason for swapping out programs.

I'm a beginner ...but for the second time around. I find revising and relearning these basics from threads such as this invaluable :)


All times are GMT -5. The time now is 05:20 AM.