Recently, while using Codex to develop a multilingual Go project, I ran into a rather troublesome problem: an engineering task that had been running for several minutes and was still actively executing was suddenly force-killed by Ubuntu.
At the time, the Ubuntu desktop warned that the device’s memory was nearly exhausted, and Firefox became unresponsive. The terminal process hosting Codex was affected as well.
This experience made me realize that, for a machine that regularly runs long tasks with AI coding tools, memory management is actually a problem that is easy to overlook.
My machine isn’t particularly high-end — a ThinkPad T570 with 16 GB of physical memory — and I normally run Firefox, Codex CLI, and a Go development environment at the same time. For compile, test, and code analysis tasks that need to run for tens of minutes at a time, the memory pressure is genuinely non-trivial.
This article documents the entire troubleshooting process and the optimizations I ultimately adopted.
1. How the Problem Happened
My development environment:
- ThinkPad T570
- 16 GB physical memory
- Ubuntu 26.04
- Firefox
- Codex CLI
- Go 1.26.8
- 4 logical CPUs
On a day-to-day basis, I use Codex CLI to handle engineering tasks in a multilingual Go project, including code analysis, compilation, testing, and historical evidence verification.
These tasks sometimes need to run continuously for tens of minutes, during which they can generate large amounts of temporary files and consume a fair amount of memory.
On December 3, 2026, the Ubuntu desktop suddenly showed an out-of-memory notification, and Firefox reported that it was unresponsive at the same time.

Shortly after, the terminal process hosting Codex was also killed, which interrupted the engineering task that was in progress.

