Commit 5d3f3f96 authored by Vladimir Bashkirtsev's avatar Vladimir Bashkirtsev

Initial commit

parents
all:
install -m 0755 zramstart /usr/sbin
install -m 0755 zramstop /usr/sbin
install -m 0755 zramstat /usr/sbin
install -m 0644 mkzram.service /lib/systemd/system
install -m 0644 zram /etc/sysconfig
[Unit]
Description=Enable compressed swap in memory using zram
After=multi-user.target
[Service]
RemainAfterExit=yes
ExecStart=/usr/sbin/zramstart
ExecStop=/usr/sbin/zramstop
Type=oneshot
[Install]
WantedBy=swap.target
# The factor is how much (from 0 to 100, percentage)
# of system RAM to allocate to ZRAM block devices
# Too big, and your system will start killing off processes
FACTOR=33
#!/bin/sh
num_cpus=$(nproc)
[ "$num_cpus" != 0 ] || num_cpus=1
last_cpu=$((num_cpus - 1))
FACTOR=33
[ -f /etc/sysconfig/zram ] && source /etc/sysconfig/zram || true
factor=$FACTOR # percentage
memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
mem_by_cpu=$(($memtotal/$num_cpus*$factor/100*1024))
modprobe -q zram num_devices=$num_cpus
for i in $(seq 0 $last_cpu); do
#enable lz4 if that supported
grep -q lz4 /sys/block/zram$i/comp_algorithm && echo lz4 > /sys/block/zram$i/comp_algorithm
echo $mem_by_cpu > /sys/block/zram$i/disksize
mkswap /dev/zram$i
swapon -p 100 /dev/zram$i
done
#!/bin/sh
ls /sys/block/zram* > /dev/null 2>&1 || exit 0
for i in /sys/block/zram*; do
compr=$(< $i/compr_data_size)
orig=$(< $i/orig_data_size)
ratio=0
if [ $compr -gt 0 ]; then
ratio=$(echo "scale=2; $orig*100/$compr" | bc -q)
fi
echo -e "/dev/${i/*\/}:\t$ratio% ($orig -> $compr)"
done
#!/bin/sh
for i in $(grep '^/dev/zram' /proc/swaps | awk '{ print $1 }'); do
swapoff "$i"
done
if grep -q "^zram " /proc/modules; then
sleep 1
rmmod zram
fi
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