Operating System - Linux
1753936 Members
10055 Online
108811 Solutions
New Discussion юеВ

Re: How much of a swap file do you need??

 
SOLVED
Go to solution
Stuart Browne
Honored Contributor

Re: How much of a swap file do you need??

Wow.. The swap behaviour of linux is pretty advanced.

Generally it will only swap out inactive processes.

If everything is active, then it's oldest segments.

It's best to use swap-file-systems instead of swap-file's for better performance.

You might want to read through the kernel-source documentation (/usr/share/doc/kernel-doc-*/vm/* in paricular), as well as the man pages for 'mkswap'.
One long-haired git at your service...
Andrew Cowan
Honored Contributor

Re: How much of a swap file do you need??

It's worth noting that Unix/Linux detects multiple swap/paging spaces and attempts to stripe data across them. This is designed not for resillience, but for performance, and if working correctly, balances IO. This is why your paging spaces should normally be of equal size. The one sin that you must NEVER commit is to place two or more paging areas on the same physical disk as your IO will go through the roof, and your performance in the direction of the toilet!
Wim Van den Wyngaert
Honored Contributor

Re: How much of a swap file do you need??

Good to read and know :
http://www.fiveanddime.net/ss/swap.htm

Wim
Wim
Stuart Browne
Honored Contributor

Re: How much of a swap file do you need??

(please note that the limits in that URL are based off of 2.2 kernels, not modern 2.4 or 2.6 kernels).
One long-haired git at your service...
Wim Van den Wyngaert
Honored Contributor

Re: How much of a swap file do you need??

Did some testing with RH kernel 2.6 on Alpha without a swap file to see how Linux reacts.

I was trying to eat all memory by executing script wim which contains :
sleep 1
bash wim

As a normal user : when free mem is 4 MB, the message "Resource temporarily unavailable" is given. Memory cache + buffers was hardly reduced in size. System cpu usage increased up to 7%.

As root : at 4 MB, the memory + buffer cache was slowly deactivated, consuming about 10% in system mode in the beginning, 90% system mode at the end. When it reached 2 MB memory cache, it started taking the 4 MB free memory. Then my telnet was aborted.

I restarted directly on the console to see how it ends. This time, a lot less system mode cpu was used (???). About 10%. But the script needed 15 seconds for 1 execution (when cache + buf were only a few MB).
When the cache reached 1 MB, it started doing something else. I guess pages were taken from processes because the buf + cache counter increased again. Script execution took already 1 min. Then oit started eating the 4 MB free memory but finally the session was killed.

In /var/log/messages I found "out of memory : killed process xxx".

The machine is still running.

What I find strange is that a normal user is refused memory while there is still a lot of cache that could be removed.

Wim
Wim
Wim Van den Wyngaert
Honored Contributor

Re: How much of a swap file do you need??

Same test with a swap file of 200 MB.
Ended with "too many open files" when swpd of vmstat reached 80 MB.

Wim
Wim