Overclock.net banner

Linux swap necessary?

5.5K views 30 replies 18 participants last post by  Boyboyd  
#1 ·
I'm contemplating which GNU/Linux distro I'm going to install. Since I'm using MLC-based SSD disks, I've decided to keep the swap partition minimal and no more than 1536 MB this time, in order to avoid wearing out the cells. However, I was thinking, is swap really necessary when you have 8 GB RAM?
 
#4 ·
I remember someone asking this in my linux class, and afaik, it's best to run a system with a swap file equal in size to your ram, just to prevent any really bad system hangs under heavy load. If you never fill up your ram much though, I don't know how much it will be used since that is up to the kernel, but I don't think you should run without any swap at all.
 
#6 ·
Quote:
Originally Posted by ZHoob2004;11694850
I remember someone asking this in my linux class, and afaik, it's best to run a system with a swap file equal in size to your ram, just to prevent any really bad system hangs under heavy load. If you never fill up your ram much though, I don't know how much it will be used since that is up to the kernel, but I don't think you should run without any swap at all.
I've been paying a lot of attention to the system monitor in Ubuntu and I can't remember ever seeing it go over 0 bytes. Not even when I was boincing.

But that's with my current sig rig. On my laptops (512 MB and 1024 MB RAM), a swap partition is definitely needed.

So what you're saying is that I should create an 8 GB swap partition?
 
#8 ·
If on a desktop environment, you don't need more than 2GBs for swap, regardless of how much physical RAM you got. It really depends on what you plan to do on your machine.
 
#11 ·
this depends on you and what you do on the pc

i have installed ubuntu and mandriva since old days with 512mb ram without pagefile (swap), never had issues, but i do only basic stuff on linux

the same goes for windows, no pagefile for me, the only game that crashed for me was cod mw2
 
#12 ·
Windows will use a page file regardless of how much RAM is free. Linux does not. Linux uses SWAP when (and if) it is actually needed. If you plan to hibernate then you'll need at least as much SWAP as you have RAM, but otherwise put in something small and be done with it. You're unlikely to ever use even close to 8GB of RAM.
 
#14 ·
Greetz
Obviously if you hibernate you must choose your ram amount for swap. Excepting that 200MB is plenty. I run KDE with lots of processes and open windows (280 processes is avg) and I only have 2GB ram. My swap is almost never used and max ever was 67 MB. I have a laptop with 512MB and use a 300MB swap. Never a problem.
 
#15 ·
With an SSD card: no swap. Never. It's pointless.

Create a RAMdisk using /dev/shm as well, and make a RAMdisk that mounts to /tmp. This will allow you to compile to /tmp (RAM) instead of your SSD.

Swap will NEVER be used unless you're running a large virtual machine as well as a bunch of other programs on the host OS. I've tested this myself and found that I only used 2 MB of swap.

you should also change the 'swappiness' parameter on the kernel. I'm a bit drunk now so a quick google should give you the results
smile.gif
You basically echo 1 to swappiness (default is 60 in the current kernel).

Swappiness is a hot debate amonst kernel devs ATM.

TL;DR

DO NOT USE SWAP ON AN SSD. If you REALLY think you need it buy a cheap USB drive and create a swap partition there.

I would suggest using suspend to RAM, but if you must use hibernate then buy a cheap 8GB flash drive, create a swap partition, activate the swap, then add it to fstab.

Also you might want to mount an old hard drive to your Torrents/Downloads folder to prevent excessive read/write.

You should really use suspend to ram using pm-utils to suspend to RAM. Swap should NOT be used on an SSD. Ever. I can't stress this enough. The number of writes is just not worth it.
 
#16 ·
Quote:


Originally Posted by ZHoob2004
View Post

I remember someone asking this in my linux class, and afaik, it's best to run a system with a swap file equal in size to your ram, just to prevent any really bad system hangs under heavy load. If you never fill up your ram much though, I don't know how much it will be used since that is up to the kernel, but I don't think you should run without any swap at all.

That used to be the case before everyone had so much RAM (it used to be 2x your amount of RAM) and usually came out to be 1gig to 2gigs. Now it's still not necessary to go over that. I think I have a 1GB swap.

Quote:


