Skip to content

Instantly share code, notes, and snippets.

@rizalp rizalp/init-zram-swapping
Last active Jan 18, 2019

Embed
What would you like to do?
/usr/bin/init-zram-swapping custom config
#!/bin/sh
# load dependency modules
# NRDEVICES=$(grep -c ^processor /proc/cpuinfo | sed 's/^0$/1/')
NRDEVICES=1
if modinfo zram | grep -q ' zram_num_devices:' 2>/dev/null; then
MODPROBE_ARGS="zram_num_devices=${NRDEVICES}"
elif modinfo zram | grep -q ' num_devices:' 2>/dev/null; then
MODPROBE_ARGS="num_devices=${NRDEVICES}"
else
exit 1
fi
modprobe zram $MODPROBE_ARGS
# Calculate memory to use for zram (1/2 of ram)
totalmem=`LC_ALL=C free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/ *.*//'`
mem=$(((totalmem * 2 / ${NRDEVICES}) * 1024))
# initialize the devices
for i in $(seq ${NRDEVICES}); do
DEVNUMBER=$((i - 1))
echo lz4 > /sys/block/zram${DEVNUMBER}/comp_algorithm
echo $mem > /sys/block/zram${DEVNUMBER}/disksize
mkswap /dev/zram${DEVNUMBER}
swapon -p 100 /dev/zram${DEVNUMBER}
done
@rizalp

This comment has been minimized.

Copy link
Owner Author

commented Jan 4, 2019

Found after sudo apt install zram-config and seeing the contents of /etc/systemd/system/multi-user.target.wants/zram-config.service

@rizalp

This comment has been minimized.

Copy link
Owner Author

commented Jan 13, 2019

/usr/bin/init-zram-swapping

@rizalp

This comment has been minimized.

Copy link
Owner Author

commented Jan 18, 2019

In /etc/sysctl.conf, append:

vm.swappiness = 80

sudo sysctl -p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.