Do We Really Need Swap?

Carlosinfl

Loves the juice
Joined
Sep 25, 2002
Messages
6,633
I have noticed that since I have used Linux since 2003, I have never ever utilized Swap partitions. Maybe I am dead wrong and I have not realized I was but whenever I view system resources, I never see anything utilzing all my system RAM to the point I need to dump data into Swap. Is this an force of habit back from when 16MB's of RAM was available? Now that most people can pick up 4 + GB's on a laptop or low end PC, do we still need to create useless partitions for Swap? Perhaps I am being ignorant in thinking most modern (2001+) systems don't need to use Swap but I myself just have never seen Swap being utilized or found a need to create this partition.
 

criccio

Fully Equipped
Joined
Mar 26, 2008
Messages
13,976
In the Windows section of the forum, the argument comes down to that certain applications utilize the swap/page file regardless of available RAM for whatever reason. Turning it off can lead to some pretty serious errors with some apps.

If this holds true with Linux at all I don't know, I just thought I would throw that out there.
 

Carlosinfl

Loves the juice
Joined
Sep 25, 2002
Messages
6,633
I understand what you're saying and also don't know if this is also the case in Linux however I just don't see why an application would require a swap partition if I have 4GB's of un-used RAM just sucking power on the system itself. Doesn't make sense to me yet...
 

RCGodward

Gawd
Joined
Oct 7, 2004
Messages
667
I quit making a swap partition on my Gentoo installs a few years ago. AFAIK I haven't had any problems.
 

keenan

2[H]4U
Joined
Aug 5, 2009
Messages
2,695
In the Windows section of the forum, the argument comes down to that certain applications utilize the swap/page file regardless of available RAM for whatever reason. Turning it off can lead to some pretty serious errors with some apps.

If this holds true with Linux at all I don't know, I just thought I would throw that out there.

The whole idea of swap is supposed to be completely transparent to the application. It's part of the operating system's memory management, and it's a bit boggling that this would pose issues on Windows. Applications should definitely not be touching or managing swap themselves, though hinting to the OS what should be kept in RAM would make sense. Anyway, I'm surprised this is still a problem.

The question asked: no this is absolutely not an issue with *nix. You're perfectly safe running without swap, though with the obvious caveat that when you run out of memory, you're out of memory. Of course this will happen if your swap is undersized or the machine overutilized too. So just make sure you have enough memory (physical & swap) for your applications and you'll be fine.
 

ameoba

Supreme [H]ardness
Joined
Jan 9, 2001
Messages
6,413
Make swap. The OOM killer might not do what you expect.
 

djBon2112

Supreme [H]ardness
Joined
Jul 29, 2006
Messages
5,279
I've run plenty of Linux machines without any swap (and between 2 and 4GB RAM), and I've never had a problem.
Posted via [H] Mobile Device
 

Langford

[H]ard|Gawd
Joined
Apr 5, 2006
Messages
1,339
My swap has been empty, but I like having a safety net. A little hard drive space is cheap.
 

Recursion

Weaksauce
Joined
Oct 17, 2009
Messages
64
I have 8gb of ram in my system, as a kernel dev I use many vm's. I almost use my swap space hourly. I go through 8gb of memory like nothing.


You need the swap or backing store to hold context, when there is no memory left. So it all falls upon your usury habits. I am a big user of memory, so I use my swap space a lot, even with 8gb of ram. You may not use memory all too much, so you may not need one.


Thogh its safer to have and not need than need and not have.
 

The_Mage18

[H]ard|Gawd
Joined
Jul 31, 2004
Messages
1,712
Swap isn't just for memory space for applications or paging unused file/app components, it's also used for kernel errors. In the event of a kernel panic or daemon crash, the kernel dumps the memory contents to the swap file before halting or rebooting. When the system reboots, the page file contents are checked during boot and any crash data moved to a core file. The cores are usually placed in / and are usually hefty in size.

This is why many distro installers prompt for a swap size that matches the amount of RAM in your system. The general golden rule is RAM x 1.5 for your swap to make sure the current memory contents can be dumped along with any daemon or app data dumps and still have some left for general use.

Basically, if you don't care to find out why your system came to a screeching halt or rebooted on you for some wierd reason, don't make a swap file. Seriously though, is a few GB of hard drive space really worth not having some extra breathing room? ;)
 

venm11

2[H]4U
Joined
Oct 6, 2004
Messages
2,236
You may need swap despite ample memory simply because of how the application (or OS) handles not being able to allocate the memory it needs. Does it crash, does it malfunction? Or do you get an out-of-memory error of some kind, and can the app recover and function normally?

