Linux – the appropriate value of vm.swappiness when using zram

linux-kernelmemoryramswapzram

I'm using zram on my computer as a compressed RAM-backed swap. When the system needs to swap something out, swapping it to a zram-backed swap file is more or less equivalent to compressing that data in-memory to free up space. This makes swapping very fast most of the time, relative to disk-backed swap. Because of this, I wonder if there is some performance to be gained by encouraging the system to swap out unused stuff more aggressively, since it can do so without actually hitting the disk?

So has anyone messed around with, say, setting vm.swappiness to 100 while using zram? Would this be desirable?

sysctl -w vm.swappiness=100

Best Answer

Short answer:vm.swappiness=100is appropriate value for zram(At least on Debian Stretch with Linux 4.9 , I believe that is best value )

I already test vm.swappiness=100 for me.

I think you can do some simple test to sure which value is best for you.

Also I made another simple program for test this question. x On my machine a very low vm.swappiness value(such as vm.swappiness=1 ) will cause obvious responsiveness problem.

About SwapCached in /proc/meminfo:

First,try vm.page-cluster=0,this maybe can reduce some useless SwapCached from swap-in.

SwapCached can speed up zram same as non-zram swap device

SwapCached is can reuse(free) when necessary:

./linux-4.9/mm$ grep -rn delete_from_swap_cache
memory-failure.c:715:   delete_from_swap_cache(p);
shmem.c:1115:       delete_from_swap_cache(*pagep);
shmem.c:1645:            * unaccounting, now delete_from_swap_cache() will do
shmem.c:1652:               delete_from_swap_cache(page);
shmem.c:1668:       delete_from_swap_cache(page);
vmscan.c:673:       __delete_from_swap_cache(page);
swap_state.c:137:void __delete_from_swap_cache(struct page *page)
swap_state.c:218:void delete_from_swap_cache(struct page *page)
swap_state.c:227:   __delete_from_swap_cache(page);
swapfile.c:947:         delete_from_swap_cache(page);
swapfile.c:987: delete_from_swap_cache(page);
swapfile.c:1023:            delete_from_swap_cache(page);
swapfile.c:1571:            delete_from_swap_cache(page);
./linux-4.9/mm$