You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
826 B
27 lines
826 B
#!/bin/bash |
|
#set -x |
|
# default factor of 1/3 of RAM |
|
factor=3 |
|
# default priority is maximum priority |
|
priority=32767 |
|
[ -f /etc/zram.conf ] && source /etc/zram.conf || true |
|
[ -z "$FACTOR" ] || factor=$FACTOR |
|
[ -z "$PRIORITY" ] || priority=$PRIORITY |
|
|
|
# Calculate ZRAM size |
|
mem_total=$(free -w |grep "^Mem" |awk '{printf("%d",$2)}') |
|
zram_size=$((${mem_total} / ${factor} /1024)) |
|
|
|
# ZRAM in recent kernels is multithreaded so we don't need to balance across CPUs |
|
modprobe -q zram num_devices=1 |
|
|
|
# Create ZRAM with first device, lz4 algorithm |
|
zramdev=$(zramctl --find --algorithm lz4 --size ${zram_size}MB 2>&1) |
|
# The above returns the device. Use it below |
|
mkswap $zramdev |
|
swapon -p $priority $zramdev |
|
|
|
# Investigate this and swapiness |
|
# echo 0 > /proc/sys/vm/page-cluster |
|
|
|
echo -e "\nActivated ZRAM swap device of ${zram_size} MB\n"
|
|
|