Conversely, I've seen some apps in windows fail [apparently] because they cannot allocate actual physical memory despite ample virtual space. It might be in that case that windows is unable to satisfy all the applications running, I never really investigated it enough.
 

Malakai

2[H]4U
Joined
Dec 29, 2001
Messages
2,124
All I say to this is, why not have one? I make a 4gb swap partition/page file no matter what; its not like I need the hdd space, it costs nothing to make, causes absolutely no performance hit, but could possibly break something for not being there.

So with no drawbacks and a few possible benefits, I say again, why not?

=)
 

Andrew_Carr

2[H]4U
Joined
Feb 26, 2005
Messages
2,349
I haven't run Linux without swap, but I did run Windows XP for awhile without a swap file and only 2GB of RAM. If I had firefox open with a lot of tabs and was gaming at the same time then sometimes the game would crash due to insufficient memory. I never had the issue, iirc, when just running a game. It freed up a decent amount of hard drive space, which was why I did it(was running low on space and I wanted to wait until I had more options than paying 120-150$ for a 500GB hard drive).
 

XOR != OR

[H]F Junkie
Joined
Jun 17, 2003
Messages
11,549
You want to really muck with the system, make a swap partition out of physical memory.

:D
 

HHunt

Supreme [H]ardness
Joined
Apr 12, 2001
Messages
6,063
You want to really muck with the system, make a swap partition out of physical memory.

:D

For extra fun, make it huge and allocate-on-demand. :D
(Something will die messily, but I'm not entirely sure what will go first.)
 

venm11

2[H]4U
Joined
Oct 6, 2004
Messages
2,236
I haven't run Linux without swap, but I did run Windows XP for awhile without a swap file and only 2GB of RAM. If I had firefox open with a lot of tabs and was gaming at the same time then sometimes the game would crash due to insufficient memory. I never had the issue, iirc, when just running a game. It freed up a decent amount of hard drive space, which was why I did it(was running low on space and I wanted to wait until I had more options than paying 120-150$ for a 500GB hard drive).

Yes, in a scenario where you know you're not going to need it, it's somewhat better not to. It will free up space (esp if you were using a minimum or permanent swap), and often it will improve performance because general hard drive use isn't competing with windows' "pro-active" use of virtual memory.

I remember that guy from corsair and his pitch of how much 6gb was improving performance on systems that only needed 2gb, because (in part) of the way windows swapping was tuned. Had they just turned off swap they'd have had the same benefit.
 

keenan

2[H]4U
Joined
Aug 5, 2009
Messages
2,695
Windows XP is way to aggressive about writing pages to disk and flushing them from RAM, which is often incredibly annoying. Maximizing an application takes ages as the whole thing is pulled back from disk and so on. However Vista and 7 improve this and it's not really a big deal anymore. I wonder if they're not fairly aggressive about keeping hiberfil.sys or something similar up to date though, as hibernating is much faster than it should be.
 

Darakian

Supreme [H]ardness
Joined
Apr 12, 2004
Messages
4,698
I just deployed a centOS file server with no swap. All seems to be well, but I'll post if anything breaks :)
 

Carlosinfl

Loves the juice
Joined
Sep 25, 2002
Messages
6,633
I have done enough research on this issue since I have asked here and realized that it 'does' matter to some degree. I see many applications on my server do page the swap memory and it it's not there, it moves to physical RAM. Not having it wont hurt anything but I do see applications cater to swap files.
 

Foxcow

2[H]4U
Joined
Jul 13, 2002
Messages
3,238
Swap isn't just for memory space for applications or paging unused file/app components, it's also used for kernel errors. In the event of a kernel panic or daemon crash, the kernel dumps the memory contents to the swap file before halting or rebooting. When the system reboots, the page file contents are checked during boot and any crash data moved to a core file. The cores are usually placed in / and are usually hefty in size.

This is why many distro installers prompt for a swap size that matches the amount of RAM in your system. The general golden rule is RAM x 1.5 for your swap to make sure the current memory contents can be dumped along with any daemon or app data dumps and still have some left for general use.

Basically, if you don't care to find out why your system came to a screeching halt or rebooted on you for some wierd reason, don't make a swap file. Seriously though, is a few GB of hard drive space really worth not having some extra breathing room? ;)


Word. Good info.
 

LstBrunnenG

Supreme [H]ardness
Joined
Jun 3, 2003
Messages
6,677
It's nice that you can use a swap file now rather than having to use up a precious primary partition.
 
Top