Skip to content

Commit

Permalink
mss: treewide: migrate to using sysctl instead of doing everything ma…
Browse files Browse the repository at this point in the history
…nually

Signed-off-by: chickendrop89 <[email protected]>
  • Loading branch information
chickendrop89 committed Jul 19, 2024
1 parent 2b37c0e commit c03c1fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ MODPATH="/data/adb/modules/magisk-swapspace"
SWAPPROP="$MODPATH/swap.prop"
SWAPFILE="$MODPATH/swap"

SWAPPINESS_SYSPATH="/proc/sys/vm/swappiness"
VFS_CACHE_PRESSURE_SYSPATH="/proc/sys/vm/vfs_cache_pressure"
VFS_CACHE_PRESSURE_SYSCTL_ENTRY="vm.vfs_cache_pressure"
SWAPPINESS_SYSCTL_ENTRY="vm.swappiness"

cprint(){
printf "- magisk-swapspace: %s \n" "$1"
Expand Down Expand Up @@ -70,8 +70,8 @@ readProp() {

# Set kernel tune - it's as simple as that
setKernelTune() {
FILE="$1"
KEY="$1"
VALUE="$2"

echo "$VALUE" > "$FILE"
sysctl -w -q "$KEY=$VALUE"
}
4 changes: 2 additions & 2 deletions service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ ENABLE_SWAP_PROP="$(readProp ENABLE-SWAP)"

# Sets the VFS Cache Pressure value if configured
if [ "$VFS_CACHE_PRESSURE_PROP" ];
then setKernelTune "$VFS_CACHE_PRESSURE_SYSPATH" "$VFS_CACHE_PRESSURE_PROP"
then setKernelTune "$VFS_CACHE_PRESSURE_SYSCTL_ENTRY" "$VFS_CACHE_PRESSURE_PROP"
fi

# Sets the Swappiness value if configured
if [ "$SWAPPINESS_PROP" ];
then setKernelTune "$SWAPPINESS_SYSPATH" "$SWAPPINESS_PROP"
then setKernelTune "$SWAPPINESS_SYSCTL_ENTRY" "$SWAPPINESS_PROP"
fi

# If swapspace was configured, swap-on boot
Expand Down
16 changes: 8 additions & 8 deletions system/bin/magiskswap
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ case $COMMAND in
;;
"swappiness")
SWAPPINESS_BACKUP="$(readProp BACKUP-SWAP)"
CURRENT_SWAPPINESS="$(cat "$SWAPPINESS_SYSPATH")"
CURRENT_SWAPPINESS="$(sysctl -n "$SWAPPINESS_SYSCTL_ENTRY")"

if [ "$VALUE" = "show" ];
then
Expand All @@ -186,7 +186,7 @@ case $COMMAND in
if [ "$SWAPPINESS_BACKUP" ];
then
cprint "swappiness has been set to the old value"
setKernelTune "$SWAPPINESS_SYSPATH" "$SWAPPINESS_BACKUP"
setKernelTune "$SWAPPINESS_SYSCTL_ENTRY" "$SWAPPINESS_BACKUP"

# Delete Backup and the property itself
deleteProp "BACKUP-SWAP"
Expand Down Expand Up @@ -214,18 +214,18 @@ case $COMMAND in
fi

# Backup first, so the value can be reset without needing a reboot
modifyProp "BACKUP-SWAP" "$(cat "$SWAPPINESS_SYSPATH")"
modifyProp "BACKUP-SWAP" "$(sysctl -n "$SWAPPINESS_SYSCTL_ENTRY")"

cprint "swappiness has been set to $VALUE"
setKernelTune "$SWAPPINESS_SYSPATH" "$VALUE"
setKernelTune "$SWAPPINESS_SYSCTL_ENTRY" "$VALUE"
modifyProp "SWAPPINESS" "$VALUE"
else
abort "VALUE is missing, or not in range (0-200)"
fi
;;
"vfs-cache-pressure")
VFS_CACHE_PRESSURE_BACKUP="$(readProp "BACKUP-VFS")"
CURRENT_VFS_CACHE_PRESSURE="$(cat "$VFS_CACHE_PRESSURE_SYSPATH")"
CURRENT_VFS_CACHE_PRESSURE="$(sysctl -n "$VFS_CACHE_PRESSURE_SYSCTL_ENTRY")"

if [ "$VALUE" = "show" ];
then
Expand All @@ -241,7 +241,7 @@ case $COMMAND in
if [ "$VFS_CACHE_PRESSURE_BACKUP" ];
then
cprint "VFS cache pressure has been reset to the old value"
setKernelTune "$VFS_CACHE_PRESSURE_SYSPATH" "$VFS_CACHE_PRESSURE_BACKUP"
setKernelTune "$VFS_CACHE_PRESSURE_SYSCTL_ENTRY" "$VFS_CACHE_PRESSURE_BACKUP"

# Delete Backup and the property itself
deleteProp "BACKUP-VFS"
Expand All @@ -258,10 +258,10 @@ case $COMMAND in
elif [ "$VALUE" -ge 1 ];
then
# Backup first, so the value can be reset without needing a reboot
modifyProp "BACKUP-VFS" "$(cat "$VFS_CACHE_PRESSURE_SYSPATH")"
modifyProp "BACKUP-VFS" "$(sysctl -n "$VFS_CACHE_PRESSURE_SYSCTL_ENTRY")"

cprint "VFS cache pressure has been set to $VALUE"
setKernelTune "$VFS_CACHE_PRESSURE_SYSPATH" "$VALUE"
setKernelTune "$VFS_CACHE_PRESSURE_SYSCTL_ENTRY" "$VALUE"
modifyProp "VFS-CACHE-PRESSURE" "$VALUE"
else
abort "VALUE is missing, or not in range (1-∞)"
Expand Down

0 comments on commit c03c1fa

Please sign in to comment.