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)" |
Emilio López | 230b671 | 2011-04-07 22:28:27 +0000 | [diff] [blame] | 8 | isramzswapbuiltin="$(ls -l /dev/block/ramzswap0 2>/dev/null)" |
Abaakouk Mehdi | f92561b | 2011-04-04 15:36:58 +0200 | [diff] [blame] | 9 | |
Emilio López | 230b671 | 2011-04-07 22:28:27 +0000 | [diff] [blame] | 10 | if [ -n "$isramzswap$isramzswapbuiltin" ] ; then |
Abaakouk Mehdi | f92561b | 2011-04-04 15:36:58 +0200 | [diff] [blame] | 11 | MODULE=ramzswap |
| 12 | DEV=/dev/block/ramzswap0 |
| 13 | else |
| 14 | DEV=/dev/block/zram0 |
| 15 | MODULE=zram |
| 16 | SYSFS_PATH=/sys/block/zram0 |
| 17 | fi |
Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 18 | |
| 19 | case "$1" in |
| 20 | start) |
| 21 | echo 3 > /proc/sys/vm/drop_caches |
Steve Kondik | 0cd3570 | 2010-10-18 12:22:23 -0400 | [diff] [blame] | 22 | echo 30 > /proc/sys/vm/swappiness |
Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 23 | modprobe $MODULE |
Abaakouk Mehdi | f92561b | 2011-04-04 15:36:58 +0200 | [diff] [blame] | 24 | if [ $MODULE = ramzswap ]; then |
| 25 | rzscontrol $DEV --disksize_kb=$2 --init |
| 26 | else |
William Graham | 3f47346 | 2011-04-10 16:25:16 -0500 | [diff] [blame] | 27 | echo "$(($2 * 1024))" > $SYSFS_PATH/disksize |
Abaakouk Mehdi | f92561b | 2011-04-04 15:36:58 +0200 | [diff] [blame] | 28 | mkswap $DEV >/dev/null |
| 29 | fi |
Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 30 | swapon $DEV |
| 31 | ;; |
| 32 | |
| 33 | stop) |
| 34 | swapoff $DEV >/dev/null 2>&1 |
| 35 | rmmod $MODULE >/dev/null 2>&1 |
| 36 | ;; |
| 37 | stats) |
Abaakouk Mehdi | f92561b | 2011-04-04 15:36:58 +0200 | [diff] [blame] | 38 | 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 Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 46 | ;; |
| 47 | *) |
Wes Garner | 2f1711d | 2010-08-31 18:04:01 -0500 | [diff] [blame] | 48 | echo "Usage: $0 {start <size>|stop|stats}" |
Steve Kondik | 2dc24f6 | 2010-07-06 00:19:10 -0400 | [diff] [blame] | 49 | exit 1 |
| 50 | esac |
| 51 | |
| 52 | exit 0 |
| 53 | |