From 5d98dd29238fc9a0b36c132324992ef657d08469 Mon Sep 17 00:00:00 2001 From: Tyler Nijmeh Date: Sun, 2 Aug 2020 14:51:41 -0700 Subject: [PATCH] Configure ZRAM in the background Signed-off-by: Tyler Nijmeh --- service.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/service.sh b/service.sh index 3178d86..54ff5ae 100644 --- a/service.sh +++ b/service.sh @@ -67,6 +67,18 @@ write() { echo "[*] $1: $curval --> $2" } +# Setup ZRAM to half of the available RAM +setup_zram() { + memsize=`cat /proc/meminfo | grep "MemTotal" | awk '{print $2}'` + halfmemsize=`echo "$(($memsize/2))"` + + swapoff /dev/block/zram0 + write /sys/block/zram0/reset 1 + write /sys/block/zram0/disksize "${halfmemsize}KB" + mkswap /dev/block/zram0 + swapon /dev/block/zram0 +} + # Print device information prior to execution echo "[*] ----- Device Information -----" # Kernel and device information @@ -197,16 +209,6 @@ do done # ZRAM -if [[ -d "/sys/block/zram0" ]] -then - memsize=`cat /proc/meminfo | grep "MemTotal" | awk '{print $2}'` - halfmemsize=`echo "$(($memsize/2))"` - - swapoff /dev/block/zram0 - write /sys/block/zram0/reset 1 - write /sys/block/zram0/disksize "${halfmemsize}KB" - mkswap /dev/block/zram0 - swapon /dev/block/zram0 -fi +[[ -d "/sys/block/zram0" ]] && setup_zram & echo "[*] Done."