From eb1e8ce8f8319ae00be846b7e6343ea7ab88e167 Mon Sep 17 00:00:00 2001 From: AmadeusGhost <42570690+AmadeusGhost@users.noreply.github.com> Date: Sat, 5 Jun 2021 10:32:05 +0800 Subject: [PATCH] zram-swap: sync upstream source (#6930) --- package/system/zram-swap/Makefile | 14 ++++++--- package/system/zram-swap/files/zram.init | 38 +++++++++--------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/package/system/zram-swap/Makefile b/package/system/zram-swap/Makefile index 486a60085..a659db73e 100644 --- a/package/system/zram-swap/Makefile +++ b/package/system/zram-swap/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=zram-swap PKG_VERSION:=1.1 -PKG_RELEASE:=6 +PKG_RELEASE:=8 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) @@ -18,14 +18,20 @@ include $(INCLUDE_DIR)/package.mk define Package/zram-swap SECTION:=utils CATEGORY:=Base system - DEPENDS:=+kmod-zram +!(BUSYBOX_CONFIG_MKSWAP&&BUSYBOX_CONFIG_SWAPON&&BUSYBOX_CONFIG_SWAPOFF):swap-utils + DEPENDS:= \ + +@BUSYBOX_CONFIG_FEATURE_SWAPON_DISCARD \ + +@BUSYBOX_CONFIG_FEATURE_SWAPON_PRI \ + +@BUSYBOX_CONFIG_MKSWAP \ + +@BUSYBOX_CONFIG_SWAPOFF \ + +@BUSYBOX_CONFIG_SWAPON \ + +kmod-zram TITLE:=ZRAM swap scripts PKGARCH:=all endef define Package/zram-swap/description - A script to activate swaping on a compressed zram partition. This - could be used to increase the available memory, by using compressed + A script to activate swaping on a compressed zram partition. This + could be used to increase the available memory, by using compressed memory. endef diff --git a/package/system/zram-swap/files/zram.init b/package/system/zram-swap/files/zram.init index 42c084855..6338bdfa5 100755 --- a/package/system/zram-swap/files/zram.init +++ b/package/system/zram-swap/files/zram.init @@ -35,18 +35,18 @@ zram_applicable() return 1 } - command -v mkswap >/dev/null || { - logger -s -t zram_applicable -p daemon.err "[ERROR] 'mkswap' not installed" + [ -x /sbin/mkswap ] || { + logger -s -t zram_applicable -p daemon.err "[ERROR] 'BusyBox mkswap' not installed" return 1 } - command -v swapon >/dev/null || { - logger -s -t zram_applicable -p daemon.err "[ERROR] 'swapon' not installed" + [ -x /sbin/swapon ] || { + logger -s -t zram_applicable -p daemon.err "[ERROR] 'BusyBox swapon' not installed" return 1 } - command -v swapoff >/dev/null || { - logger -s -t zram_applicable -p daemon.err "[ERROR] 'swapoff' not installed" + [ -x /sbin/swapoff ] || { + logger -s -t zram_applicable -p daemon.err "[ERROR] 'BusyBox swapoff' not installed" return 1 } } @@ -97,19 +97,6 @@ zram_comp_algo() fi } -zram_comp_streams() -{ - local dev="$1" - local logical_cpus=$( grep -ci "^processor" /proc/cpuinfo ) - [ $logical_cpus -gt 1 ] || return 1 - local zram_comp_streams="$( uci -q get system.@system[0].zram_comp_streams )" - [ -n "$zram_comp_streams" ] && [ "$zram_comp_streams" -le "$logical_cpus" ] || zram_comp_streams=$logical_cpus - if [ -e /sys/block/$( basename $dev )/max_comp_streams ]; then - logger -s -t zram_comp_streams -p daemon.debug "Set max compression streams to '$zram_comp_streams' for zram '$dev'" - echo $zram_comp_streams > /sys/block/$( basename $dev )/max_comp_streams - fi -} - #print various stats info about zram swap device zram_stats() { @@ -121,7 +108,6 @@ zram_stats() printf "%-25s - %s\n" "Block device" $zdev awk '{ printf "%-25s - %d MiB\n", "Device size", $1/1024/1024 }' <$zdev/disksize printf "%-25s - %s\n" "Compression algo" "$(cat $zdev/comp_algorithm)" - printf "%-25s - %s\n" "Compression streams" "$( cat $zdev/max_comp_streams)" awk 'BEGIN { fmt = "%-25s - %.2f %s\n" fmt2 = "%-25s - %d\n" @@ -164,6 +150,11 @@ zram_compact() start() { + [ -e /proc/swaps ] || { + logger -s -t zram_start -p daemon.crit "kernel doesn't support swap" + return 1 + } + if [ $( grep -cs zram /proc/swaps ) -ne 0 ]; then logger -s -t zram_start -p daemon.notice "[OK] zram swap is already mounted" return 1 @@ -179,10 +170,9 @@ start() zram_reset "$zram_dev" "enforcing defaults" zram_comp_algo "$zram_dev" - zram_comp_streams "$zram_dev" echo $(( $zram_size * 1024 * 1024 )) >"/sys/block/$( basename "$zram_dev" )/disksize" - mkswap "$zram_dev" - swapon -d $zram_priority "$zram_dev" + /sbin/mkswap "$zram_dev" + /sbin/swapon -d $zram_priority "$zram_dev" } stop() @@ -191,7 +181,7 @@ stop() for zram_dev in $( grep zram /proc/swaps |awk '{print $1}' ); do { logger -s -t zram_stop -p daemon.debug "deactivate swap $zram_dev" - swapoff "$zram_dev" && zram_reset "$zram_dev" "claiming memory back" + /sbin/swapoff "$zram_dev" && zram_reset "$zram_dev" "claiming memory back" local dev_index="$( echo $zram_dev | grep -o "[0-9]*$" )" if [ $dev_index -ne 0 ]; then logger -s -t zram_stop -p daemon.debug "removing zram $zram_dev"