Automatically setup swap on zram ✨ with optional systemd support, a simpler alternative to zram-generator and systemd-swap
Automatically setup swap on zram ✨
See also https://fedoraproject.org/wiki/Changes/SwapOnZRAM#Benefit_to_Fedora
zramd
package form the AUR.sudo systemctl enable --now zramd
.deb
file corresponding to your system architecturesudo dpkg -i DEB_FILE
.tar.gz
file corresponding to your system architecturetar xf TAR_FILE
zramd
binary to /usr/local/bin
./etc/rc.local
e.g.
/usr/local/bin/zramd start
zramd --help
Usage: zramd <command> [<args>]
Options:
--help, -h display this help and exit
--version display version and exit
Commands:
start load zram module and setup swap devices
stop stop swap devices and unload zram module
zramd start --help
Usage: zramd start [--algorithm ALGORITHM] [--fraction FRACTION] [--max-size MAX_SIZE] [--num-devices NUM_DEVICES] [--priority PRIORITY] [--skip-vm]
Options:
--algorithm ALGORITHM, -a ALGORITHM
zram compression algorithm
[default: zstd, env: ALGORITHM]
--fraction FRACTION, -f FRACTION
maximum percentage of RAM allowed to use
[default: 1.0, env: FRACTION]
--max-size MAX_SIZE, -m MAX_SIZE
maximum total MB of swap to allocate
[default: 8192, env: MAX_SIZE]
--num-devices NUM_DEVICES, -n NUM_DEVICES
maximum number of zram devices to create
[default: 1, env: NUM_DEVICES]
--priority PRIORITY, -p PRIORITY
swap priority
[default: 100, env: PRIORITY]
--skip-vm, -s skip initialization if running on a VM
[default: false, env: SKIP_VM]
--help, -h display this help and exit
--version display version and exit
make docker
command e.g.
# This command will create builds (.tar.gz and .deb) for all supported architectures
CURRENT_TAG=v0.8.5 make docker
go
(at least version 1.16), the command may be different depending on the distribution:
# ArchLinux
sudo pacman -S go
# Ubuntu
sudo apt-get install golang
make
to create a build with the same architecture as the current system:
# If you cloned this repository you can just run make
make
# To create a Raspberry Pi build you need to specify the arch e.g.
GOOS=linux GOARCH=arm GOARM=7 make
# If you downloaded a .tar.gz or .zip (instead of cloning this repo) you need to specify additional info
CURRENT_DATE=$(date --iso-8601=seconds) VERSION=Unknown make
# So, to target the Raspberry Pi (without a repo) the command would look like
CURRENT_DATE=$(date --iso-8601=seconds) VERSION=Unknown GOOS=linux GOARCH=arm GOARM=7 make
zramd.bin
will be created under the dist/
directory, now you can uninstall go
if you like./etc/default/zramd
, just edit the variables as you like and restart the zramd
service i.e. sudo systemctl restart zramd
zramd start --max-size 1024
or zramd start --fraction 0.5 --priority 0
zramd
service after a kernel upgrade, you just need to restart your computer.zramd
loads and unloads the zram kernel module assuming that the system is not using zram for other stuff (like mounting /tmp
over zram).--skip-vm
parameter to avoid initialization when running inside a virtual machine.systemd-oomd
or earlyoom
(they may not be available on all distributions).swapon -show
or zramctl
to see all swap devices currently in use, this is useful if you want to confirm that all of the zram devices were setup correctly.tail /dev/zero
but keep in mind that your system may become unresponsive if you do not have an application like earlyoom
to kill tail
just before it reaches the memory limit.systemd-run
e.g.
sudo systemd-run -t \
-p ProtectHostname=yes \
-p PrivateNetwork=yes \
-p IPAddressDeny=any \
-p NoNewPrivileges=yes \
-p RestrictNamespaces=yes \
-p RestrictRealtime=yes \
-p RestrictSUIDSGID=yes \
-p MemoryDenyWriteExecute=yes \
-p LockPersonality=yes \
-p 'CapabilityBoundingSet=CAP_SYS_ADMIN CAP_SYS_MODULE' \
-p 'SystemCallFilter=@module @swap @system-service' \
-p SystemCallArchitectures=native \
-p SystemCallErrorNumber=EPERM \
-p 'DeviceAllow=block-* rw' \
-p DevicePolicy=closed \
-p RestrictAddressFamilies=AF_UNIX \
-p RestrictAddressFamilies=~AF_UNIX \
/usr/bin/zramd --version