At first, I couldn’t tell whether the culprit was Firefox, the Go compilation, or Codex itself.
So instead of directly changing system parameters, I used Remote Desktop Commander (RDC) to read the local logs and the actual configuration.
2. Finding the Real Cause of the Kill: systemd-oomd
After investigation, I found that this incident was directly tied to Ubuntu’s systemd-oomd.
systemd-oomd is a userspace memory pressure management mechanism provided by systemd on Linux.
When the system is under sustained high memory pressure, it can pick a systemd control group to kill based on pressure metrics, thereby freeing memory.
Here’s a detail that’s easy to miss:
It doesn’t necessarily kill just a single memory-hungry process; it may kill an entire systemd scope outright.
My Codex CLI happened to be running inside a dynamic scope created by Ptyxis.
The systemd-oomd logs contained a record like this:
Killed /user.slice/user-1000.slice/user@1000.service/app.slice/ptyxis-spawn-....scope due to memory pressure for /user.slice/user-1000.slice/user@1000.service being 71.31% > 50.00% for > 20s with reclaim activityIn plain terms:
The memory pressure on the user-level service exceeded the configured 50% threshold and stayed there for more than 20 seconds. systemd-oomd ultimately chose to kill the Ptyxis scope inside it.
Further checks showed that at least two similar events occurred on December 3 alone:
- First event: memory pressure at 65.20%, above the 50% threshold.
- Second event: memory pressure at 71.31%, above the 50% threshold.
Both events satisfied the condition of exceeding the threshold for more than 20 seconds.
This also explains why Codex could be interrupted mid-run: what got killed was not just a single command, but the whole terminal process group containing Codex and its child processes.
3. Further Checks on Memory, Swap, and ZRAM
Next, I checked the system’s memory state at the time.
Ubuntu recognized about 14 GiB of total physical memory, with roughly 12 GiB in use and about 2.3 GiB available.
The swap situation was not great either:
| Item | Original configuration |
|---|---|
| Physical memory | ~14 GiB |
| ZRAM | 7.4 GiB |
| Disk swap | 4 GiB |
| Total swap capacity | ~11.4 GiB |
| Swap used | ~10.2 GiB |
ZRAM was fully used, and most of the original disk swap was in use as well.
On top of that, I found that Firefox was running multiple web content processes with fairly high memory usage.
There was another easily overlooked issue: at the time, the system’s /tmp used tmpfs, and about 4.4 GiB of temporary files had accumulated there.
tmpfs uses virtual memory as its file storage, and the associated pages can also be swapped out to swap under memory pressure.
This means the large volume of temporary files generated by engineering tasks may have added to the pressure on both system memory and swap space.
Of course, this doesn’t mean /tmp was the sole cause of this failure. The real problem was that multiple applications and engineering tasks together created substantial memory pressure.
4. Increasing Disk Swap Capacity
The first thing I addressed was the insufficient swap space.
My original disk swap was only 4 GiB, plus a 7.4 GiB ZRAM configuration.
I decided to keep the existing setup and add an extra 12 GiB disk swap file.
The commands I ran:
sudo fallocate -l 12G /swap-extra.img
sudo chmod 600 /swap-extra.img
sudo mkswap /swap-extra.img
sudo swapon -p 10 /swap-extra.imgThen I added the following entry to /etc/fstab:
/swap-extra.img none swap sw,pri=10 0 0With this in place, the newly added swap is also enabled automatically after an Ubuntu reboot.
The final configuration:
| Swap type | Capacity | Priority |
|---|---|---|
| ZRAM | 7.4 GiB | 100 |
Original /swap.img | 4 GiB | -1 |
New /swap-extra.img | 12 GiB | 10 |
| Total | 23.4 GiB | — |
After adding it, I ran swapon --show again and confirmed that all three swap areas were active.
The reported total swap capacity had grown from about 11.4 GiB to about 23.4 GiB.
One thing worth clarifying: adding swap is not the same as adding physical memory, and it doesn’t guarantee that OOM will never happen again. Disk swap is also noticeably slower to access than physical memory.
My main goal in expanding swap was to give the system a larger buffer.
5. Lowering the Priority of the Codex Terminal for systemd-oomd Kills
Beyond adding swap, I also wanted to protect Codex’s long-running engineering tasks as much as possible.
My investigation showed that systemd provides a property for setting kill preference:
ManagedOOMPreference=avoidWhat it does is make systemd-oomd try to avoid choosing control groups that have avoid set when it picks a kill target.
This is not an absolute exemption from being killed, but when other suitable candidates exist, it lowers the odds of an important engineering task being killed first.
I created a persistent configuration for the dynamic Ptyxis scopes:
File:
~/.config/systemd/user/ptyxis-spawn-.scope.d/90-oom-protection.confContents:
[Scope]
ManagedOOMPreference=avoidThen I reloaded the user-level systemd configuration and applied runtime protection to the Codex scope that was running at the time.
After that, I created a test scope and confirmed that newly created matching scopes also picked up the avoid setting.
Finally, I verified via RDC that the current Codex scope’s property was indeed:
ManagedOOMPreference=avoidOne caveat: this configuration applies to matching Ptyxis terminal scopes, not to Codex alone. It also cannot stop the Linux kernel’s own OOM Killer.
I chose not to disable systemd-oomd outright, because that could leave the system hanging for a long time when memory runs low, while also removing a layer of active memory pressure protection.
6. Adjusting the Engineering Temp Directory: Keeping /tmp, Moving to the SSD
This part is a detail I think is worth sharing from the whole optimization effort.
I like to use /tmp day to day, mainly because Ubuntu cleans out the temporary files there after a reboot.
For a machine that runs engineering tasks frequently, that’s genuinely convenient.
But now I had discovered that /tmp uses tmpfs, and Go projects generate large numbers of temporary repositories, ZIP files, test files, and diagnostic logs.
If the machine only reboots once a week, these files can keep piling up over the course of that week.
I didn’t want to lose the convenience of /tmp‘s automatic cleanup for the sake of memory optimization, so I didn’t directly modify the system’s /tmp.
My final decision:
- Keep the system-level
/tmpas is, still using tmpfs. - Move the multilingual Go project’s engineering temp files to the SSD.
- Clean up the engineering temp files manually on a regular schedule.
The new engineering temp directory:
$HOME/.cache/go-tour-i18n/tmp/Checking via RDC, this directory sits on:
/dev/sdb1
ext4That is my Home SSD partition, about 938 GiB in capacity, with roughly 693 GiB free at the time.
The command to create the directory:
mkdir -p -m 700 "$HOME/.cache/go-tour-i18n/tmp"From then on, new engineering tasks store their temporary repositories, ZIP files, test data, logs, and performance diagnostic files in this directory.
When a temporary environment variable needs to be set, you can use:
export TMPDIR="$HOME/.cache/go-tour-i18n/tmp"
export GOTMPDIR="$HOME/.cache/go-tour-i18n/tmp"To create a temporary working directory, use:
mktemp -d "$HOME/.cache/go-tour-i18n/tmp/task.XXXXXXXX"This preserves the isolation between temporary files and the official repositories, while also reducing the amount of engineering temp files occupying tmpfs.
The new SSD temp directory is not automatically emptied on reboot, so I clean it up manually on a regular basis rather than setting up an automatic deletion task.
7. Resolving Codex Sandbox Access to the New Temp Directory
After moving the engineering temp directory to the SSD, I ran into a new problem.
Codex runs in workspace-write sandbox mode. Even though the directory had been created successfully, that didn’t mean Codex automatically had write permission for it.
Initially, the only option was to temporarily add this to the Codex launch command:
--add-dir "$HOME/.cache/go-tour-i18n/tmp"That solved the problem, but having to add the parameter every time I started Codex wasn’t a good experience.
I had already granted Codex access to the Go build cache directory in its configuration file, so this time I decided to modify the global configuration directly.
Configuration file:
~/.codex/config.tomlOriginal configuration:
[sandbox_workspace_write]
writable_roots = ["/home/wangqiang/.cache/go-build"]Changed to:
[sandbox_workspace_write]
writable_roots = [
"/home/wangqiang/.cache/go-build",
"/home/wangqiang/.cache/go-tour-i18n/tmp"
]I kept the original Go build cache grant and only added the new engineering temp directory.
I did not turn off the Codex sandbox, nor did I grant Codex access to the entire Home directory.
After the change, I specifically started a new Codex session and asked it to run actual read/write tests in the project terminal:
set -eu
TEST_FILE="$HOME/.cache/go-tour-i18n/tmp/codex-sandbox-test.txt"
printf 'Codex sandbox test\n' > "$TEST_FILE"
cat "$TEST_FILE"
rm "$TEST_FILE"
echo "RESULT=PASS"The final results:
COMMAND_RC=0
WRITE_TEST=PASS
READ_TEST=PASS
DELETE_TEST=PASS
RESULT=PASS
This means that Codex sessions started from now on can use this engineering temp directory directly, without needing to grant access via --add-dir every time.
8. What I Left Unchanged for Now
This round of optimization wasn’t about tweaking every memory-related parameter available.
I decided to leave the following configurations as they were for now:
- ZRAM capacity and compression algorithm.
vm.swappiness.- systemd-oomd’s global pressure threshold and duration.
- Go’s
GOMEMLIMIT,GOGC, andGOMAXPROCS. - The global concurrency limit for Go tests.
- The Linux kernel OOM Killer.
- The tmpfs settings for Ubuntu’s system-level
/tmp.
The reason is simple: there isn’t enough evidence yet that these parameters need changing.
Blindly restricting Go compilation performance, disabling memory protection, or making sweeping changes to global thresholds just to avoid OOM could well introduce new problems.
I preferred to tackle the clearest current issues first — expanding swap, protecting the important engineering scopes, and relocating where temporary files are stored.
9. Current Results and Ongoing Observation
As of December 4, 2026, the completed work includes:
- Disk swap increased from 4 GiB to 16 GiB.
- Kept the original 7.4 GiB ZRAM.
- The
ManagedOOMPreference=avoidsetting is now in effect for the Ptyxis scope currently hosting Codex. - Configured persistent OOM protection for matching Ptyxis scopes going forward.
- Created the SSD engineering temp directory.
- Updated Codex’s global
writable_rootsconfiguration. - Ran write, read, and delete tests on the temp directory in a new Codex session.
All of these configurations and functional tests have passed so far.
However, I haven’t yet observed a full week of real engineering workload, and I don’t have enough evidence to say process kills will never happen again.
Next, I’ll keep using my original multilingual Go development workflow and watch memory usage during long compilations, tests, and Codex engineering tasks.
If memory pressure problems occur again, I’ll decide whether further adjustments are needed based on the actual logs.
Final Thoughts
This incident made me realize that using AI coding tools isn’t just about model capability and code quality — the local runtime environment matters too.
On a development machine with only 16 GB of memory, running Firefox, Codex, Go compilation, and large volumes of temporary files simultaneously can genuinely create noticeable memory pressure.
I don’t intend to buy Codex more runtime by switching off system protections; instead, I want to minimize the odds of long-running engineering tasks being unexpectedly interrupted while keeping the system’s safety mechanisms intact.
Whether this setup is stable enough will only be confirmed by real-world use going forward.

