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

Set max count of zram devices to 28 for huge cpu systems #24

Open
wants to merge 7 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
2 changes: 1 addition & 1 deletion mkzram.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Unit]
Description=Enable compressed swap in memory using zram
After=multi-user.target
DefaultDependencies=no

[Service]
RemainAfterExit=yes
Expand Down
4 changes: 2 additions & 2 deletions zram.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Summary: Enable compressed swap in memory
Name: zram
Version: 1.0.0
Release: 2%{?dist}
Version: 1.0.1
Release: 4%{?dist}
License: GPLv2
Group: System Environment/Daemons
Source0: %{name}-%{version}.tar.bz2
Expand Down
43 changes: 33 additions & 10 deletions zramstart
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
#!/bin/sh

num_cpus=$(nproc)
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))
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))
mem_by_cpu=$(($memtotal/$num_cpus*${FACTOR}/100*1024))

modprobe zram num_devices=$num_cpus

modprobe -q zram num_devices=$num_cpus
function getKernelMajorVersion() {
head -c 1 /proc/sys/kernel/osrelease
}

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
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

14 changes: 12 additions & 2 deletions zramstat
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#!/bin/sh

function getKernelMajorVersion() {
head -c 1 /proc/sys/kernel/osrelease
}

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)
if [ $(getKernelMajorVersion) -gt 3 ]; then
compr=$(cat $i/mm_stat | awk '{ print $2 }')
orig=$(cat $i/mm_stat | awk '{ print $1 }')
else
compr=$(< $i/compr_data_size)
orig=$(< $i/orig_data_size)
fi

ratio=0
if [ $compr -gt 0 ]; then
ratio=$(echo "scale=2; $orig*100/$compr" | bc -q)
Expand Down
21 changes: 17 additions & 4 deletions zramstop
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
#!/bin/sh

set -o pipefail
set -o nounset
set -e
set -x

function getKernelMajorVersion() {
head -c 1 /proc/sys/kernel/osrelease
}

for i in $(grep '^/dev/zram' /proc/swaps | awk '{ print $1 }'); do
swapoff "$i"
swapoff -v "$i"
n=$(echo $i | sed 's/[^0-9]//g')
echo 1 > /sys/block/zram${n}/reset
if [ $(getKernelMajorVersion) -gt 3 ]; then
echo $n > /sys/class/zram-control/hot_remove
fi
done

if grep -q "^zram " /proc/modules; then
sleep 1
rmmod zram
if [ $(getKernelMajorVersion) -le 3 ]; then
grep zram /proc/modules && rmmod -v zram
fi