zram-swap: fix zram dev reset for multicore cpu devices
authorEmil Muratov <gpm@hotplug.ru>
Wed, 1 Aug 2018 21:18:45 +0000 (00:18 +0300)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 29 Sep 2018 15:23:11 +0000 (17:23 +0200)
 * "zram stop" could reset up to $(num_of_cores) zram devices even if
   some of those were not mounted as swap dev's. This fix tries to
   enumerate mounted swap zram dev's before making a reset

 * remove hot-added zram devs on stop (except zram0)

Signed-off-by: Emil Muratov <gpm@hotplug.ru>
package/system/zram-swap/files/zram.init

index 419221b1a3ac173672333e5c6bba0ad83588f45e..1eba3f4d98b800ea8f986ee36d0a770c429c34c1 100644 (file)
@@ -133,18 +133,16 @@ start()
 
 stop()
 {
-       local zram_dev proc_entry
-
-       for core in $( list_cpu_idx ); do {
-               zram_dev="$( zram_dev "$core" )"
-               proc_entry="/sys/block/$( basename "$zram_dev" )/reset"
-
-               grep -sq ^"$zram_dev " /proc/swaps && {
-                       logger -s -t zram_stop -p daemon.debug "deactivate swap $zram_dev"
-                       swapoff "$zram_dev"
-               }
-
-               zram_reset "$zram_dev" "claiming memory back"
+       local zram_dev
+
+       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"
+               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"
+                       echo $dev_index > /sys/class/zram-control/hot_remove
+               fi
        } done
 }