Urgent.News

What's breaking now, across thousands of outlets.

Tech

Stop Thrashing Under Memory Pressure: Practical zram + systemd-oomd on Linux

Stop Thrashing Under Memory Pressure: Practical zram + systemd-oomd on Linux When a homelab box or small VPS runs out of free RAM, the failure mode is rarely a clean kill. More often the machine spends minutes thrashing: anonymous pages bounce to a slow disk swap, the page cache collapses, SSH becomes sticky, and then the kernel OOM killer finally fires. Two complementary tools fix different…

When a home lab or small virtual private server runs out of free RAM, the failure mode is rarely a clean kill. Instead, the machine spends minutes thrashing as pages bounce to slow disk swap, the page cache collapses, SSH becomes unresponsive, and the kernel OOM killer eventually fires. Two complementary tools address different aspects of this issue: zram, which provides compressed swap in RAM, and systemd-oomd, a userspace OOM daemon that monitors cgroup v2 pressure stall information (PSI) to kill offending processes before the entire system stalls.

This article walks through a practical setup for both zram and systemd-oomd, with verification steps and a safe rollback method. It does not cover hibernation solutions, in-depth zswap details, or memory capping recipes.

Swap is not an "emergency RAM" solution. Swap exists to allow rarely used anonymous pages to be reclaimed like clean file pages. Without any swap, those anonymous pages remain pinned, leading to more aggressive reclaiming and potential thrashing under memory pressure. While swap on a disk-backed device still works, it can significantly slow down pressure scenarios on a busy SSD or a slow VPS volume, turning moderate pressure into multi-second stalls. zram, however, keeps the swap path in RAM using compression (kernel documentation suggests a rough 2:1 compression ratio, though actual ratios vary by workload).

The following steps outline how to configure zram and systemd-oomd on a Linux system:

1. Ensure your Linux kernel supports zram and cgroup v2. Verify these by checking the output of `mount | grep -E cgroup2` and `cat /proc/pressure/memory`. Your distribution should already have the necessary packages installed (e.g., `zram-generator` for Fedora, Arch, or Debian/Ubuntu).

2. Install the required packages. On Fedora, `zram-generator` is typically pre-installed. For Arch Linux, install the `zram-generator` package, and for Debian/Ubuntu, install `zram-tools` or the appropriate systemd-zram-generator package from your package manager.

3. Configure zram using the `zram-generator` service. Create a minimal configuration file `/etc/systemd/zram-generator.conf` with content like:

```

/dev/null

EOF

[zram0]

zram-size = min(ram / 2, 8192)

compression-algorithm = zstd

swap-priority = 100

options = discard

```

This configuration sets the zram device size to half of the system's RAM (up to a maximum of 8192 MiB), uses the ZSTD compression algorithm, and prioritizes the swap path over disk swap.

4. Reload systemd and start the `systemd-zram-setup@zram0.service` unit to activate the zram device. Verify the zram swap using `zramctl`, `swapon --show`, and `/proc/swaps`. Check live compression statistics with `/sys/block/zram0/mm_stat` and `/sys/block/zram0/comp_algorithm`.

5. Test the setup by intentionally triggering memory pressure, such as running memory-intensive applications. Monitor the system's behavior to ensure that zram swap is being used effectively and that the system does not enter a thrashing state.

6. Disable zswap if zram is used as the primary swap mechanism. Use `sysctl` commands to check if zswap is enabled and disable it if necessary. Persist the change by adding the appropriate kernel parameter to the bootloader configuration.

By following these steps, you can achieve a balanced system that utilizes compressed swap in RAM with zram and proactively manages OOM conditions with systemd-oomd, minimizing system instability under memory pressure.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

636 Bytes: What Happens When You Stop Teaching RPA the Path

I sat in a room with a very large automation system and a very familiar problem: it had become fragile. The language came quickly. DOM. Timestamps. Timing windows. Selectors. Retries. Circle back.

  • Traditional RPA relies on brittle selectors and timing windows
  • New architecture uses intent-driven automation with 636-byte WebAssembly module
  • Cost reduction of 82.1% achieved with intent architecture

An 18-hour half-life for mixed launch feeds

Product Hunt, Hacker News, and GitHub do not speak the same language. One is votes in a 24-hour window, one is comments on a Show HN, one is stars on a repo that may have been created last month.

  • 18-hour half-life chosen for LaunchSignal ranking system
  • GitHub stars weighted heavily at 2 × stars + forks
  • 18-hour half-life balances recent activity and fair representation

More from Friday 28 August →