arm-sdk

os build toolkit for various embedded devices
git clone https://git.parazyd.org/arm-sdk
Log | Files | Refs | Submodules | README | LICENSE

zram (1136B)


      1 #!/bin/sh
      2 ### BEGIN INIT INFO
      3 # Provides:          zram
      4 # Required-Start:    $local_fs
      5 # Required-Stop:     $local_fs
      6 # Default-Start:     S
      7 # Default-Stop:      0 1 6
      8 # Short-Description: Use compressed RAM as in-memory swap
      9 # Description:       Use compressed RAM as in-memory swap
     10 ### END INIT INFO
     11 
     12 # Author: Antonio Galea <antonio.galea@gmail.com>
     13 # Thanks to Przemysław Tomczyk for suggesting swapoff parallelization
     14 
     15 FRACTION=75
     16 
     17 MEMORY=`perl -ne'/^MemTotal:\s+(\d+)/ && print $1*1024;' < /proc/meminfo`
     18 CPUS=`grep -c processor /proc/cpuinfo`
     19 SIZE=$(( MEMORY * FRACTION / 100 / CPUS ))
     20 
     21 case "$1" in
     22   "start")
     23     param=`modinfo zram|grep num_devices|cut -f2 -d:|tr -d ' '`
     24     modprobe zram $param=$CPUS
     25     for n in `seq $CPUS`; do
     26       i=$((n - 1))
     27       echo $SIZE > /sys/block/zram$i/disksize
     28       mkswap /dev/zram$i
     29       swapon /dev/zram$i -p 10
     30     done
     31     ;;
     32   "stop")
     33     for n in `seq $CPUS`; do
     34       i=$((n - 1))
     35       swapoff /dev/zram$i && echo "disabled disk $n of $CPUS" &
     36     done
     37     wait
     38     sleep .5
     39     modprobe -r zram
     40     ;;
     41   *)
     42     echo "Usage: `basename $0` (start | stop)"
     43     exit 1
     44     ;;
     45 esac