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.

Here are Munin's diagrams.

Memory usage: http://koryagin.com/w/q/memory-day.png

Swap in/out: http://koryagin.com/w/q/swap-day.png

Why does Linux decide to increase cache and use swap when the RAM size is much bigger than the memory used by programs?

share|improve this question
2  
The linux VM subsystem in the past few years has been very much tuned to favor buffer space and cache space; applications taking up memory but not doing anything will get shuffled to disk. This increases responsiveness and performance. Unless you're seeing performance issues you really shouldn't need to worry about it. –  Bart Silverstrim Sep 2 '11 at 11:02
add comment

2 Answers

up vote 15 down vote accepted

Your server probably has some memory-eating and/or inactive processes having many inactive pages. Linux kernel prefers to swap out inactive portions of programs to swap since most likely the memory is better used as cache.

If you wish to change this behaviour, play with vm.swappiness sysctl tunable but be warned, outsmarting the kernel developers / distro maintainers is not that easy. :-)

Are you having performance problems on your server during that swap spike or did you ask out of curiosity?

share|improve this answer
    
I have no performance problems at this particular server. But at another one, where the situation is not so clear, I'm thinking about what to do. Can't some Linux memory managemnent logic be the reason for PHP-FPM segfaults, if they doesn't match any of the known PHP problems? So, generally in favor of curiosity. –  Pavel Koryagin Sep 2 '11 at 11:23
    
BTW, this server intensively handles a very few amount of data with a fixed set of scripts, so it should not have intensive I/O. So why does Linux want to have such big cache? –  Pavel Koryagin Sep 2 '11 at 11:26
    
Linux heavily caches files, file metadata, directory entries and so on. Try out command slabtop. –  Janne Pikkarainen Sep 2 '11 at 11:34
    
Thanks a lot. It'll take a while to understand what to do with slabtop info. –  Pavel Koryagin Sep 2 '11 at 11:49
    
Let that run full-screen when your boss walks past your cubicle and make yourself a guru in his/her eyes. :-) Another nice "ooh, that sure looks hard to understand" command is systat -vmstat in FreeBSD (probably other BSDs too). –  Janne Pikkarainen Sep 2 '11 at 12:08
add comment

You should try to play with swappiness parameter. As you can see your system started to swap when it tried to increase file cache size, this is normal if swappines is not 0.

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.