4 # description: Linux zramswap setup
7 [ "$NUM_CPUS" != 0 ] || NUM_CPUS
=1
8 NUM_DEVS
=$NUM_CPUS # kernel version <= 3.15
10 TOTALRAM
=$
(grep MemTotal
/proc
/meminfo |
awk ' { print $2 } ')
11 DISK_SIZE
=$
(($TOTALRAM/$NUM_CPUS*$FACTOR/100*1024))
13 # show supported compression algorithms: `cat /sys/block/zram*/comp_algorithm`
14 # select your compression algorithm, lzo is the default
15 # speed: lz4 > zstd > lzo
16 # compression: zstd > lzo > lz4
19 #Defaults for vm.overcommit_memory, vm.page-cluster, vm.swappiness
26 [ ! -e /sys
/module
/zram
] && modprobe zram num_devices
=$NUM_DEVS || modprobe
-r zram
&& modprobe zram num_devices
=$NUM_DEVS
27 for i
in /sys
/block
/zram
*; do
28 /usr
/bin
/echo $COMP_ALGORITHMS > ${i}/comp_algorithm
;
29 /usr
/bin
/echo $DISK_SIZE > ${i}/disksize
;
32 for i
in /dev
/zram
*; do
33 /usr
/sbin
/mkswap
${i};
34 /usr
/sbin
/swapon
-d -p100 ${i};
37 echo 1 > /proc
/sys
/vm
/overcommit_memory
38 echo 0 > /proc
/sys
/vm
/page-cluster
39 echo 100 > /proc
/sys
/vm
/swappiness
43 [ ! -e /sys
/module
/zram
] && exit 0
45 echo $OVERCOMMIT_MEMORY > /proc
/sys
/vm
/overcommit_memory
46 echo $PAGE_CLUSTER > /proc
/sys
/vm
/page-cluster
47 echo $SWAPPINESS > /proc
/sys
/vm
/swappiness
49 for i
in /dev
/zram
*; do
50 /usr
/sbin
/swapoff
${i};
53 for i
in /sys
/block
/zram
*; do
54 /usr
/bin
/echo 1 > ${i}/reset;
56 [ -e /sys
/module
/zram
] && modprobe
-r zram