Preventing System Freezes on Ubuntu 24.04 (Cursor & Memory Exhaustion)

When using AI-heavy editors like Cursor, the system can occasionally freeze or become unresponsive as the app consumes RAM to store agent chats and index files. This guide explains how to configure Ubuntu's built-in systemd-oomd and optimize swappiness to kill the process before the system locks up.

  1. Optimize Swappiness for 32GB+ RAM By default, Ubuntu is aggressive about using the swap file (on the slow disk). On machines with high RAM, this causes "stuttering." We want the system to prioritize your fast RAM.

Check current value:

bash
cat /proc/sys/vm/swappiness

Change it to 10 (Permanent): Open the configuration file:

bash
sudo nano /etc/sysctl.conf

Add this line to the bottom:

vm.swappiness=10

Apply without rebooting:

bash
sudo sysctl -p
  1. Configure the OOM Killer (systemd-oomd)

Ubuntu 24.04 includes systemd-oomd, which monitors "Memory Pressure." If Cursor starts eating RAM too fast, this tool will kill it to save the OS.

Edit the OOM configuration:

bash
sudo nano /etc/systemd/oomd.conf

Set the Kill Thresholds:

Use these settings to trigger a kill when your Swap is 85% full (preventing a total freeze): ini [OOM]

SwapUsedLimit=85%
DefaultMemoryPressureLimit=60%
DefaultMemoryPressureDurationSec=20s

Restart the service:

bash
sudo systemctl restart systemd-oomd
  1. How to Monitor Cursor's Memory Use To see if Cursor is the culprit in real-time, use oomctl. This tool shows you exactly which "slice" of your system is under pressure.
bash
oomctl

If Cursor is killed, you can verify it in the logs:

bash
journalctl -u systemd-oomd --since="10 minutes ago"
  1. Emergency Recovery (The "Magic" Keys) If your system does freeze before the killer acts, do not pull the power plug. Use the Magic SysRq keys to trigger a manual kill: Hold Alt + SysRq (Print Screen). While holding them, tap f. This forces the kernel to immediately kill the most memory-expensive process (usually Cursor/Chrome).