blob: bb3a349574de8477ea476df71e3e14d61594749a [file] [log] [blame]
Steve Kondik2dc24f62010-07-06 00:19:10 -04001#!/system/bin/sh
2#
3# Compcache manager
4# shade@chemlab.org (cyanogen)
5#
6
wjb1818fc32011-04-05 12:23:45 -04007isramzswap="$(find /system/lib/modules/ -name ramzswap.ko 2>/dev/null)"
Emilio López230b6712011-04-07 22:28:27 +00008isramzswapbuiltin="$(ls -l /dev/block/ramzswap0 2>/dev/null)"
Abaakouk Mehdif92561b2011-04-04 15:36:58 +02009
Emilio López230b6712011-04-07 22:28:27 +000010if [ -n "$isramzswap$isramzswapbuiltin" ] ; then
Abaakouk Mehdif92561b2011-04-04 15:36:58 +020011 MODULE=ramzswap
12 DEV=/dev/block/ramzswap0
13else
14 DEV=/dev/block/zram0
15 MODULE=zram
16 SYSFS_PATH=/sys/block/zram0
17fi
Steve Kondik2dc24f62010-07-06 00:19:10 -040018
19case "$1" in
20 start)
21 echo 3 > /proc/sys/vm/drop_caches
Steve Kondik0cd35702010-10-18 12:22:23 -040022 echo 30 > /proc/sys/vm/swappiness
Steve Kondik2dc24f62010-07-06 00:19:10 -040023 modprobe $MODULE
Abaakouk Mehdif92561b2011-04-04 15:36:58 +020024 if [ $MODULE = ramzswap ]; then
25 rzscontrol $DEV --disksize_kb=$2 --init
26 else
William Graham3f473462011-04-10 16:25:16 -050027 echo "$(($2 * 1024))" > $SYSFS_PATH/disksize
Abaakouk Mehdif92561b2011-04-04 15:36:58 +020028 mkswap $DEV >/dev/null
29 fi
Steve Kondik2dc24f62010-07-06 00:19:10 -040030 swapon $DEV
31 ;;
32
33 stop)
34 swapoff $DEV >/dev/null 2>&1
35 rmmod $MODULE >/dev/null 2>&1
36 ;;
37 stats)
Abaakouk Mehdif92561b2011-04-04 15:36:58 +020038 if [ $MODULE = ramzswap ]; then
39 rzscontrol $DEV --stats
40 else
41 cd $SYSFS_PATH && for i in * ; do
42 echo -n "$i:"
43 cat $i
44 done
45 fi
Steve Kondik2dc24f62010-07-06 00:19:10 -040046 ;;
47 *)
Wes Garner2f1711d2010-08-31 18:04:01 -050048 echo "Usage: $0 {start <size>|stop|stats}"
Steve Kondik2dc24f62010-07-06 00:19:10 -040049 exit 1
50esac
51
52exit 0
53