updated on Sat Jan 14 04:03:48 UTC 2012
[aur-mirror.git] / zramswap / zramswap.rc.d
blobba18b409c8b7d0b324a3b6a96bc31bac63aed9c1
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
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))
14 case "$1" in
15 start)
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
27 done
29 # Creating swap filesystems
30 for i in $(seq 0 $decr_num_cpus); do
31 mkswap /dev/zram$i
32 done
34 # Switch the swaps on
35 for i in $(seq 0 $decr_num_cpus); do
36 swapon -p 100 /dev/zram$i
37 done
39 stat_done
41 stop)
42 stat_busy "Switching off zram-based swap"
43 # Switching off swap
44 for i in $(seq 0 $decr_num_cpus); do
45 if [[ "$(grep /dev/zram$i /proc/swaps)" != "" ]]; then
46 swapoff /dev/zram$i
48 done
50 rmmod zram
51 stat_done
54 echo "usage: $0 {start|stop}"
55 esac
57 exit 0