diff --git a/README.md b/README.md index 3c70131..9efb66d 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,9 @@ Allow the scheduler to place tasks on their origin CPU, increasing cache localit * nr_requests: 128 --> 64: Reduce I/O latencies slightly by reducing the maximum queue depth. * cfq / kyber: Use a scheduler with balanced scheduling to reduce I/O latencies, which is essential for fast flash storage (eMMC & UFS). +### ZRAM +ZRAM reduces disk wear by reducing disk writes, and also increases cache locality by allowing more data to fit in RAM at once. KTweak configures ZRAM to take up at most half of the available RAM on the system, which is a good ratio of RAM to ZRAM for a mobile device. + # Other Notes You should know that KTweak applies after init finishes + android mounts + 120 seconds in order to prevent Android's init from overwriting any values. diff --git a/system/bin/ktweak b/system/bin/ktweak index 8bfa0d6..8c81da0 100644 --- a/system/bin/ktweak +++ b/system/bin/ktweak @@ -58,6 +58,30 @@ write() { fi } +# Setup ZRAM to half of the available RAM (sync) +setup_zram() { + memsize=`cat /proc/meminfo | grep "MemTotal" | awk '{print $2}'` + halfmemsize=`echo "$(($memsize/2))"` + + swapoff /dev/block/zram0 + _write /sys/block/zram0/reset 1 + _write /sys/block/zram0/disksize "${halfmemsize}KB" + + avail_algs=`cat /sys/block/zram0/comp_algorithm` + for alg in lz4 zstd lzo deflate + do + if [[ "$avail_algs" == *"$alg"* ]] + then + _write "${queue}scheduler" "$alg" + break + fi + + done + + mkswap /dev/block/zram0 + swapon /dev/block/zram0 +} + usage() { echo -n "Usage: `basename $0` [OPTIONS] Options: @@ -174,4 +198,7 @@ do write "${queue}nr_requests" 64 done +# ZRAM +[[ -d "/sys/block/zram0" ]] && setup_zram &> /dev/null & + exit 0