17483c8fbcf4a4d33410abe7190385daaafb6d02
1 #!/bin/sh /etc/rc.common
9 while read line
; do case "$line" in MemTotal
:*) set $line; echo "$2"; break ;; esac; done </proc
/meminfo
12 zram_size
() # in megabytes
14 local zram_size
="$( uci -q get system.@system[0].zram_size_mb )"
15 local ram_size
="$( ram_size )"
17 if [ -z "$zram_size" ]; then
18 # e.g. 6mb for 16mb-routers or 61mb for 128mb-routers
19 echo $
(( $ram_size / 2048 ))
29 grep -sq ^
"$zram_dev " /proc
/swaps
&& {
30 logger
-s -t zram_applicable
-p daemon.notice
"[OK] '$zram_dev' already active"
34 [ -e "$zram_dev" ] ||
{
35 logger
-s -t zram_applicable
-p daemon.crit
"[ERROR] device '$zram_dev' not found"
39 which mkswap
>/dev
/null ||
{
40 logger
-s -t zram_applicable
-p daemon.err
"[ERROR] 'mkswap' not installed"
44 which swapon
>/dev
/null ||
{
45 logger
-s -t zram_applicable
-p daemon.err
"[ERROR] 'swapon' not installed"
49 which swapoff
>/dev
/null ||
{
50 logger
-s -t zram_applicable
-p daemon.err
"[ERROR] 'swapoff' not installed"
59 echo "/dev/zram${core:-0}"
66 local proc_entry
="/sys/block/$( basename "$dev" )/reset"
68 logger
-s -t zram_reset
-p daemon.debug
"$message via $proc_entry"
69 echo "1" >"$proc_entry"
74 # Offset by 1 if /dev/zram0 is in use by /tmp
75 if [ "$(mount | grep /dev/zram0)" ]; then
77 # Hot-add new ZRAM device (if necessary)
78 if [ ! -b /dev
/zram1
]; then
79 cat /sys
/class
/zram-control
/hot_add
92 } done <"/proc/cpuinfo"
97 # http://shmilyxbq-compcache.googlecode.com/hg/README
98 # if >1 cpu_core, reinit kmodule with e.g. num_devices=4
100 local zram_size
="$( zram_size )"
103 for core
in $
( list_cpu_idx
); do {
104 zram_dev
="$( zram_dev "$core" )"
105 zram_applicable
"$zram_dev" ||
return 1
107 logger
-s -t zram_start
-p daemon.debug
"activating '$zram_dev' for swapping ($zram_size MegaBytes)"
109 zram_reset
"$zram_dev" "enforcing defaults"
110 echo $
(( $zram_size * 1024 * 1024 )) >"/sys/block/$( basename $zram_dev )/disksize"
118 local zram_dev proc_entry
120 for core
in $
( list_cpu_idx
); do {
121 zram_dev
="$( zram_dev "$core" )"
122 proc_entry
="/sys/block/$( basename "$zram_dev" )/reset"
124 grep -sq ^
"$zram_dev " /proc
/swaps
&& {
125 logger
-s -t zram_stop
-p daemon.debug
"deactivate swap $zram_dev"
129 zram_reset
"$zram_dev" "claiming memory back"