12

Does it matter if the amount of a swap area in Linux was set too small (say 1Gb), and the main RAM is 128Gb?

Should we always set the amount of swap area to be twice the amount of RAM?

UPDATED:

Hi, thank all of you for replying this question. In fact, I have this question because we have encountered some problems when using a small cluster system. The problems are posted in Here. The following picture is some information about some of the computers in this small cluster.

information

The MEMTOT is the total amount of RAM of that machine, the SWAPTO is the total amount of SW AP area of that machine, and the SWAPUS is the used amount of SWAP area. As shown in the picture, the usage of SWAP is indeed small.

When trying to solve those problems posted in Here, we're not sure if the amount of SWAP area is set too small, which is just 1Gb relative to 128Gb, as shown in the picture. Thus, I have this question. I'm sorry I didn't post the whole background information in the original version of this post. Before that, we also thought that if the amount of RAM is large, we could set the amount of SWAP small. We tried to set the SWAP of c0148 to be 16Gb, the problem seems to be none (Maybe we should take this conclusion after observing their statuses for a long time).

We're not professionals on Linux system, and we couldn't explain why this happened. It is a probability that this is a cluster system, and the SGE is managing the resources of each machine, and it needs to have a relative large amount of SWAP because that machine may be used by many jobs submitted by many users.

In addition, if we just set the amount of SWAP too large, what other problems it would cause is also worthy considering.

mining
  • 233
  • 1
  • 11
  • 1
    If you have 128Gb of ram, and you start swapping - that system is probably way out of control and dead anyways. I, personally, would probably run that server without swap at all. The OOMKiller should take care of any runaway process before running out of memory causes a crash - and the crash is faster to fix anyways. – Ryan Gooler Feb 16 '15 at 18:21
  • @RyanGooler This will force linux to keep old data in RAM even if it has not been accessed since boot time. – Navin Feb 16 '15 at 20:13
  • 1
    Which would be - what? A few megs of stuff from init? Some cached memory that will be tossed as soon as something actually needs the ram? If your machine NEEDS to swap memory to function, its overloaded and needs to be scaled up anyways. – Ryan Gooler Feb 16 '15 at 22:55
  • Hi, @RyanGooler, thank you for replying. I've updated the post, if convenient, please check it. – mining Feb 17 '15 at 02:26
  • Hi, @Navin, thanks for replying. Indeed the machines are running for a long time since booting. I've updated the post, if convenient, please check it. – mining Feb 17 '15 at 02:27
  • 1
    @Ryan Gooler: If you're doing scientific simulations, a processes that uses 128 Gb or more is not unreasonable. – jamesqf Feb 17 '15 at 06:03
  • 1
    See [How much SWAP space on a high memory system?](https://serverfault.com/q/5841) – Martin Schröder Feb 17 '15 at 12:17
  • @MartinSchröder, thank you very much! The reference is very helpful! – mining Feb 17 '15 at 14:30
  • @MartinSchröder, I think the answers in the http://serverfault.com/questions/5841/how-much-swap-space-on-a-high-memory-system is exactly the information what I'm looking for. – mining Feb 17 '15 at 14:38
  • 1
    @RyanGooler True enough. My point is that increasing swap *can* allow programs to use up more physical ram. It's only a few MB but it's better than nothing :) – Navin Feb 17 '15 at 19:10

3 Answers3

19

The Linux kernel has a setting to control how often the swap is used, called swappiness, described at https://unix.stackexchange.com/questions/88693/why-is-swappiness-set-to-60-by-default.

A swappiness of zero means that the swap will be used only if the system runs out of memory. A swappiness of 100 forces programs to use swap instantly.

Tweak your system as you like it to behave, but having 128 GB of RAM is very unlikely that your system runs out of memory easily, so having 2 / 4 GB of swap could be enough. It's not advisable, but possible, to run a system without swap partition.

I think the rule of the swap area to be twice the amount of RAM is outdated, and is useful only on systems that are around 1 GB of RAM and are always on the edge of full RAM usage.

jcbermu
  • 17,278
  • 2
  • 52
  • 60
  • 2
    While setting `swappiness` to 0 seems logical with a large amount of RAM, it may be better to keep it as the default value of `60`: [http://unix.stackexchange.com/a/88820/50687](http://unix.stackexchange.com/a/88820/50687). – A.L Feb 16 '15 at 17:02
  • 1
    Is there some graph with swappiness form 0 to 100 on one axis and something else on the other to demonstrate how… the swappiness depends on the value? – user1306322 Feb 16 '15 at 20:53
  • Hi, @jcbermu, I've updated the post, if convenient, please check it. – mining Feb 17 '15 at 02:27
5

I believe the 2x rule of thumb is outdated. Our workstations have 16GB ram, we typically only use around 25% of that and hardly use over 50%. So for our purposes, we don't use any swap.

Since you have to decide how much swap to create, and it's theoretical that any number you choose will not be enough at some point, then why not choose 0? Or - why not just install more RAM?

I believe this is a very personal decision based on how your computer will be used and how much RAM it has.

gjcamann
  • 159
  • 2
  • Hi, @gjcamnn, thank you for replying. I've updated the post, if convenient, please check it. – mining Feb 17 '15 at 02:28
0

Unless you are going to perform some memory consuming calculations, you don't need swap at all (but is better to have small swap partition). But having swap > ram is needed when you are going to use suspend to disk.

ustp
  • 11