forked from DMorgado/my-zram-systemd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zram
51 lines (40 loc) · 1.18 KB
/
zram
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
NUM_CPUS=$(nproc)
[ "$NUM_CPUS" != 0 ] || NUM_CPUS=1
NUM_DEVS=$NUM_CPUS
FACTOR=10 # percentage
TOTALRAM=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
DISK_SIZE=$(($TOTALRAM/$NUM_CPUS*$FACTOR/100*1024))
#Defaults for vm.overcommit_memory, vm.page-cluster, vm.spwapiness
OVERCOMMIT_MEMORY=0
PAGE_CLUSTER=3
SPWAPINESS=60
start() {
[ ! -e /sys/module/zram ] && modprobe zram num_devices=$NUM_DEVS || modprobe -r zram && modprobe zram num_devices=$NUM_DEVS
for i in /sys/block/zram*; do
/usr/bin/echo $DISK_SIZE > ${i}/disksize;
done
for i in /dev/zram*; do
/usr/sbin/mkswap ${i};
/usr/sbin/swapon -d -p100 ${i};
done
echo 1 > /proc/sys/vm/overcommit_memory
echo 0 > /proc/sys/vm/page-cluster
echo 100 > /proc/sys/vm/swappiness
}
stop() {
[ ! -e /sys/module/zram ] && exit 0
echo $OVERCOMMIT_MEMORY > /proc/sys/vm/overcommit_memory
echo $PAGE_CLUSTER > /proc/sys/vm/page-cluster
echo $SPWAPINESS > /proc/sys/vm/swappiness
for i in /dev/zram*; do
/usr/sbin/swapoff ${i};
done
for i in /sys/block/zram*; do
/usr/bin/echo 1 > ${i}/reset;
done
[ -e /sys/module/zram ] && modprobe -r zram
}
case $1 in
(start|stop) "$1" ;;
esac