Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

On my SBCs and VPSs I use a cache-heavy zram setup with LZ4 and `vm.page-cluster=0` being the most important changes to the default, and cache pressure and swappiness both to 200 off the top of my head, and things like only doing foreground IO when the background write buffer is full. This type of swapping is fast, and is easy on the CPU, and gives a lot of extra disk cache on this type of low performing storage. I disable disk schedulers because they haven't been necessary and would just add overhead.

This means there's a lot of available RAM capacity, that there's a hefty read cache to avoid the SD card, that when there are disk writes on writable storage it can still read from it, and with the lack of clustering and the speed of decompression there's no swapping lag whenever a page needs to be swapped back. This swap early, swap often is the complete opposite of the OOM-prevention swapping you used to use on disks, which was slow and interrupted IO whereas LZ4 in RAM is fast and doesn't interrupt IO.

I have been using this setup since 2022 and have not had any issues but I don't compile anything on those setups, though I see no reason why it would not be safer than compiling without zram at all.



could you please write a ELI5 guide that I could follow on my tiny VPS? It's debian-based. Thanks!


Of course! Just touching these files should be everything you need:

  /etc/sysctl.d/99-240716-vm.conf
  vm.dirty_background_ratio = 1
  vm.dirty_ratio = 100
  vm.page-cluster = 0
  vm.swappiness = 200
  vm.vfs_cache_pressure = 1
dirty_background_ratio = starts background writing when it's at least 1% of available mem; dirty_ratio = starts force writing when all avail (not total) ram is full; page-cluster = swap in only what's needed; swappiness = lower means swapping is expensive higher signals swapping is cheap; vfs_cache_pressure = lower keeps more dentries and inodes in memory.

  /etc/udev/rules.d/99-240716-ioschedulers.rules
  ACTION=="add|change", KERNEL=="mmcblk[0-9]*|nvme[0-9]*|sd[a-z]*", ATTR{queue/scheduler}="none" 
Removes schedulers from typical local writeable storage.

  /etc/systemd/zram-generator.conf
  [zram0]
  zram-size = ram
  compression-algorithm = lz4
Might have to install systemd-zram-generator if it doesn't already exist.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: