Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a core 2 laptop with 4gb of ram. I use the machine for browsing, network stuff and simple programming. (I use this machine to host a small ftp and web server semi-occasionally.)

Would there be any benefit to having a swap partition? My understanding is that with that much memory, there would be no need to have a swap for my mediocre usage. In fact, the kernel will be forced to use my ram, which will be faster.

Is this correct?

share|improve this question
1  
related question ... serverfault.com/questions/19007/… –  tomjedrz Jun 9 '09 at 21:42
    
also related question serverfault.com/questions/5841/… –  Avery Payne Jun 10 '09 at 6:15
    
Also related: serverfault.com/questions/352431/… –  chutz Nov 6 '12 at 20:47
add comment

7 Answers 7

Do I need a swap partition?

You need a swap partition (not a swap file) to send your workstation to sleep.

How can I force the kernel not to use swap?

sysctl vm.swappiness=0

On another note: How is that related to server administration?

share|improve this answer
    
But as far as performance goes, it makes no difference? –  Bill Gray Jun 9 '09 at 21:47
2  
There might be a slight overhead when activating swap but nothing you could measure as long as you don't use the swap. No need to measure if you use it, since you can go off have a cup of coffee (or two). If you really start using it you'll notice :) –  Server Horror Jun 9 '09 at 21:50
2  
Not really, but given todays storage prices you'll probably want some swap anyway (just stay with the default of you distro install if you don't know how much). You'll save yourself some headache if at some point you are starting a huge SQL query (or something similiar) and run into the OOM killer just because of that. On the other hand for that purpose you could always simply use a swap file. –  Server Horror Jun 10 '09 at 1:39
1  
You mean hibernate, sleep is ACPI and doesn't touch the disk. –  LapTop006 Jun 20 '09 at 10:47
1  
You are right it won't to quote LWN: swap_tendency = mapped_ratio/2 + distress + vm_swappiness - disabling swap is a lot easier by simply removing all swap space. I'm opinionated and unless you know what you're doing you should have a swap partition (I don't pretend to know so I have swap on all my machines set up, just in case) –  Server Horror Jun 10 '11 at 18:35
show 2 more comments

There is benefit. Whether you need it is up for debate. At a minimum, swap gives you a safety net in case something happens that is unexpected. Your system will swap instead of starting to have programs crash or killed from OOM.

share|improve this answer
2  
OOM will come into play regardless of swap. It's just that with swap it happens later. –  Server Horror Jun 9 '09 at 21:46
    
What is the benefit aside from risk management? –  Bill Gray Jun 9 '09 at 21:46
    
With swap though the sluggishness and disk thrashing will be a sure sign that things are going south –  Kevin Kuphal Jun 10 '09 at 3:11
add comment

Suspend-to-disc also requires enough swap to save the contents of memory into (it might use compression depending on settings and version).

As it's a laptop, you may want to use suspend-to-disc.

share|improve this answer
add comment

In fact, the kernel will be forced to use my ram, which will be faster. ?

Maybe, most likely no - modern operating systems are intelligent (well, sane) about using available RAM - even old ones are pretty good. On all the linux machines I've used, the swap count stays at 0 bytes until it's required - there's no reason the OS would use swap unless it's forced too..

The issue only arrises when you run out of physical memory..

  • Without any swap-space, the system tends to freeze for a few minutes, the OOM-killer (out-of-memory) kicks in and starts killing processes until there is enough free memory for the main bits of the system to function..
  • With swap-space, the application that's caused the swap'ing might slow down a bit (a good indication it's reaching the physical memory limitations), and.. nothing, it just carries on..
share|improve this answer
add comment

No. If for some reason you later decide you have to have swap you can create a file and tell the OS to use that file on your file system for swap space.

share|improve this answer
add comment

Think of an application's working set as comprising two parts: the data it is holding in its own address space and the data it is accessing from files. The first must be held in RAM or in swap for correctness, the second can be correctly retrieved from disk or fileserver and need only be cached in RAM for performance.

Apologies that I have no empirical evidence for this, but I have always assumed that there is a performance benefit from being able to page out data in the first category that's no longer part of the working set so that less data from the second category need be fetched from disk or network.

share|improve this answer
add comment

In essentiality, what swap gives you is protection against burst memory consumption - if some application of yours decides to allocate too much memory for your system's good (memory consumption approaches total available memory), what you are going to get is termination of the said application or (best case) or termination of other applications (not good at all), either way, in 99% cases, the application will not get to do whatever it was going to do. With swap, there is a possibility, that the said application will do whatever it intended to do, release the memory and the normal operation will be resumed. With no swap there is no such possibility. Can you really not spare 4Gb of your hard drive for swap? We definitely DO have swap enabled on our systems even though they have at the very least 32Gb RAM.

Generally, what is your problem with swap? The only "real" downside I see is, that you are shaving some gigabytes off of your usable disk space, but thats all there is about it. Or am I missing something?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.