6 # get the number of CPUs
7 num_cpus
=$
(grep -c processor
/proc
/cpuinfo
)
8 # if something goes wrong, assume we have 1
9 [[ "$num_cpus" != 0 ]] || num_cpus
=1
11 # set decremented number of CPUs
12 decr_num_cpus
=$
((num_cpus
- 1))
16 stat_busy
"Enabling zram-based swap"
17 # get the amount of memory in the machine
18 mem_total_kb
=$
(grep MemTotal
/proc
/meminfo |
grep -E --only-matching '[[:digit:]]+')
19 mem_total
=$
((mem_total_kb
* 1024))
21 # load dependency modules
22 modprobe zram num_devices
=$num_cpus
24 # initialize the devices
25 for i
in $
(seq 0 $decr_num_cpus); do
26 echo $
((mem_total
/ num_cpus
)) > /sys
/block
/zram
$i/disksize
29 # Creating swap filesystems
30 for i
in $
(seq 0 $decr_num_cpus); do
35 for i
in $
(seq 0 $decr_num_cpus); do
36 swapon
-p 100 /dev
/zram
$i
42 stat_busy
"Switching off zram-based swap"
44 for i
in $
(seq 0 $decr_num_cpus); do
45 if [[ "$(grep /dev/zram$i /proc/swaps)" != "" ]]; then
54 echo "usage: $0 {start|stop}"