Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workstation tuning params #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions zramstart
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@
num_cpus=$(grep -c processor /proc/cpuinfo)
[ "$num_cpus" != 0 ] || num_cpus=1

last_cpu=$((num_cpus - 1))
FACTOR=33
threads=$((num_cpus * 4))
last_thread=$((threads - 1))
FACTOR=200

[ -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))
mem_by_cpu=$(($memtotal/$threads*$factor/100*1024))
modprobe -q zram num_devices=$threads
for i in $(seq 0 $last_thread); 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

modprobe -q zram num_devices=$num_cpus
# vm.vfs_cache_pressure=50
# vm.dirty_ratio=30
# vm.dirty_background_ratio=20

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
# ON SSD
# vm.swappiness=5
# ON HDD
# vm.swappiness=99

# if you having SSD, you may try class 1 (realtime)
# ionice -c 2 -p `pgrep kswapd0`
33 changes: 26 additions & 7 deletions zramstat
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@

ls /sys/block/zram* > /dev/null 2>&1 || exit 0

sum_compr=0
sum_orig=0

while [ 1 ]; do

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)"
compr=$(< $i/compr_data_size)
orig=$(< $i/orig_data_size)
sum_compr=$((sum_compr+compr))
sum_orig=$((sum_orig+orig))
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

ratio=0
if [ $sum_compr -gt 0 ]; then
ratio=$(echo "scale=2; $sum_orig*100/$sum_compr" | bc -q)
fi
sum_orig=$((sum_orig/1024/1024))
sum_compr=$((sum_compr/1024/1024))
diff=$((sum_orig-sum_compr))

echo -ne "\t GAINED $diff MB by using $sum_compr MB\r "
sleep 1
done