Você está na página 1de 3

Create zRam a Memory Compression on Arch Linux

www.techrapid.co.uk /linux/arch-linux/create-zram-memory-compression-on-arch-linux
zRam is a virtual memory compression using block devices named /dev/zram using a fast compression algorithm
that compress the least recently used (LRU) or inactive space in the memory allows the GNU/Linux kernel to free
up more memory with less performance hit.
zRam is greatly increasing the available amount of memory without swap disks/partition. It is recommended
for user to use zRam instead of not using swap or swap on slow disks.

Create a zRam block devices


Load the zRam modules to the kernel using modprobe:
Shell
1

sudo modprobe zram

Set the zRam extremely fast compression algorithm using lz4:


Shell
1

sudo sh -c "echo 'lz4' > /sys/block/zram0/comp_algorithm"

Set 2 Gigabyte available zRam disk space for swap:


Shell
1

sudo sh -c "echo '2G' > /sys/block/zram0/disksize"

Create a swap on zRam block devices:


Shell
1

sudo mkswap --label zram0 /dev/zram0

Enable the zRam block devices for swapping with high priority:
Shell
1

sudo swapon --priority 100 /dev/zram0

Automatically activate zRam swap at startup


Create a systemd service (zram.service) using a text editor such as nano:
Shell
1

sudo nano /etc/systemd/system/zram.service

Add following to the zram.service:


Shell

1
2
3
4
5
6
7
8
9
10
11

[Unit]
Description=zRam block devices swapping
[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c "modprobe zram && echo lz4 > /sys/block/zram0/comp_algorithm | echo 2G >
/sys/block/zram0/disksize && mkswap --label zram0 /dev/zram0 && swapon --priority 100 /dev/zram0"
ExecStop=/usr/bin/bash -c "swapoff /dev/zram0 && rmmod zram"
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

Enable the zram.service to automatically run at startup:


Shell
1

sudo systemctl enable zram

Disable zRam block devices


Disable the zRam block devices swapping:
Shell
1

sudo swapoff /dev/zram0

Remove the zRam module from the kernel:


Shell
1

sudo rmmod zram

Disable the zram.service from automatically run at startup:


Shell
1

sudo systemctl disable zram.service

See also
1. Zram or zswap section (Maximizing Performance) ArchWiki
2. zram: Compressed RAM based block devices Linux Kernel Documentation
3. Image by TobiasD / CC0 Public Domain

Related Articles
Automatically Update Arch Linux with Systemd
Install AUR Packages with Yaourt on Arch Linux
Install KDE Plasma 5 on Arch Linux
Improve Fonts Rendering Quality on Arch Linux
Updating Dynamic DNS (DDNS) With Wget on Linux

Você também pode gostar