r3b311i0n / systemd-swap

Script for creating hybrid swap space from zram swaps, swap files and swap partitions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

systemd-swap

Script to manage swap on:

  • zswap - Enable/Configure
  • zram - Autoconfigurating for swap
  • files - (sparse files for saving space, supports btrfs)
  • block devices - auto find and do swapon

ℹ️ It is configurable in /etc/systemd/swap.conf.

Additional terms:

  • SwapFC (File Chunked) - provides a dynamic swap file allocation/deallocation

File location

/etc/systemd/swap.conf
/usr/lib/systemd/system/systemd-swap.service
/usr/bin/systemd-swap

Please don't forget to enable and start with

sudo systemctl enable --now systemd-swap

Install

  • Arch: in the community.

  • Debian

    git clone --depth=1 https://github.com/Nefelim4ag/systemd-swap.git
    cd systemd-swap
    make deb
    sudo dpkg -i systemd-swap_*_all.deb
  • Fedora

    git clone --depth=1 https://github.com/Nefelim4ag/systemd-swap.git
    cd systemd-swap
    FEDORA_VERSION=f32 make rpm
    sudo rpm -U systemd-swap-*noarch.rpm
  • CentOS

    git clone --depth=1 https://github.com/Nefelim4ag/systemd-swap.git
    ./systemd-swap/package.sh centos
    sudo rpm -U ./systemd-swap/systemd-swap-*noarch.rpm
  • Manual

    git clone --depth=1 https://github.com/Nefelim4ag/systemd-swap.git
    sudo make install
    
    # or into /usr/local:
    sudo make prefix=/usr/local install

About configuration

Q: Do we need to activate both zram and zswap?
A: Nope, it's useless, as zram is a compressed RAM DISK, but zswap is a compressed "writeback" CACHE on swap file/disk. Also having both activated can lead to inverse LRU as noted here

Q: Do I need to use swapfc_force_use_loop on swapFC?
A: Nope, as you wish really, native swapfile should work faster and it's safer in OOM condition in comparison to loop backed scenario.

Q: When would we want a certain configuration?
A: In most cases (Notebook, Desktop, Server) it's enough to enable zswap + swapfc (on server tuning of swapfc can be needed). If you use a SSD and care about flash memory wear, use only ZRam.

Q: Can we use this to enable hibernation?
A: Nope as hibernation wants a persistent fs blocks and wants access to swap data directly from disk, this will not work on: swapfc (without some magic of course, see #85).

Note

  • ℹ️ Zram dependence: util-linux >= 2.26

  • ℹ️ If you use zram not for swap only, use kernel 4.2+ or please add rule for modprobe like:

    options zram max_devices=32

Switch on systemd-swap:s automatic swap management

  • Enable swapfc if wanted (note, you should never use zram and zswap at the same time, read more here)

    vim /etc/systemd/swap.conf
    zram_enabled=0
    zswap_enabled=1
    swapfc_enabled=1
  • Stop any external swap:

    sudo swapoff -a
  • Remove swap entry from fstab:

    vim /etc/fstab
  • Remove your swap

    # For Ubuntu
    sudo rm -f /swapfile
    
    # For Centos 7 (if using a swap partition and lvm)
    lvremove -Ay /dev/centos/swap
    lvextend -l +100%FREE centos/root
  • Remove swap from Grub:

    # For Ubuntu remove resume* in grub
    vim /etc/default/grub
    
    # For Centos 7 remove rd.lvm.lv=centos/swap*
    vim /etc/default/grub
    
    # For Manjaro remove resume* in grub & mkinitcpio
    vim /etc/default/grub
    vim /etc/mkinitcpio.conf
    # For Ubuntu
    update-grub
    
    # For Centos 7
    grub2-mkconfig -o /boot/grub2/grub.cfg
    
    # For Manjaro
    update-grub
    mkinitcpio -P

About

Script for creating hybrid swap space from zram swaps, swap files and swap partitions.

License:GNU General Public License v3.0


Languages

Language:Shell 87.4%Language:Makefile 12.6%