#!/bin/bash
### BEGIN INIT INFO
# Provides:          zram
# Required-Start:
# Required-Stop:
# Default-Start: 3
# Default-Stop:
# Short-Description: Boost memory performance
# Description:
### END INIT INFO
cores=$(nproc --all)
modprobe zram num_devices=$cores

swapoff -a

totalmem=`free | grep -e "^Mem:" | awk '{print $2}'`
mem=$(( ($totalmem / $cores)* 1024 ))

core=0
while [ $core -lt $cores ]; do
  echo $mem > /sys/block/zram$core/disksize
  echo lz4 > /sys/block/zram$core/comp_algorithm
  mkswap /dev/zram$core
  swapon -p 5 /dev/zram$core
  let core=core+1
done
