Skip to content

Commit

Permalink
v7.1 (20200328)
Browse files Browse the repository at this point in the history
修复:某些平台的`/sys/class/zram-control`不能如预期工作导致ZRAM控制错误
改进:ZRAM相关提示语更加明确

Signed-off-by: Matt Yang <yccy@outlook.com>
  • Loading branch information
yc9559 committed Mar 28, 2020
1 parent 5a26651 commit e61e6be
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 34 deletions.
2 changes: 1 addition & 1 deletion customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ui_print ""
ui_print "* QTI memory optimization"
ui_print "* https://github.com/yc9559/qti-mem-opt"
ui_print "* Author: Matt Yang"
ui_print "* Version: v7 (20200327)"
ui_print "* Version: v7.1 (20200328)"
ui_print ""

# Only some special files require specific permissions
Expand Down
2 changes: 1 addition & 1 deletion module.prop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=qti-mem-opt
name=QTI memory optimization
version=v7 (20200327)
version=v7.1 (20200328)
versionCode=5
author=Matt Yang
description=Memory management optimaization for Android platforms. Repo: https://github.com/yc9559/qti-mem-opt
34 changes: 7 additions & 27 deletions script/libmem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Linux memory tunning Library
# https://github.com/yc9559/
# Author: Matt Yang
# Version: 20200317
# Version: 20200327

# include PATH
BASEDIR="$(dirname "$0")"
Expand All @@ -16,7 +16,6 @@ VM="/proc/sys/vm"
LMK="/sys/module/lowmemorykiller/parameters"
ZRAM="/sys/block/zram0"
ZRAM_DEV="/dev/block/zram0"
ZRAM_CTL="/sys/class/zram-control"

###############################
# ZRAM tool functions
Expand All @@ -25,7 +24,7 @@ ZRAM_CTL="/sys/class/zram-control"
# return: true/false
mem_has_zram_mod()
{
if [ -b "$ZRAM_DEV" ] || [ -d "$ZRAM_CTL" ]; then
if [ -b "$ZRAM_DEV" ]; then
echo "true"
else
echo "false"
Expand All @@ -35,9 +34,12 @@ mem_has_zram_mod()
# $1:binary $2:arg
mem_fallback()
{
# try binary provided by vendor toybox
"/vendor/bin/$1" "$2"
[ "$?" == "0" ] && return
# try binary provided by system toybox
"/system/bin/$1" "$2"
# try binary provided by magisk busybox
[ "$?" == "0" ] && return
"$1" "$2"
}
Expand Down Expand Up @@ -75,28 +77,6 @@ mem_start_zram()
lock_val "0" $VM/page-cluster
}

mem_close_zram()
{
# control swap if only the kernel support ZRAM, otherwise leave swap untouched
[ "$(mem_has_zram_mod)" == "false" ] && return

mem_stop_zram
for i in 0 1 2 3 4; do
echo $i > $ZRAM_CTL/hot_remove
done
}

mem_open_zram()
{
# control swap if only the kernel support ZRAM, otherwise leave swap untouched
[ "$(mem_has_zram_mod)" == "false" ] && return

local id
id="$(cat $ZRAM_CTL/hot_add)"
ZRAM="/sys/block/zram$id"
ZRAM_DEV="/dev/block/zram$id"
}

mem_get_available_comp_alg()
{
if [ "$(mem_has_zram_mod)" == "false" ]; then
Expand Down Expand Up @@ -149,7 +129,7 @@ mem_zram_status()
{
# check whether the zram block device exists
if [ "$(mem_has_zram_mod)" == "false" ]; then
echo "ZRAM is not supported by kernel."
echo "Ignored. Unsupported by kernel."
return
fi

Expand All @@ -158,6 +138,6 @@ mem_zram_status()
if [ "$swap_info" != "" ]; then
echo "Enabled. Size $(echo "$swap_info" | awk '{print $3}')kB, using $(mem_get_cur_comp_alg)."
else
echo "Disabled."
echo "Disabled by user."
fi
}
11 changes: 6 additions & 5 deletions script/mem_opt_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# QTI memory optimization
# https://github.com/yc9559/qti-mem-opt
# Author: Matt Yang
# Version: v7 (20200327)
# Version: v7.1 (20200328)

# Runonce after boot, to speed up the transition of power modes in powercfg

Expand All @@ -15,7 +15,7 @@ BASEDIR="$(dirname "$0")"

TMEM="$(mem_get_total_byte)"
ZRAM_ALGS="$(mem_get_available_comp_alg)"
[ "$ZRAM_ALGS" == "unsupported" ] && ZRAM_ALGS="The kernel does not support zram"
[ "$ZRAM_ALGS" == "unsupported" ] && ZRAM_ALGS="<unsupported>"

zram_size=""
zram_alg=""
Expand Down Expand Up @@ -86,7 +86,7 @@ save_panel()
write_panel "QTI memory optimization"
write_panel "https://github.com/yc9559/qti-mem-opt"
write_panel "Author: Matt Yang"
write_panel "Version: v7 (20200327)"
write_panel "Version: v7.1 (20200328)"
write_panel "Last performed: $(date '+%Y-%m-%d %H:%M:%S')"
write_panel ""
write_panel "[ZRAM status]"
Expand Down Expand Up @@ -115,9 +115,10 @@ setprop persist.vendor.sys.memplus.enable "false"
lock_val "0" /sys/module/memplus_core/parameters/memory_plus_enabled
lock_val "0" /proc/sys/vm/memory_plus

mem_close_zram
# we don't know when system will init ZRAM
mem_stop_zram
wait_until_login
mem_open_zram
mem_stop_zram

# disable oneplus mods which kill apps fast
lock_val "0" $LMK/batch_kill
Expand Down

0 comments on commit e61e6be

Please sign in to comment.