Boston Linux & UNIX was originally founded in 1994 as part of The Boston Computer Society. We meet on the third Wednesday of each month at the Massachusetts Institute of Technology, in Building E51.

BLU Discuss list archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] to swap or not swap

Did you want to have a discussion about swapping?

Everyone would agree, you should always avoid swapping unless the memory requirement of some job exceeds the maximum ram you can put into your system, or unless it's a one-off job, or you simply don't care if it takes 100 or 1000 times longer than necessary, and nothing else in the system matters.

I've certainly seen machines start swapping some active processes, and they become totally unresponsive.  Ssh got swapped out, and can't get enough CPU share to respond to a login request before the client times out.  You were lucky that you already had a logged-in terminal sitting there, and you can still "ls" because that was super hot in the cache and hasn't been expunged yet, but if you type "top" or "ps" or something that was already ejected from cache, then your prompt simply hangs indefinitely, as long as the runaway process is still active in swap memory.

Some people would suggest disabling swap entirely, but I don't believe that's best.  When you allow your system to have a small amount of swap (say 1G) then the kernel is able to swap idle processes and dead/zombie processes, making more room for cache & buffers & other stuff, which improves performance.  By keeping the swap small, you limit the length of time that you get crushed, in the event a process accidentally runs away and gobbles memory incessantly.  With 512M or 1G of swap, usually a runaway process will cause your system to utterly suck for a couple of minutes before the runaway process dies and things return to normal.

This latter argument doesn't carry a lot of value.  If you login to some long-running existing system you have, and check "top" or "free" you'll see some amount of swap space consumed, usually non-zero, but usually pretty small anyway.  Say 10M or maybe 100M.  So the real truth is, there's not much memory to gain by swapping out the dead/idle processes.  "Yay, I've effectively increased my 16GB system to 16GB & 10MB."  But I still recommend adding a small amount of swap to systems.

BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!

Boston Linux & Unix /