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.
 
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.
 
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...
 
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.
 
Make swap. The OOM killer might not do what you expect.
 
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
 
My swap has been empty, but I like having a safety net. A little hard drive space is cheap.
 
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.
 
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? ;)
 
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.
 
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?

=)
 
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).
 
You want to really muck with the system, make a swap partition out of physical memory.

:D
 
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.)
 
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.
 
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.
 
I just deployed a centOS file server with no swap. All seems to be well, but I'll post if anything breaks :)
 
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.
 
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.
 
It's nice that you can use a swap file now rather than having to use up a precious primary partition.
 
Back
Top