Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 1 | #!/system/bin/sh |
| 2 | # |
| 3 | # Compcache manager |
| 4 | # shade@chemlab.org (cyanogen) |
| 5 | # |
| 6 | |
wjb | 1818fc3 | 2011-04-05 12:23:45 -0400 | [diff] [blame^] | 7 | isramzswap="$(find /system/lib/modules/ -name ramzswap.ko 2>/dev/null)" |
Abaakouk Mehdi | f92561b | 2011-04-04 15:36:58 +0200 | [diff] [blame] | 8 | |
| 9 | if [ -n "$isramzswap" ] ; then |
| 10 | MODULE=ramzswap |
| 11 | DEV=/dev/block/ramzswap0 |
| 12 | else |
| 13 | DEV=/dev/block/zram0 |
| 14 | MODULE=zram |
| 15 | SYSFS_PATH=/sys/block/zram0 |
| 16 | fi |
Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 17 | |
| 18 | case "$1" in |
| 19 | start) |
| 20 | echo 3 > /proc/sys/vm/drop_caches |
Steve Kondik | 0cd3570 | 2010-10-18 12:22:23 -0400 | [diff] [blame] | 21 | echo 30 > /proc/sys/vm/swappiness |
Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 22 | modprobe $MODULE |
Abaakouk Mehdi | f92561b | 2011-04-04 15:36:58 +0200 | [diff] [blame] | 23 | if [ $MODULE = ramzswap ]; then |
| 24 | rzscontrol $DEV --disksize_kb=$2 --init |
| 25 | else |
| 26 | echo "$((2 * 1024))" > $SYSFS_PATH/disksize |
| 27 | mkswap $DEV >/dev/null |
| 28 | fi |
Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 29 | swapon $DEV |
| 30 | ;; |
| 31 | |
| 32 | stop) |
| 33 | swapoff $DEV >/dev/null 2>&1 |
| 34 | rmmod $MODULE >/dev/null 2>&1 |
| 35 | ;; |
| 36 | stats) |
Abaakouk Mehdi | f92561b | 2011-04-04 15:36:58 +0200 | [diff] [blame] | 37 | if [ $MODULE = ramzswap ]; then |
| 38 | rzscontrol $DEV --stats |
| 39 | else |
| 40 | cd $SYSFS_PATH && for i in * ; do |
| 41 | echo -n "$i:" |
| 42 | cat $i |
| 43 | done |
| 44 | fi |
Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 45 | ;; |
| 46 | *) |
Wes Garner | 2f1711d | 2010-08-31 18:04:01 -0500 | [diff] [blame] | 47 | echo "Usage: $0 {start <size>|stop|stats}" |
Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 48 | exit 1 |
| 49 | esac |
| 50 | |
| 51 | exit 0 |
| 52 | |