Reading though virtual memory of redis documentation and redis.conf:

... specify an amount of RAM that's more or less between 60 and 80% of your free RAM.

Sounds simple enough: Dedicate majority of your RAM for redis process and rest will be automatically saved into redis swap file, no worries. Reality is not that simple.

What happens is that, linux kernel aggressively caches file contents and inodes to RAM for "perfomance" reasons. Redis server will start writing to swap file which will be kept in RAM for "performance" and redis process will lack regular RAM for its normal operation. As a result, portions of redis swap-file are kept inside the RAM and portions of redis process are swapped by system onto a disk. A major trashing and inversion of memory hierarchy.

Issue is that redis decided to use non-standard VM mechanism, and that is ok. But developers should have described a proper way to configure kernel for all of this to be possible.

For instance, I have 2.0G of RAM, and value vm-max-memory is set to 1500mb. When this memory fills up redis starts writing to swap file, and after a while, simple redis GET operation takes tens of seconds to complete.

In order to fix this problem, what needs to be done is to moderate VM settings of kernel. Firstly, you can increase tendency to reclaim memory by changing cache pressure: (I not sure about the exact values)

echo 200 > /proc/sys/vm/vfs_cache_pressure

Swappiness will reduce amount of pages that are swapped

echo 20 > /proc/sys/vm/swappiness

If you are in memory/trashing trouble and need to quickly reclaim some memory, issue this cmd:

sync; echo 3 > /proc/sys/vm/drop_caches

It is interesting that drop_caches is not really a kernel setting, but writing to it will send a signal/message the the kernel.

To summarize, I really like redis and what it is doing, but documentation is missing few relevant details regarding its virtual memory capabilites and it will not run smoothly unless kernel is compliant to the rules of redis.