title: how to test zramfs performance in android?
body: <p>I have followed swap to zram section in this link: <a href="https://source.android.com/devices/low-ram.html" rel="nofollow">https://source.android.com/devices/low-ram.html</a>.</p>
  
  <p>Given in the link:</p>
  
  <pre><code>zRAM swap can increase the amount of memory available in the system by compressing memory pages and putting them in a dynamically allocated swap area of memory.
  
  Again, since this is trading off CPU time for a small increase in memory, you should be careful about measuring the performance impact zRAM swap has on your system.
  
  Android handles swap to zRAM at several levels:
  
  First, the following kernel options must be enabled to use zRAM swap effectively:
  CONFIG_SWAP
  CONFIG_CGROUP_MEM_RES_CTLR
  CONFIG_CGROUP_MEM_RES_CTLR_SWAP
  CONFIG_ZRAM
  Then, you should add a line that looks like this to your fstab:
  /dev/block/zram0 none swap defaults zramsize=&lt;size in bytes&gt;,swapprio=&lt;swap partition priority&gt;
  
  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.
  
  By default, the Linux kernel swaps in 8 pages of memory at a time. When using ZRAM, the incremental cost of reading 1 page at a time is negligible and may help in case the device is under extreme memory pressure. To read only 1 page at a time, add the following to your init.rc:
  `write /proc/sys/vm/page-cluster 0`
  In your init.rc, after the `mount_all /fstab.X` line, add:
  `swapon_all /fstab.X`
  The memory cgroups are automatically configured at boot time if the feature is enabled in kernel.
  If memory cgroups are available, the ActivityManager will mark lower priority threads as being more swappable than other threads. If memory is needed, the Android kernel will start migrating memory pages to zRAM swap, giving a higher priority to those memory pages that have been marked by ActivityManager.
  </code></pre>
  
  <p>As per the steps given below: zramfs is getting created with node /dev/zram0.
  I wanted to test the performance by doing read/write.(I have allotted zram size as 50MB)</p>
  
  <p>For testing I came across the link:<a href="https://code.google.com/p/compcache/wiki/zramperf" rel="nofollow">https://code.google.com/p/compcache/wiki/zramperf</a></p>
  
  <p>Read test given in the link:</p>
  
  <pre><code>Read benchmark
  1G file was copied to (z)ramdisk which was then synchronously read into /dev/null using different block sizes.
  
  if [ -z "$1" ]; then
          echo "Missing file to read into /dev/null"
          exit 1
  else
          FI="$1"
  fi
  
  if [ -z "$2" ]; then
          echo "Missing file to dump output"
          exit 1
  else
          FO="$2"
  fi
  
  for B in 64 128 256 512 1K 2K 4K 8K 16K 32K 64K 128K 256K 512K 1M; do
          echo "$B" | tee -a "$FO"
          echo 1 &gt; /proc/sys/vm/drop_caches
          echo 1 &gt; /proc/sys/vm/drop_caches
          sleep 1
  
          dd if="$FI" of=/dev/null bs="$B" iflag=sync 2&gt;&amp;1 | tee -a "$FO"
  done
  </code></pre>
  
  <p>Write test:</p>
  
  <pre><code>Write benchmark
  First make sure that test (512M) file was completely cached. Then synchronously write this file to (z)ramdisk.
  
  if [ -z "$1" ]; then
          echo "Missing file to be written"
          exit 1
  else
          FI="$1"
  fi
  
  # make sure input file is cached
  dd if="$FI" of=/dev/null
  dd if="$FI" of=/dev/null
  dd if="$FI" of=/dev/null
  dd if="$FI" of=/dev/null
  
  for B in 64 128 256 512 1K 2K 4K 8K 16K 32K 64K 128K 256K 512K 1M; do
          echo "$B" | tee -a "$FO"
          dd if="$FI" of=`basename "$FI"` bs="$B" oflag=sync 2&gt;&amp;1 | tee -a "$FO"
  done
  </code></pre>
  
  <p>I am not comfortable with shell. Further someone please tell what should i give arg option for 1 and 2 in read benchmark and arg option 1 in write benchmark.</p>
  
  <p>Please help me run performance test on this.
  thanks.</p>