docs: record user-1001.slice memory limit fix (MemoryHigh instead of MemoryMax, swap enabled)
Some checks failed
CI / test (18.x) (push) Has been cancelled
CI / test (20.x) (push) Has been cancelled
CI / test (22.x) (push) Has been cancelled

This commit is contained in:
jedarden 2026-05-30 10:01:51 -04:00
parent c3ff0d6564
commit 9e717bdb24

View file

@ -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