From 9e717bdb2424b296854bf7db39c71ef03036a1bf Mon Sep 17 00:00:00 2001 From: jedarden Date: Sat, 30 May 2026 10:01:51 -0400 Subject: [PATCH] docs: record user-1001.slice memory limit fix (MemoryHigh instead of MemoryMax, swap enabled) --- notes/bf-41xv.md | 52 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/notes/bf-41xv.md b/notes/bf-41xv.md index 32e808c..0728640 100644 --- a/notes/bf-41xv.md +++ b/notes/bf-41xv.md @@ -1,4 +1,7 @@ -# Fix for user-1001.slice Memory Limits +# user-1001.slice Memory Fix (Bead bf-41xv) + +## Summary +Replaced MemoryMax hard cap with MemoryHigh soft cap and enabled cgroup swap for user-1001.slice on NixOS. ## Problem The user-1001.slice had: @@ -13,26 +16,41 @@ Changed to: - `MemoryMax=infinity` (no hard kill) - `MemorySwapMax=infinity` (can use system swap) -## Configuration Files -Persistent configs in `/etc/systemd/system.control/user-1001.slice.d/`: -- `50-MemoryHigh.conf`: `MemoryHigh=34359738368` (32G) -- `50-MemoryMax.conf`: `MemoryMax=infinity` -- `50-MemorySwapMax.conf`: `MemorySwapMax=infinity` +## Changes Made -## Verification +### NixOS Configuration (`/etc/nixos/configuration.nix`) +Fixed syntax error with `writeTextDir` (needed parentheses around the call) and configured: + +```nix +systemd.tmpfiles.rules = [ + "L+ /etc/systemd/system/user-1001.slice.d/50-memory.conf - - - - /etc/systemd/system-user-slices/user-1001.slice.d/50-memory.conf" +]; + +systemd.packages = [ + (pkgs.writeTextDir "etc/systemd/system-user-slices/user-1001.slice.d/50-memory.conf" '' + [Slice] + # MemoryHigh applies soft memory pressure (reclaim) instead of hard OOM kill + MemoryHigh=32G + # Do not set MemoryMax - allow emergency usage if needed + # Do not set MemorySwapMax - allow cgroup to use system swap + '') +]; +``` + +### Verification +After `nixos-rebuild switch`: ```bash -# Current cgroup values -cat /sys/fs/cgroup/user.slice/user-1001.slice/memory.high # 34359738368 (32G) cat /sys/fs/cgroup/user.slice/user-1001.slice/memory.max # max (unlimited) +cat /sys/fs/cgroup/user.slice/user-1001.slice/memory.high # 34359738368 (32G) cat /sys/fs/cgroup/user.slice/user-1001.slice/memory.swap.max # max (unlimited) - -# systemd properties -systemctl show user-1001.slice | grep -E "MemoryMax|MemoryHigh|MemorySwapMax" ``` -## How It Was Done -```bash -sudo systemctl set-property -- user-1001.slice MemoryMax=infinity MemorySwapMax=infinity MemoryHigh=32G -``` +The NixOS-generated config in `/nix/store/.../user-1001.slice.d/50-memory.conf` contains the correct settings. -The `systemctl set-property` command without `--runtime` makes the changes persistent across reboots by creating drop-in files in `/etc/systemd/system.control/`. +## Why This Matters +- **Before**: MemoryMax=32G meant hard OOM kill at the limit +- **After**: MemoryHigh=32G allows the kernel to apply gradual memory pressure and reclaim pages, giving processes time to respond before OOM +- Swap overflow provides an additional 24GB buffer for memory spikes + +## Date +2026-05-30