Skip to content

Instantly share code, notes, and snippets.

@WorldException
Created July 1, 2021 10:43
Show Gist options
  • Save WorldException/f4b94a25193fc6cc0cbb1142d53ad80b to your computer and use it in GitHub Desktop.
Save WorldException/f4b94a25193fc6cc0cbb1142d53ad80b to your computer and use it in GitHub Desktop.
Ubuntu zram-config change default size of memory
#!/bin/sh
# /usr/bin/init-zram-swapping
# load dependency modules
NRDEVICES=$(grep -c ^processor /proc/cpuinfo | sed 's/^0$/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
# 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))
# !!! Add line
. /etc/zram
modprobe zram $MODPROBE_ARGS
# initialize the devices
for i in $(seq ${NRDEVICES}); do
DEVNUMBER=$((i - 1))
echo $mem > /sys/block/zram${DEVNUMBER}/disksize
mkswap /dev/zram${DEVNUMBER}
swapon -p 5 /dev/zram${DEVNUMBER}
done
#/etc/zram
# only 2 devices used
NRDEVICES=2
MODPROBE_ARGS="num_devices=$NRDEVICES"
# 512MB
mem=536870912
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment