add zram config

pull/335/head
Yunqi Ouyang 2019-05-24 15:46:21 +08:00
parent f570b2ad13
commit 74bc2dbf1d
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#!/bin/bash -e
install -m 755 files/zram "${ROOTFS_DIR}/etc/init.d/"
on_chroot << EOF
systemctl enable zram
EOF

View File

@ -0,0 +1,26 @@
#!/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