systemd-swap
â ī¸ Current code quality and commit frequency is low â ī¸
systemd/zram-generator since zram should be enough in most systems
Users should migrate toScript 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
/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 Linux: in the community repo.
-
git clone https://github.com/Nefelim4ag/systemd-swap.git cd systemd-swap make deb sudo apt install ./systemd-swap_*_all.deb
-
sudo dnf copr enable zeno/systemd-swap sudo dnf install systemd-swap
or
git clone https://github.com/Nefelim4ag/systemd-swap.git cd systemd-swap make rpm sudo dnf install ./systemd-swap-*noarch.rpm
-
Manual
Install dependencies:
python3
>= 3.7python3
packages:systemd-python
andsysv_ipc
git clone https://github.com/Nefelim4ag/systemd-swap.git cd systemd-swap 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 zram is enough since it on average compresses 2-3x and is much faster than disk based swap.
Q: How many zram devices should one use? A: If you are not using an ancient kernel (pre 4.7) there's no benefit from using multiple zram devices.
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).
Switch on systemd-swap:s automatic swap management
-
Enable swapfc if wanted (note, you should never use zram and zswap at the same time)
vim /etc/systemd/swap.conf.d/overrides.conf
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