mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 14:23:38 +00:00
zram-swap: sync upstream source (#6930)
This commit is contained in:
parent
9ae00955cc
commit
eb1e8ce8f8
@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=zram-swap
|
PKG_NAME:=zram-swap
|
||||||
PKG_VERSION:=1.1
|
PKG_VERSION:=1.1
|
||||||
PKG_RELEASE:=6
|
PKG_RELEASE:=8
|
||||||
|
|
||||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||||
|
|
||||||
@ -18,14 +18,20 @@ include $(INCLUDE_DIR)/package.mk
|
|||||||
define Package/zram-swap
|
define Package/zram-swap
|
||||||
SECTION:=utils
|
SECTION:=utils
|
||||||
CATEGORY:=Base system
|
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
|
TITLE:=ZRAM swap scripts
|
||||||
PKGARCH:=all
|
PKGARCH:=all
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/zram-swap/description
|
define Package/zram-swap/description
|
||||||
A script to activate swaping on a compressed zram partition. This
|
A script to activate swaping on a compressed zram partition. This
|
||||||
could be used to increase the available memory, by using compressed
|
could be used to increase the available memory, by using compressed
|
||||||
memory.
|
memory.
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
@ -35,18 +35,18 @@ zram_applicable()
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
command -v mkswap >/dev/null || {
|
[ -x /sbin/mkswap ] || {
|
||||||
logger -s -t zram_applicable -p daemon.err "[ERROR] 'mkswap' not installed"
|
logger -s -t zram_applicable -p daemon.err "[ERROR] 'BusyBox mkswap' not installed"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
command -v swapon >/dev/null || {
|
[ -x /sbin/swapon ] || {
|
||||||
logger -s -t zram_applicable -p daemon.err "[ERROR] 'swapon' not installed"
|
logger -s -t zram_applicable -p daemon.err "[ERROR] 'BusyBox swapon' not installed"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
command -v swapoff >/dev/null || {
|
[ -x /sbin/swapoff ] || {
|
||||||
logger -s -t zram_applicable -p daemon.err "[ERROR] 'swapoff' not installed"
|
logger -s -t zram_applicable -p daemon.err "[ERROR] 'BusyBox swapoff' not installed"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,19 +97,6 @@ zram_comp_algo()
|
|||||||
fi
|
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
|
#print various stats info about zram swap device
|
||||||
zram_stats()
|
zram_stats()
|
||||||
{
|
{
|
||||||
@ -121,7 +108,6 @@ zram_stats()
|
|||||||
printf "%-25s - %s\n" "Block device" $zdev
|
printf "%-25s - %s\n" "Block device" $zdev
|
||||||
awk '{ printf "%-25s - %d MiB\n", "Device size", $1/1024/1024 }' <$zdev/disksize
|
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 algo" "$(cat $zdev/comp_algorithm)"
|
||||||
printf "%-25s - %s\n" "Compression streams" "$( cat $zdev/max_comp_streams)"
|
|
||||||
|
|
||||||
awk 'BEGIN { fmt = "%-25s - %.2f %s\n"
|
awk 'BEGIN { fmt = "%-25s - %.2f %s\n"
|
||||||
fmt2 = "%-25s - %d\n"
|
fmt2 = "%-25s - %d\n"
|
||||||
@ -164,6 +150,11 @@ zram_compact()
|
|||||||
|
|
||||||
start()
|
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
|
if [ $( grep -cs zram /proc/swaps ) -ne 0 ]; then
|
||||||
logger -s -t zram_start -p daemon.notice "[OK] zram swap is already mounted"
|
logger -s -t zram_start -p daemon.notice "[OK] zram swap is already mounted"
|
||||||
return 1
|
return 1
|
||||||
@ -179,10 +170,9 @@ start()
|
|||||||
|
|
||||||
zram_reset "$zram_dev" "enforcing defaults"
|
zram_reset "$zram_dev" "enforcing defaults"
|
||||||
zram_comp_algo "$zram_dev"
|
zram_comp_algo "$zram_dev"
|
||||||
zram_comp_streams "$zram_dev"
|
|
||||||
echo $(( $zram_size * 1024 * 1024 )) >"/sys/block/$( basename "$zram_dev" )/disksize"
|
echo $(( $zram_size * 1024 * 1024 )) >"/sys/block/$( basename "$zram_dev" )/disksize"
|
||||||
mkswap "$zram_dev"
|
/sbin/mkswap "$zram_dev"
|
||||||
swapon -d $zram_priority "$zram_dev"
|
/sbin/swapon -d $zram_priority "$zram_dev"
|
||||||
}
|
}
|
||||||
|
|
||||||
stop()
|
stop()
|
||||||
@ -191,7 +181,7 @@ stop()
|
|||||||
|
|
||||||
for zram_dev in $( grep zram /proc/swaps |awk '{print $1}' ); do {
|
for zram_dev in $( grep zram /proc/swaps |awk '{print $1}' ); do {
|
||||||
logger -s -t zram_stop -p daemon.debug "deactivate swap $zram_dev"
|
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]*$" )"
|
local dev_index="$( echo $zram_dev | grep -o "[0-9]*$" )"
|
||||||
if [ $dev_index -ne 0 ]; then
|
if [ $dev_index -ne 0 ]; then
|
||||||
logger -s -t zram_stop -p daemon.debug "removing zram $zram_dev"
|
logger -s -t zram_stop -p daemon.debug "removing zram $zram_dev"
|
||||||
|
Loading…
Reference in New Issue
Block a user