How to use the Linux system swap and zram swap?

  

Swap and zram under Linux are two techniques for expanding memory, which can indicate the performance of the system to a certain extent. Of course, swap and zram swap, in general, the use of zram is more. Here's how to use the Linux system swap and zram swap?

Disk swap: is the part of the disk as memory, the application is completely transparent, comparable to the increased memory, but the disadvantage is obvious, when used in the swap, speed It is very slow.

zram: It is to divide a part of the physical memory, compress the memory data that is not commonly used, and put it into zram. When it is used, the data is decompressed, which is equivalent to sacrificing some CPU efficiency and increasing disguised. The memory.

If the device supports zram, it is definitely preferred to use zram, but some device kernels are older, only use disk swap.

To see if the device is zram:

adb to the shell in the device, cd /dev/block/, see if there is zram0 or zram1

If there is no such file It is not necessarily that the device does not support zram. It is also possible that the zram option is not checked in the kernel. You can search for zram in the kernel source.

The following is a script that was written: use disk swap

#! /system/bin/sh

#SWAP_FILE=“/data/swap1”

if [ ! -f “/data/swap1” ]; then

dd if=/dev/zero of=/data/swap1 bs=390250 count=256

fi

Busybox mkswap /data/swap1

busybox swapon -p 0 /data/swap1

echo 0 》/proc/sys/vm/swappiness

cat /proc/sys/Vm/swappiness

busybox free -m

The value in /proc/sys/vm/swappiness represents the priority of using swap, 0 is not used, 100 means maximum use

Update:

If you want to know which swap file the current swap uses,

cat /proc/swap will know.

The above is the use of the Linux system swap and zram swap. If your computer's memory is too small, you can use swap or zram swap to expand the memory.

Copyright © Windows knowledge All Rights Reserved