Skip to content

Commit

Permalink
Enable bash verbose mode.
Browse files Browse the repository at this point in the history
Set pipefail to produce a failure return code if any command errors.
Set nounset to exit when your script tries to use undeclared variables.
Set "-e" to exit immediately when a command fails.

Change max devices to max 28:

https://bugzilla.redhat.com/show_bug.cgi?id=1383283

MAX_SWAPFILES is defined as

        ((1 << MAX_SWAPFILES_SHIFT) - SWP_MIGRATION_NUM - SWP_HWPOISON_NUM)

which limits the number of swap files below 32 (depending on kernel config), quite possibly to 28.
  • Loading branch information
eugenepaniot committed Jan 23, 2017
1 parent 6642693 commit 296231a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions zramstart
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/sh

num_cpus=$(nproc)
num_cpus=$(($num_cpus<32?$num_cpus:32))
set -o pipefail
set -o nounset
set -e
set -x

num_cpus=$(grep -c processor /proc/cpuinfo)
num_cpus=$(($num_cpus<28?$num_cpus:28))

[ "$num_cpus" != 0 ] || num_cpus=1

last_cpu=$((num_cpus - 1))
Expand All @@ -16,7 +22,7 @@ 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
[ -f /sys/block/zram$i/comp_algorithm ] && 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
Expand Down
2 changes: 2 additions & 0 deletions zramstop
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

set -x

for i in $(grep '^/dev/zram' /proc/swaps | awk '{ print $1 }'); do
swapoff "$i"
done
Expand Down

0 comments on commit 296231a

Please sign in to comment.