# AI agents consume all your memory in linux by default

> Source: <https://dev.to/leanid_piliptsevich_7c592/ai-agents-consume-all-your-memory-in-linux-by-default-47ph>
> Published: 2026-09-19 00:10:27+00:00

My **64 GB Linux workstation** kept freezing while coding agents worked on a couple of projects. All 4 GB of swap filled up. Applications were killed. Half the memory looked like cache.

Then I found **22 GB of agent-created files in a tmpfs-backed `/tmp`**.

`tmpfs` stores file contents in **RAM or swap**. Unlike clean disk-backed cache, those contents cannot simply be discarded. Some memory monitors include tmpfs in cache-related accounting, making the memory pressure easy to misread.<sup>1</sup>

Memory-backed temporary storage can offer fast I/O, fewer storage writes, and cleanup on reboot. But swapping can undermine those benefits.<sup>2</sup>

The distinction is workload size. Systemd recommends `/tmp` for **small, bounded files** and `/var/tmp` for larger data.<sup>3</sup> This is not uniquely an AI problem: GCC also creates temporary intermediate files.<sup>4</sup> Parallel agent work simply made the trade-off visible on my machine.

Run these in a Linux terminal:

```
# Filesystem containing /tmp
findmnt -T /tmp -o TARGET,SOURCE,FSTYPE

# Capacity and usage of that filesystem
df -hT /tmp

# Directory sizes, largest last; stay on one filesystem
sudo du -x -h --max-depth=1 /tmp | sort -h

# RAM and swap usage
free -h
```

Look for `tmpfs` under `FSTYPE`. Keep `-T`: plain `findmnt /tmp` can return nothing when `/tmp` is not a separate mount.<sup>5</sup>

`df` measures the containing filesystem; `du` measures the directory tree.<sup>6</sup><sup>7</sup> In `free`, focus on **` available`**.<sup>8</sup> Large tmpfs usage alongside low available memory deserves investigation—not automatic blame for every crash.

Create a private directory and check its filesystem and free space:

```
mkdir -p "$HOME/.local/tmp"
chmod 700 "$HOME/.local/tmp"
findmnt -T "$HOME/.local/tmp" -o TARGET,SOURCE,FSTYPE
df -hT "$HOME/.local/tmp"
```

`mkdir -p` creates missing directories; `chmod 700` restricts ordinary access to the owner.<sup>9</sup><sup>10</sup> Confirm the directory is disk-backed before proceeding.

```
export TMPDIR="$HOME/.local/tmp"
```

**Launch your agent from that same terminal.** Programs honoring `TMPDIR` can use the new location. Hard-coded `/tmp` paths and existing workspaces need separate changes.<sup>3</sup>

Verify the path and filesystem **inside the agent’s actual execution environment**, especially with containers or sandboxes.<sup>5</sup> Clean up completed scratch data yourself; this directory does not inherit `/tmp`’s cleanup policy.<sup>3</sup>

`/tmp` disk-backed system-wide
For systemd-based distributions, inspect first:

```
# Mount unit and any overrides
systemctl cat tmp.mount --no-pager

# Explicit /tmp configuration; no output means no matching entry
findmnt --fstab --mountpoint /tmp

# Root filesystem, mount options, and free space
findmnt -T / -o TARGET,SOURCE,FSTYPE,OPTIONS
df -hT /
```

`tmp.mount` is one name, with a dot.<sup>11</sup>

Use the following only when `/tmp` is tmpfs, its unit is distribution-provided with no local customizations, `/etc/fstab` has no `/tmp` entry, and `/` is writable, disk-backed, and has adequate space. Otherwise, use Option 1 rather than forcing this shortcut.<sup>5</sup><sup>11</sup>

```
sudo systemctl mask tmp.mount
```

This prevents future activation without unmounting the current `/tmp`.<sup>11</sup> **Save your work, copy anything needed out of `/tmp`, then reboot when ready. Existing tmpfs files disappear; they do not migrate to disk.**<sup>1</sup>

After reboot, verify:

```
findmnt -T /tmp -o TARGET,SOURCE,FSTYPE
```

`/tmp` should now belong to the disk-backed root filesystem. To reverse the mask, run `sudo systemctl unmask tmp.mount`, then reboot.<sup>11</sup>

This trades memory-backed storage for root-disk usage and can remove mount-specific restrictions such as `nosuid,nodev`. Disk space, cleanup, and security policy still matter.<sup>12</sup><sup>3</sup>

Native macOS and Windows normally use **disk-backed temporary directories**, so large temporary trees primarily consume disk space.<sup>13</sup><sup>14</sup> They can still exhaust memory; disk-backed does not mean cache-free.<sup>15</sup> For Linux containers or virtual machines, check inside that environment.<sup>5</sup>

This is not a reason to disable tmpfs everywhere. It is a reason to put multi-gigabyte workspaces on storage chosen deliberately.

**“Temporary” describes how long data is needed—not where it belongs.**

[Linux kernel: Tmpfs](https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html). ↩

[Ubuntu: Data Driven Analysis — /tmp on tmpfs](https://ubuntu.com/blog/data-driven-analysis-tmp-on-tmpfs). ↩

[systemd: Using /tmp/ and /var/tmp/ Safely](https://systemd.io/TEMPORARY_DIRECTORIES/). ↩

[GCC: Environment Variables](https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html). ↩

[findmnt(8)](https://man7.org/linux/man-pages/man8/findmnt.8.html). ↩

[df(1)](https://man7.org/linux/man-pages/man1/df.1.html). ↩

[du(1)](https://man7.org/linux/man-pages/man1/du.1.html). ↩

[free(1)](https://man7.org/linux/man-pages/man1/free.1.html). ↩

[mkdir(1)](https://man7.org/linux/man-pages/man1/mkdir.1.html). ↩

[chmod(1)](https://man7.org/linux/man-pages/man1/chmod.1.html). ↩

[systemctl(1)](https://man7.org/linux/man-pages/man1/systemctl.1.html). ↩

[systemd: upstream tmp.mount](https://raw.githubusercontent.com/systemd/systemd/main/units/tmp.mount). ↩

[Apple: File System Basics](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html). ↩

[Microsoft: GetTempPath2](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a). ↩

[Microsoft: File Caching](https://learn.microsoft.com/en-us/windows/win32/fileio/file-caching). ↩
