Create ZRam a Memory Compression on Arch Linux

Embed Size (px)

Citation preview

  • 8/19/2019 Create ZRam a Memory Compression on Arch Linux

    1/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 algorithmthat compress the least recently used (LRU) or inactive space in the memory allows the GNU/Linux kernel to freeup more memory with less performance hit.

    zRam is greatly increasing the available amount of memory without swap disks/partition. It is recommendedfor 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

    Aut omatically 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

    http://www.techrapid.co.uk/linux/arch-linux/create-zram-memory-compression-on-arch-linuxhttp://www.techrapid.co.uk/linux/arch-linux/create-zram-memory-compression-on-arch-linux

  • 8/19/2019 Create ZRam a Memory Compression on Arch Linux

    2/3

    1234567891011

    [Unit]Description=zRam block devices swapping[Service]Type=oneshotExecStart=/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 LinuxUpdating Dynamic DNS (DDNS) With Wget on Linux

    http://www.techrapid.co.uk/linux/updating-dynamic-dns-ddns-with-wget-on-linux/http://www.techrapid.co.uk/linux/arch-linux/improve-font-rendering-on-arch-linux/http://www.techrapid.co.uk/linux/arch-linux/install-kde-plasma-on-arch-linux/http://www.techrapid.co.uk/linux/arch-linux/install-aur-package-with-yaourt-on-arch-linux/http://www.techrapid.co.uk/linux/arch-linux/automatic-update-arch-linux-with-systemd/http://creativecommons.org/publicdomain/zero/1.0/deed.enhttp://pixabay.com/en/users/TobiasD-206193/http://pixabay.com/en/users/TobiasD-206193/https://www.kernel.org/doc/Documentation/blockdev/zram.txthttps://wiki.archlinux.org/index.php/Maximizing_performance#Zram_or_zswap

  • 8/19/2019 Create ZRam a Memory Compression on Arch Linux

    3/3