Candid photograph of a Linux server terminal with a soft olive-green glow against a dark slate background, conveying a calm technical atmosphere.

Step-by-step guides for system administrators — covering command-line basics, web server setup, and preparation material for technical interviews.

Browse Tutorials

Managing zram and swap for memory optimisation on RHEL

zram is a compressed RAM block device that RHEL can use as swap. It packs anonymous pages into memory, reducing reliance on fast storage during brief memory pressure. It does not add physical RAM; compression consumes CPU and memory.

Conventional disk swap remains useful for cold pages, while zram avoids disk latency by keeping compressed data in RAM. zswap is a separate frontswap cache, not another name for zram. Combine them by purpose instead of applying one tuning value everywhere.

Australian estates are often hybrid: workloads sit in Sydney or Melbourne cloud regions, on-premises systems in Canberra handle residency-sensitive data, and remote Pilbara sites face constrained WAN links. Local operations teams often call a memory spike “a bit of a squeeze”, then trace it through capacity and workload data before changing a host.

Because RHEL support is commonly arranged through Red Hat subscriptions and Australian certified partners, memory tuning belongs in a documented change process. Record the baseline, stage the alteration, and retain a rollback path.

How zram fits with RHEL memory management

zram suits bursty, memory-intensive services because it can absorb temporary anonymous-memory growth without immediately filling a swap partition. It is less convincing for continuously cold workloads, where disk swap gives a clearer cost model and a larger safety margin.

RHEL 9 estates commonly use systemd-zram-generator, while RHEL 8 estates may use zram-tools. Check packages and kernel support before configuring either controller:

dnf list 'systemd-zram-generator*' 'zram-tools*'
modinfo zram

Keep the image on one controller; running both against zram0 can produce conflicting setup.

Enabling compressed swap safely

For a temporary test on a new device, load the module, choose an advertised algorithm, size it, initialise it, and activate it. Replace zstd if unsupported.

sudo modprobe zram
cat /sys/class/zram-control/zram0/comp_algorithm
echo zstd | sudo tee /sys/class/zram-control/zram0/comp_algorithm
echo 1G | sudo tee /sys/block/zram0/disksize
sudo mkswap /dev/zram0
sudo swapon --priority 100 /dev/zram0

For persistence, use the generator on RHEL 9 rather than adding commands to an init script. Install systemd-zram-generator, create /etc/systemd/zram-generator.conf, then reboot in a maintenance window so the generator can create the device.

[zram0]
zram-size = 8G
compression-algorithm = zstd

Verify swap activation with swapon --show rather than assuming the file alone worked. RHEL 8 installations using zram-tools should follow /etc/default/zram instead. Admin shortcuts such as bash aliases and functions can shorten repeated checks; keep them out of automated jobs, where explicit commands are easier to audit.

Sizing zram and disk swap

A conservative starting point for bursty services is 25–50% of physical RAM, then adjust from observed demand and compression. The configured size is logical swap capacity; physical RAM consumed varies with the workload and compression ratio.

Give zram a higher swap priority than disk swap so short-lived pages avoid storage latency. A vm.swappiness=100 value can suit a zram-first host, but it also encourages swapping and can reduce page-cache pressure; benchmark and persist the accepted value under /etc/sysctl.d.

Retain disk swap for cold data and as a fallback when zram fills. Prefer a dedicated partition or LVM logical volume to a swap file on XFS, where copy-on-write rules need extra care. On a Perth-hosted server with an intermittent WAN, local compression avoids sending reclaimable pages across the link; disk swap still needs measured I/O latency.

Monitoring pressure before users notice

Capture the live state with the commands below. For a wider index, the site's Linux commands reference covers common diagnostics without replacing workload-specific checks.

free -h
swapon --show
zramctl
vmstat 1 10
journalctl -k | grep -Ei 'out of memory|oom-killer'

In vmstat, sustained si and so show swap movement, while high wa indicates storage waits. Compare those fields with DATA and MEM from zramctl: frequent compressed swaps can be healthy if latency stays stable. Read /proc/pressure/memory where exposed and alert on kernel OOM messages.

Australian operations teams covering remote sites often rely on shared dashboards across FIFO handovers and intermittent links. Send zramctl, PSI, OOM, and latency metrics centrally instead of depending on live terminal inspection.

A production-ready memory profile

Treat this profile as a reviewable baseline rather than a universal recipe:

For rack audits, encode the host ID and zram profile in a QR asset label and verify it from Android. The barcode scanner app example shows how a simple scanning client can fit that workflow; runtime values should still come from zramctl, not the label.

Recovery, persistence, and the next deployment

Create disk swap with mkswap /dev/swap-device and swapon, then add its filesystem UUID to /etc/fstab as UUID=... none swap defaults 0 0. Obtain the identifier with blkid and verify the entry in a maintenance window so a malformed UUID cannot delay boot.

Use Kickstart, cloud-init, Image Builder, or Ansible to standardise RHEL versions, generator settings, and swap layouts across the estate. This is useful for Australian organisations moving between self-hosted Canberra infrastructure and Sydney or Melbourne cloud capacity, because one baseline can be reproduced without local improvisation.

Capture sudo swapon --show and sudo zramctl on one canary RHEL host before applying the profile.