wok view linux-zram/stuff/compcache @ rev 21917
linux-zram: split swap according to cores count
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Oct 05 11:36:18 2019 +0200 (2019-10-05) |
parents | 7f188676b59c |
children | ac1cbda6d814 |
line source
1 #!/bin/sh
2 # /etc/init.d/compcache: Start, stop and restart COMPCACHE daemon on SliTaz,
3 # at boot time or with the command line. Daemons options are configured
4 # with /etc/daemons.conf
5 #
6 . /etc/init.d/rc.functions
7 source /etc/compcache.conf
9 NAME="compcache"
10 DESC="$(_ '%s daemon' compcache)"
11 EXIST=$(cat /proc/swaps | grep zram0)
13 case "$1" in
14 start)
15 if [ -n "$EXIST" ] ; then
16 _ '%s is already running.' $NAME
17 exit 1
18 fi
19 action 'Loading module...'
20 devices=$(awk '/cpu cores/{c=$4} /processor/{p++}
21 END { if (c>0) p=c; if (p==0) p++; print p }' /proc/cpuinfo)
22 modprobe zram zram_num_devices=$devices &&
23 [ -n "$SIZE_KB" ] && for i in $(seq 0 $(($devices-1))); do
24 echo $(($SIZE_KB * 1024 / $devices)) > /sys/block/zram$i/disksize
25 done
26 status
28 action 'Starting %s: %s...' "$DESC" $NAME
29 for i in $(seq 0 $(($devices-1))); do
30 mkswap /dev/zram$i && swapon /dev/zram$i -p 100
31 done
32 status
33 ;;
34 stop)
35 if [ -z "$EXIST" ] ; then
36 _ '%s is not running.' $NAME
37 exit 1
38 fi
39 action 'Stopping %s: %s...' "$DESC" $NAME
40 for i in $(cd /sys/block/; ls -d zram*); do
41 swapoff /dev/$i && echo 1 > /sys/block/$i/reset
42 done
43 status
44 action 'Unloading module...'
45 rmmod zram
46 status
47 ;;
48 *)
49 emsg "<n><b>$(_ 'Usage:')</b> $0 [start|stop]"
50 newline
51 exit 1
52 ;;
53 esac
55 exit 0