[ASUS ZenFone 8] bnsmb:
How to disable or change the swap device in the Android 12 from ASUS for the Zenfone 8

In the original Android 12 from ASUS for the Zenfone 8 a swap device is configured by default:

ASUS_I006D:/ # getprop ro.product.build.fingerprint
asus/WW_I006D/ASUS_I006D:12/SKQ1.210821.001/31.1010.0411.113:user/release-keys
ASUS_I006D:/ #

ASUS_I006D:/ # getprop ro.product.build.date
Wed Jul 27 02:56:23 CST 2022
ASUS_I006D:/ #

ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7389499392 223170560 84582400 12218368
-/+ buffers/cache: 7377281024 235388928
Swap: 4294963200 0 4294963200
ASUS_I006D:/ #

Note:

All commands in these instructions must be done by the user root.

To disable the swap device in the Android 12 from ASUS open a shell and execute:

setprop vendor.zram.enable 0

Example:

ASUS_I006D:/data/adb/workdir/ramdisk # free
total used free shared buffers
Mem: 7612669952 7334137856 278532096 82571264 19410944
-/+ buffers/cache: 7314726912 297943040
Swap: 4294963200 0 4294963200
root@ASUS_I006D:/data/adb/workdir/ramdisk #

ASUS_I006D:/ # setprop vendor.zram.enable 0
ASUS_I006D:/ #

ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7392669696 220000256 84586496 12263424
-/+ buffers/cache: 7380406272 232263680
Swap: 0 0 0
ASUS_I006D:/ #

Note:

To execute the command via adb use

adb shell su - -c setprop vendor.zram.enable 0

To re-enable the swap device execute as user root :

setprop vendor.zram.enable 1

e.g.

ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7392796672 219873280 84598784 12288000
-/+ buffers/cache: 7380508672 232161280
Swap: 0 0 0
ASUS_I006D:/ #

ASUS_I006D:/ # setprop vendor.zram.enable 1
ASUS_I006D:/ #

ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7397068800 215601152 84598784 12292096
-/+ buffers/cache: 7384776704 227893248
Swap: 4294963200 0 4294963200
ASUS_I006D:/ #

To change the size of the swap device change the value for the variable

vendor.zram.disksize

and disable and re-enable the swap device. The default unit for the value of the variable vendor.zram.disksize is byte; use the postfix M for megabytes or G for gigabytes.

e.g. to use a swap device with 2 GB do:

ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7398703104 213966848 84631552 12365824
-/+ buffers/cache: 7386337280 226332672
Swap: 4294963200 0 4294963200
ASUS_I006D:/ #

ASUS_I006D:/ # setprop vendor.zram.enable 0
ASUS_I006D:/ #

ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7394570240 218099712 84631552 12361728
-/+ buffers/cache: 7382208512 230461440
Swap: 0 0 0
ASUS_I006D:/ #

ASUS_I006D:/ # setprop vendor.zram.disksize 2G
ASUS_I006D:/ #

ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7533645824 79024128 86020096 12369920
-/+ buffers/cache: 7521275904 91394048
Swap: 0 0 0
ASUS_I006D:/ #

ASUS_I006D:/ # setprop vendor.zram.enable 1
ASUS_I006D:/ #

ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7514472448 98197504 85999616 12374016
-/+ buffers/cache: 7502098432 110571520
Swap: 2147479552 0 2147479552
ASUS_I006D:/ #

Note:

This can also be done in a Magisk script to make the new config for the swap device persistent:

e.g.

cat <<EOT >/data/adb/service.d/0010reconfigure_swap
#
# change the size of the swap volume to 2 GB
#
setprop vendor.zram.enable 0
setprop vendor.zram.disksize 2G
setprop vendor.zram.enable 1
EOT

chmod 755 /data/adb/service.d/0010reconfigure_swap

Result after a reboot:

ASUS_I006D:/ $ free
total used free shared buffers
Mem: 7612669952 6047076352 1565593600 58441728 17780736
-/+ buffers/cache: 6029295616 1583374336
Swap: 2147479552 0 2147479552
ASUS_I006D:/ $

To disable the swap device completely via Magisk script use these commands:

cat <<EOT >/data/adb/service.d/0010disable_swap
#
# disable the swap device
#
setprop vendor.zram.enable 0
EOT

chmod 755 /data/adb/service.d/0010disable_swap

Result after a reboot:

shell@ASUS_I006D:/ $ free
total used free shared buffers
Mem: 7612669952 5930426368 1682243584 55574528 17719296
-/+ buffers/cache: 5912707072 1699962880
Swap: 0 0 0
shell@ASUS_I006D:/ $

Note that this approach does not work in the OmniROM 12 for the ASUS Zenfone 8.

Update 20.09.2022 /bs

see How to create or change a swap device in the OmniROM using Magisk for how to change or disable the swap device in the OmniROM.

Update 04.10.2022 /bs

See How to trigger an action when a property is changed for how to implement enabling or disabling the swap device on ZRAM via a property value in the OmniROM or other OS