Originally Posted by Jimi
View Post

It is required to have at least the amount of RAM you have in swap if you want to hibernate your computer.

Mine hibernates fine with a 1GB swap.
 
#17 ·
This used to be a pet peeve of mine - the idea that swap should be directly proportional to RAM.. It should be inversely proportional since the more ram you have the less swap you need. Also huge amounts of swap are needed more for Windoze since it leaks so badly with all the unresolved prefetch and what-not. Besides, they have a vested interest in their hardware partners so they can afford to be sloppy.

It is better to have more than to run out but the heaviest use I have ever seen on any machine by a user who did magazine layouts and web design professionally was still under 2Gigs on a Win2K machine. I have never seen any Linux install (other than an overworked server with 40+ workstations) use even 2Gig. ever. Home systems? Less than 1G tops.
 
#18 ·
I always keep a 256MB swap just in case. You never know what you may be doing or what could eat up your ram, though I have never had an issue.
 
#19 ·
Question on why you need swap for Hibernate: Is this just so the session is saved to the HDD? I never used a swap space when I had 4GBs of RAM and Sleep worked fine. However, I never saw a hibernate option in the various power menus either.

I just don't know though what you could possibly be running that would consume 8GBs of RAM though.
 
#20 ·
I have been experimenting with *nix as a DAW/recording studio - with limited success.

I would, personally, recommend keeping a swap-part.
 
#21 ·
Quote:
Originally Posted by enorbet2;11703776
This used to be a pet peeve of mine - the idea that swap should be directly proportional to RAM.. It should be inversely proportional since the more ram you have the less swap you need. Also huge amounts of swap are needed more for Windoze since it leaks so badly with all the unresolved prefetch and what-not. Besides, they have a vested interest in their hardware partners so they can afford to be sloppy.

It is better to have more than to run out but the heaviest use I have ever seen on any machine by a user who did magazine layouts and web design professionally was still under 2Gigs on a Win2K machine. I have never seen any Linux install (other than an overworked server with 40+ workstations) use even 2Gig. ever. Home systems? Less than 1G tops.
Mine too. Back in the days of 256MB people would swear by the formula 2-4X the amount of swap space. Nowadays if you think you need it 256MB will suffice.

I don't use swap: ever. It's pointless, and even harmful for SSDs.
Quote:
Originally Posted by Rookie1337;11704064
Question on why you need swap for Hibernate: Is this just so the session is saved to the HDD? I never used a swap space when I had 4GBs of RAM and Sleep worked fine. However, I never saw a hibernate option in the various power menus either.

I just don't know though what you could possibly be running that would consume 8GBs of RAM though.
Sleep is probably referring to suspend to RAM. MS and their ******ed nomenclatures. Why not S1,2.3, etc.? After all that is the ACPI standard....
 
#22 ·
Quote:
Originally Posted by binormalkilla;11708600
It's pointless, and even harmful for SSDs.
Dangerous? That's really exaggerating the impact, especially for Linux where SWAP is probably going to remain unused for the majority of the time.
 
#23 ·
Quote:
Originally Posted by binormalkilla;11708600
/Snipped:
Sleep is probably referring to suspend to RAM. MS and their ******ed nomenclatures. Why not S1,2.3, etc.? After all that is the ACPI standard....
Well I was actually talking about my experience in Linux there. I never really used sleep with Windows because I for some reason just never trusted it to be left alone for very long.
 
#24 ·
Quote:


Originally Posted by randomizer
View Post

Dangerous? That's really exaggerating the impact, especially for Linux where SWAP is probably going to remain unused for the majority of the time.

Why risk it? There is really no point in running a swap partition on an SSD.
 
#25 ·
Quote:


Originally Posted by binormalkilla
View Post

Why risk it? There is really no point in running a swap partition on an SSD.

Exactly, why risk it?

The worst it will be is just a couple of gigs of HDD space sitting there doing nothing. So its probably best to just keep a small swap space.

I would rather have 2gigs sitting there than to have my PC crash later on down the road and have to add one.
 
#26 ·
Quote:
Originally Posted by binormalkilla;11710369
Why risk it?
Because SWAP is slow, and it's much slower on a HDD. I'd prefer the lesser of the two evils... or more RAM.