forked from mystilleef/FedoraZram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zramstart
executable file
·45 lines (32 loc) · 1.1 KB
/
zramstart
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
#!/bin/sh
set -o pipefail
set -o nounset
set -e
set -x
FACTOR=33
COMP_ALGORITHM=lz4
num_cpus=$(grep -c processor /proc/cpuinfo)
num_cpus=$(($num_cpus<28?$num_cpus:28))
[ "$num_cpus" != 0 ] || num_cpus=1
max_comp_streams=$(($num_cpus>2?2:1))
last_cpu=$((num_cpus - 1))
[ -f /etc/sysconfig/zram ] && source /etc/sysconfig/zram || true
memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
mem_by_cpu=$(($memtotal/$num_cpus*${FACTOR}/100*1024))
modprobe zram num_devices=$num_cpus
function getKernelMajorVersion() {
head -c 1 /proc/sys/kernel/osrelease
}
for i in $(seq 0 $last_cpu); do
n=$i
if [ $(getKernelMajorVersion) -gt 3 ]; then
n=$(cat /sys/class/zram-control/hot_add)
fi
block=/sys/block/zram${n}
if [ "$(cat ${block}/disksize)" -eq 0 ] ; then
[ -f ${block}/comp_algorithm ] && grep -q ${COMP_ALGORITHM} ${block}/comp_algorithm && echo ${COMP_ALGORITHM} > ${block}/comp_algorithm
echo $mem_by_cpu > ${block}/disksize
mkswap /dev/zram$n
swapon -v -p 100 /dev/zram$n
fi
done