Skip to content

Commit

Permalink
Use zram module hot add support instead of modprobe
Browse files Browse the repository at this point in the history
  • Loading branch information
nefelim4ag committed May 11, 2016
1 parent 005ea9d commit 2f143ee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 0 additions & 4 deletions 90-systemd-swap.conf

This file was deleted.

5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ It is configurable in /etc/systemd-swap.conf.
Source:
```
/etc/systemd-swap.conf
/usr/lib/modprobe.d/90-systemd-swap.conf
/usr/lib/systemd/system/systemd-swap.service
/usr/lib/systemd/scripts/systemd-swap.sh
```
Expand All @@ -17,7 +16,3 @@ Using:
Note:
=======
Dependence: util-linux >= 2.26

In package install /usr/lib/modprobe.d/90-systemd-swap.conf - this file create zram devices, 32 - this is maximum for this module.

You can use empty devices. 32 - because zram can't create new devices if others already in using, like loop module.
1 change: 0 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ fi
$SUDO cp -v ./systemd-swap.sh /usr/lib/systemd/scripts/systemd-swap.sh
$SUDO ln -svf /etc/systemd-swap.conf /etc/systemd/swap.conf
$SUDO cp -v ./systemd-swap.service /usr/lib/systemd/system/systemd-swap.service
$SUDO cp -v ./90-systemd-swap.conf /etc/modprobe.d/90-systemd-swap.conf
22 changes: 16 additions & 6 deletions systemd-swap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,32 @@ manage_zram(){
case $1 in
start)
[ -z ${zram[size]} ] && return 0
# if module not loaded create many zram devices for users needs
[ -f /dev/zram0 ] || modprobe zram num_devices=32
zram[alg]=${zram[alg]:-lzo}
zram[streams]=${zram[streams]:-${sys[cpu_count]}}
zram[force]=${zram[force]:-true}
# Wrapper, for handling zram initialization problems
while :; do
[ -d /sys/module/zram ] || modprobe zram
# zramctl is a external program -> return name of first free device
if zram[dev]=$(zramctl -f -a ${zram[alg]} -t ${zram[streams]} -s ${zram[size]}); then
OUTPUT="$(zramctl -f -a ${zram[alg]} -t ${zram[streams]} -s ${zram[size]} 2>&1 || :)"
if echo $OUTPUT | grep -q "/dev/zram"; then
zram[dev]="$OUTPUT"
break
else
# if force option disabled, just break loop
if ! ${zram[force]}; then
if echo $OUTPUT | grep -q "zramctl: no free zram device found"; then
WARN "zramctl can't find free device"
INFO "Use workaround hook for hot add"
if [ -f /sys/class/zram-control/hot_add ]; then
NEW_ZRAM=$(cat /sys/class/zram-control/hot_add)
INFO "Success: new device /dev/zram$NEW_ZRAM"
else
ERRO "This kernel not support hot add zram device, please use 4.2< kernels"
fi
elif ! ${zram[force]}; then
break
else
sleep 1
fi
sleep 1
fi
done
mkswap ${zram[dev]}
Expand Down

0 comments on commit 2f143ee

Please sign in to comment.