aboutsummaryrefslogtreecommitdiffstats
path: root/package/system/zram-swap
diff options
context:
space:
mode:
authorEmil Muratov <gpm@hotplug.ru>2019-02-24 10:00:03 +0300
committerChristian Lamparter <chunkeey@gmail.com>2019-07-07 13:02:06 +0200
commita9deed62af569608af3e4e076138d788e24b1652 (patch)
tree9029beb32b0bbd5263a64df2eeeda70a2b761bd8 /package/system/zram-swap
parentafa5ce2493505dc0a0de4cefa9ccbf3a6389bdbc (diff)
downloadupstream-a9deed62af569608af3e4e076138d788e24b1652.tar.gz
upstream-a9deed62af569608af3e4e076138d788e24b1652.tar.bz2
upstream-a9deed62af569608af3e4e076138d788e24b1652.zip
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 <gpm@hotplug.ru> Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Diffstat (limited to 'package/system/zram-swap')
-rwxr-xr-xpackage/system/zram-swap/files/zram.init55
1 files changed, 34 insertions, 21 deletions
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 </proc/meminfo
}
-zram_size() # in megabytes
+zram_getsize() # in megabytes
{
local zram_size="$( uci -q get system.@system[0].zram_size_mb )"
- local ram_size="$( ram_size )"
+ local ram_size="$( ram_getsize )"
if [ -z "$zram_size" ]; then
# e.g. 6mb for 16mb-routers or 61mb for 128mb-routers
@@ -106,9 +110,9 @@ zram_comp_streams()
fi
}
+#print various stats info about zram swap device
zram_stats()
{
- #print various stats info about zram swap device
local zdev="/sys/block/$( basename "$1" )"
printf "\nGathering stats info for zram device \"$( basename "$1" )\"\n\n"
@@ -143,12 +147,16 @@ zram_compact()
# compact zram device (reduce memory allocation overhead)
local zdev="/sys/block/$( basename "$1" )"
- old_mem_used=`awk '{print $3}' <$zdev/mm_stat`
- old_overhead=`awk '{print $3-$2}' <$zdev/mm_stat`
+ local old_mem_used=`awk '{print $3}' <$zdev/mm_stat`
+ local old_overhead=`awk '{print $3-$2}' <$zdev/mm_stat`
- echo ""
- echo "Compacting zram device..."
echo 1 > $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
+}