Skip to content

Commit

Permalink
Make zram device creation more robust
Browse files Browse the repository at this point in the history
Issues with zramctl not finding a device on the first try have been
observed, this makes the zram device creation process used by
zram-config more robust to attempt to compensate for this issue.

Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed Feb 1, 2021
1 parent 768bdeb commit 87728f7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion zram-config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ createZdevice() {
modprobe --verbose zram >> "$ZLOG" 2>&1 || return 1
fi

RAM_DEV="$(zramctl -f -s "$MEM_SIZE" -a "$ALG" | tr -dc '0-9')"
RAM_DEV="$(zramctl --find | tr -dc '0-9')"

if [[ -z $RAM_DEV ]]; then
echo "Failed to find an open zram device, trying one more time!"
RAM_DEV="$(zramctl --find | tr -dc '0-9')"
if [[ -z $RAM_DEV ]]; then
echo "Still failed to find an open zram device, stopping creation!"
return 1
fi
fi

zramctl --size "$MEM_SIZE" --algorithm "$ALG" "/dev/zram${RAM_DEV}"

if [[ -n $MEM_SIZE ]]; then
echo "$MEM_SIZE" > "/sys/block/zram${RAM_DEV}/mem_limit"
Expand Down

0 comments on commit 87728f7

Please sign in to comment.