How to prevent going to SWAP?

We have a critical application which uses pretty much of our RAM memory. At most time the application stays in RAM, however there are some situation (e.g. when some other applications and deamons start using more RAM) which make it going to SWAP meaning that our application starts to respond very slowly.

Are there any ways we could prevent our application from going to SWAP?

Thanks guys!


Turn off swap, or use mlockall() to prevent process memory from being swapped out. There are process and system limits though of how many pages can be locked, which may need to be adjusted for your purposes.


Have a look here. By echoing a value between 0 and 100 to /proc/sys/vm/swappiness, you can control the eagerness of swapping (0 being not very eager, while 100 is very eager).


You need to fix the underlying reason you're going to swap in the first place. That means tuning your app or adding RAM. Swapping is the symptom, not the problem - incorrect hardware sizing for your app (or a badly tuned/architected app) is the problem.