8

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?

HopelessN00b
  • 54,273
Bill Gray
  • 1,355

8 Answers8

15

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?

serverhorror
  • 6,538
4

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.

Kevin Kuphal
  • 9,194
4

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.

MarkR
  • 2,928
2

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.

Dustin
  • 199
2

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..
dbr
  • 1,588
1

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.

James
  • 627
0

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?

shylent
  • 820
0

I have an old server running with 4GB of RAM, and the swap on it is 4GB and a small amount of it gets used. Rarely, but it does get used. If you can't spare 4GB for the swap, I would upgrade the hard disk.