« Previous 1 2
Stretching devices with limited resources
Fewer Memories
Setup
Zswap is easily configured by passing the parameter zswap.enabled=1
to the kernel at boot in GRUB configuration options. Zram is more complicated, and not nearly as well documented as one would expect in most distributions. Listing 2 shows how to set up two swap devices (and how to initialize and tear down the first one) with exclusively manual steps on Ubuntu Server 20.04 LTS. Listing 3 makes use of the zram-config
package found in Ubuntu (again, Server version 20.04 LTS) to automate part of the process to mount a second device as a RAM drive for /var/logs
.
Listing 2
Initializing Zram the Hard Way
# Aligning versions between kernel and modules referenced by virtual package $ sudo apt update; sudo apt upgrade $ sudo apt install -y linux-image-extra-virtual # Create half a gigabyte ZRAM device at next available device file $ zramctl --find --size=512M /dev/zram0 $ zramctl NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT /dev/zram0 lzo-rle 512M 0B 0B 0B 2 # Make the ZRAM block device into a swap partition $ sudo mkswap /dev/zram0 Setting up swapspace version 1, size = 512 MiB (536866816 bytes) no label, UUID=0818f196-4e38-43be-88ad-de6b45f50ce5 # Turn the swap partition on $ Swapon /dev/zram0 $ zramctl NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT /dev/zram0 lzo-rle 512M 4K 73B 12K 2 [SWAP] # Cleanup procedure (destroy the ZRAM setup) $ sudo swapoff /dev/zram0 $ sudo zramctl --reset /dev/zram0
Listing 3
Initializing Zram the Easy Way
# install Ubuntu's ZRAM management package $ sudo apt install zram-config # start the service $ sudo systemctl start zram-config $ zramctl NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT /dev/zram1 lzo-rle 495.8M 4K 73B 12K 2 [SWAP] # Now let's make a ramdrive for /var/logs $ zramctl --find --size=512M /dev/zram0 # lay a filesystem on the ramdrive $ sudo mkfs.ext2 -q /dev/zram0 # mount the ramdrive $ sudo mount /dev/zram0 /var/log $ zramctl NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT /dev/zram0 lzo-rle 512M 208K 3.1K 48K 2 /var/log /dev/zram1 lzo-rle 495.8M 4K 73B 12K 2 [SWAP]
Infos
- "Assess USB performance while exploring storage caching" by Federico Lucifredi, ADMIN , issue 48, 2018, pg. 94, https://www.admin-magazine.com/Archive/2018/48/Assess-USB-performance-while-exploring-storage-caching
- Marvell ESPRESSObin v7: http://wiki.espressobin.net/tiki-index.php
- Serial 2.12 for Macintosh: https://www.decisivetactics.com/products/serial/
- Das U-Boot – the Universal Boot Loader: https://www.denx.de/wiki/U-Boot
- Yocto Project: https://www.yoctoproject.org
- Armbian – Linux for ARM development boards: https://www.armbian.com/espressobin/
- "Swap tricks" by Federico Lucifredi, ADMIN , issue 9, 2012, pg. 83
- Kernel docs for zram: https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html
- Kernel docs for zswap: https://www.kernel.org/doc/html/latest/admin-guide/mm/zswap.html
- free(1) man page: https://linux.die.net/man/1/free
« Previous 1 2
Buy this article as PDF
(incl. VAT)