How to enable zram
This document is following the procedures metioned by [1].
When memory was low, system would unresponsive and even freeze. ZRAM creates RAM based
block storage named /dev/zram0 (or 1, 2, 3, etc). Pages written there are compressed and stored
in memory. This allows for very fast I/O and the compression savings provide additional memory.
See the document in detail.
1. Quick
sudo apt install zram-tools sudo vi /etc/default/zramswap
File: /etc/default/zramswap ... PERCENT=50 # 50% ram use zram .... |
sudo zramswap stop sudo zramswap start sudo zramswap status
# Kernel sudo vi /etc/sysctl.conf
File: /etc/sysctl.conf vm.vfs_cache_pressure=500 vm.swappiness=100 vm.dirty_background_ratio=1 vm.dirty_ratio=50 |
sudo sysctl --system # enable the parameters |
2. Procedure
2.1. Before
Verification
free -m sudo cat /proc/swaps |

2.2. Install zram-tool
sudo apt install zram-tools |
E.g.

Check
sudo cat /proc/swaps

zramswap status

2.3. Config
sudo vi /etc/default/zramswap
File: /etc/default/zramswap ... PERCENT=50 # 50% ram use zram .... |
sudo zramswap stop sudo zramswap start sudo zramswap status |
E.g.

2.4. Verification
sudo zramswap status
E.g.

3. Setup Kernel parameters
3.1. Before
sudo cat /proc/swaps

3.2. Setup
sudo vi /etc/sysctl.conf
File: /etc/sysctl.conf vm.vfs_cache_pressure=500 vm.swappiness=100 vm.dirty_background_ratio=1 vm.dirty_ratio=50 |
sudo sysctl --system |
E.g.

3.3. Verification
sudo cat /proc/swaps

4. References
https://haydenjames.io/raspberry-pi-performance-add-zram-kernel-parameters/
https://www.kernel.org/doc/Documentation/blockdev/zram.txt