Commit 1ec87215 authored by Vladimir Bashkirtsev's avatar Vladimir Bashkirtsev

New zram module is capable to use multiple CPUs for compression - no need to...

New zram module is capable to use multiple CPUs for compression - no need to create multiple devices anymore
parent 0efbb9ba
#!/bin/sh #!/bin/sh
num_cpus=$(nproc)
[ "$num_cpus" != 0 ] || num_cpus=1
last_cpu=$((num_cpus - 1))
FACTOR=33 FACTOR=33
[ -f /etc/sysconfig/zram ] && source /etc/sysconfig/zram || true [ -f /etc/sysconfig/zram ] && source /etc/sysconfig/zram || true
factor=$FACTOR # percentage factor=$FACTOR # percentage
memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ') memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
mem_by_cpu=$(($memtotal/$num_cpus*$factor/100*1024)) mem_used=$(($memtotal*$factor/100*1024))
modprobe -q zram num_devices=$num_cpus
for i in $(seq 0 $last_cpu); do modprobe -q zram
#enable lz4 if that supported grep -q lzo-rle /sys/block/zram0/comp_algorithm && echo lzo-rle > /sys/block/zram0/comp_algorithm
grep -q lz4 /sys/block/zram$i/comp_algorithm && echo lz4 > /sys/block/zram$i/comp_algorithm echo $mem_used > /sys/block/zram0/disksize
echo $mem_by_cpu > /sys/block/zram$i/disksize mkswap /dev/zram0
mkswap /dev/zram$i swapon -p 100 /dev/zram0
swapon -p 100 /dev/zram$i
done
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment