How to prevent going to SWAP?
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).