ipv6 kernel parameters
[dotFiles.git] / centos / etc / init.d / zramswap
blobd654aabca0463a8a00c4bd6a94cb6f4f3f38a51a
1 #!/bin/bash
3 # chkconfig: 345 20 80
4 # description: Linux zramswap setup
6 NUM_CPUS=$(nproc)
7 [ "$NUM_CPUS" != 0 ] || NUM_CPUS=1
8 NUM_DEVS=$NUM_CPUS # kernel version <= 3.15
9 FACTOR=50 # percentage
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
17 COMP_ALGORITHMS=lzo
19 #Defaults for vm.overcommit_memory, vm.page-cluster, vm.swappiness
20 OVERCOMMIT_MEMORY=0
21 PAGE_CLUSTER=3
22 SWAPPINESS=100
25 start() {
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;
30 done
32 for i in /dev/zram*; do
33 /usr/sbin/mkswap ${i};
34 /usr/sbin/swapon -d -p100 ${i};
35 done
37 echo 1 > /proc/sys/vm/overcommit_memory
38 echo 0 > /proc/sys/vm/page-cluster
39 echo 100 > /proc/sys/vm/swappiness
42 stop() {
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};
51 done
53 for i in /sys/block/zram*; do
54 /usr/bin/echo 1 > ${i}/reset;
55 done
56 [ -e /sys/module/zram ] && modprobe -r zram
59 case $1 in
60 (start|stop) "$1" ;;
61 esac