From: Emil Muratov Date: Sun, 24 Feb 2019 07:00:03 +0000 (+0300) Subject: zram-swap: Add extra commands for status/compaction X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=1d68badbb3c10da3b70cac6a2768f7b86e49de86;p=openwrt%2Fstaging%2Fadrian.git zram-swap: Add extra commands for status/compaction This patch adds two new commands: zram status - shows memory stats for all zram swaps zram compaction - trigger compaction for all zram swaps Signed-off-by: Emil Muratov Signed-off-by: Christian Lamparter (cherry picked from commit a9deed62af569608af3e4e076138d788e24b1652) --- diff --git a/package/system/zram-swap/files/zram.init b/package/system/zram-swap/files/zram.init index 6b5714bb1c..ae432f3b00 100755 --- a/package/system/zram-swap/files/zram.init +++ b/package/system/zram-swap/files/zram.init @@ -2,17 +2,21 @@ START=15 -ram_size() +EXTRA_COMMANDS="compact status" +EXTRA_HELP=" compact trigger compaction for all Z-RAM swap dev's + status print out status information & statistics about Z-RAM swap devices" + +ram_getsize() { local line while read line; do case "$line" in MemTotal:*) set $line; echo "$2"; break ;; esac; done $zdev/compact + + # If not running interactively, than just return + [ -z "$PS1" ] && return 0 + + echo "" + echo "Compacting zram device $zdev" awk -v old_mem="$old_mem_used" -v ovr="$old_overhead" 'BEGIN { fmt = "%-25s - %.1f %s\n" } { printf fmt, "Memory usage reduced by ", (old_mem-$3)/1024/1024, "MiB" printf fmt, "Overhead reduced by", (ovr-($3-$2))/ovr*100, "%" }' <$zdev/mm_stat @@ -156,23 +164,13 @@ zram_compact() start() { - local zram_size="$( zram_size )" - local zram_dev - if [ $( grep -cs zram /proc/swaps ) -ne 0 ]; then logger -s -t zram_start -p daemon.notice "[OK] zram swap is already mounted" - # If not running interactively, than just quit - [ -z "$PS1" ] && return 1 - - # show memory stats and compact all zram swaps - for zram_dev in $( grep zram /proc/swaps |awk '{print $1}' ); do { - zram_compact "$zram_dev" - zram_stats "$zram_dev" - } done - return + return 1 fi - zram_dev="$( zram_getdev )" + local zram_size="$( zram_getsize )" + local zram_dev="$( zram_getdev )" zram_applicable "$zram_dev" || return 1 logger -s -t zram_start -p daemon.debug "activating '$zram_dev' for swapping ($zram_size MegaBytes)" @@ -200,3 +198,18 @@ stop() } done } +# show memory stats for all zram swaps +status() +{ + for zram_dev in $( grep zram /proc/swaps |awk '{print $1}' ); do { + zram_stats "$zram_dev" + } done +} + +# trigger compaction for all zram swaps +compact() +{ + for zram_dev in $( grep zram /proc/swaps |awk '{print $1}' ); do { + zram_compact "$zram_dev" + } done +}