Tookmund / Swapspace

A fork of Jeroen T. Vermeulen's excellent dynamic swap space manager
GNU General Public License v2.0
128 stars 12 forks source link

Feature request: swap compression #25

Closed axet closed 4 years ago

axet commented 4 years ago

Hello!

I'd like to share an idea, which can be fun to have: swap files compression! I'm not talking about zram or Zswap but about swap files on compressed filesystems. Swapspace is an ideal candidat for that because it create's swap files dynamically and can handle additional actions to mount/unmount for compression purpose.

Idea is simple: create temp file in /var/lib/swapspace/swap.1 (as usual) but instead of running 'swapon /var/lib/swapspace/swap.1' do losetup, create file system with compression (zfs, raiser4, jffs2, btrfs) then mount it and create actual swap file inside this new mounted partition.

Maybe it is overkill, or maybe it is actually can improve performance on slow hdd systems.

chungy commented 4 years ago

Compression is incompatible with swap, and this is hard enforced by the kernel. Swap files cannot be copy-on-write (why they can't be used on ZFS, or default btrfs) nor can they be compressed.

zswap is what you really want for swap compression.

axet commented 4 years ago

If so, I should probably close the issue. Here is a guy claiming who using swap on network drive: https://unix.stackexchange.com/questions/347620/compressed-swapfile-without-zram-or-zswap

Tookmund commented 4 years ago

As @chungy said, you can’t use filesystem compression for swapfiles. We have to specifically disable compression for swapfiles on BTRFS to get swapspace working there (on Linux 5.0+).