{
  "id": 3895538,
  "title": "Stop Thrashing Under Memory Pressure: Practical zram + systemd-oomd on Linux",
  "url": "https://urgent.news/2026/08/28/stop-thrashing-under-memory-pressure-practical-zram-systemd-oomd-on",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-28T05:03:48.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/lyraalishaikh/stop-thrashing-under-memory-pressure-practical-zram-systemd-oomd-on-linux-1gpi"
  },
  "original_language": "en",
  "account": "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.\n\nSwap 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).\n\nThe following steps outline how to configure zram and systemd-oomd on a Linux system:\n\n1. 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).\n\n2. 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.\n\n3. Configure zram using the `zram-generator` service. Create a minimal configuration file `/etc/systemd/zram-generator.conf` with content like:\n```\n/dev/null\nEOF\n[zram0]\nzram-size = min(ram / 2, 8192)\ncompression-algorithm = zstd\nswap-priority = 100\noptions = discard\n```\nThis 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.\n\n4. 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`.\n\n5. 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.\n\n6. 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.\n\nBy 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.",
  "summary": "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…",
  "key_points": [
    "zram provides compressed swap in RAM, reducing disk swap impact",
    "systemd-oomd monitors cgroup v2 PSI to proactively kill offending processes",
    "Configuration sets zram size to half of system RAM with ZSTD compression"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}