memory-managementlinux-kernelandroid-kernel

How to enable zram swap in Android Build/kernel?


How to enable zram as swap device in android linux kernel ? Is there any way create zram before init process ? kernelcmdline or kernel config.

As per zram.txt no default way.


Solution

  • Here is the answer (from Android build zram):

    1. Enable zram in kernel config as built in module.

    2. Add the below line in your fstab file

      /dev/block/zram0 none swap defaults zramsize=size in bytes,swapprio=swap partition priority
      
      • zramsize is mandatory and indicates how much uncompressed memory you want the zram area to hold. Compression ratios in the 30-50% range are usually observed.

      • swapprio is optional and not needed if you don't have more than one swap area.

    3. In init.rc add the following line:

      swapon_all /fstab.X