{"slug": "ai-agents-consume-all-your-memory-in-linux-by-default", "title": "AI agents consume all your memory in linux by default", "summary": "A developer traced repeated freezes on a 64 GB Linux workstation to roughly 22 GB of agent-created files accumulating in a tmpfs-backed /tmp, where contents live in RAM or swap and cannot be discarded like ordinary disk cache. The writeup recommends diagnosing the mount with findmnt, df and du, then either redirecting agents to a disk-backed directory via TMPDIR or masking systemd's tmp.mount so /tmp falls back to the root filesystem. The author notes the behavior is not unique to AI workloads, since compilers such as GCC also create temporary intermediate files, but parallel coding agents made the memory trade-off visible.", "body_md": "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.\n\nThen I found **22 GB of agent-created files in a tmpfs-backed `/tmp`**.\n\n`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>\n\nMemory-backed temporary storage can offer fast I/O, fewer storage writes, and cleanup on reboot. But swapping can undermine those benefits.<sup>2</sup>\n\nThe 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.\n\nRun these in a Linux terminal:\n\n```\n# Filesystem containing /tmp\nfindmnt -T /tmp -o TARGET,SOURCE,FSTYPE\n\n# Capacity and usage of that filesystem\ndf -hT /tmp\n\n# Directory sizes, largest last; stay on one filesystem\nsudo du -x -h --max-depth=1 /tmp | sort -h\n\n# RAM and swap usage\nfree -h\n```\n\nLook for `tmpfs` under `FSTYPE`. Keep `-T`: plain `findmnt /tmp` can return nothing when `/tmp` is not a separate mount.<sup>5</sup>\n\n`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.\n\nCreate a private directory and check its filesystem and free space:\n\n```\nmkdir -p \"$HOME/.local/tmp\"\nchmod 700 \"$HOME/.local/tmp\"\nfindmnt -T \"$HOME/.local/tmp\" -o TARGET,SOURCE,FSTYPE\ndf -hT \"$HOME/.local/tmp\"\n```\n\n`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.\n\n```\nexport TMPDIR=\"$HOME/.local/tmp\"\n```\n\n**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>\n\nVerify 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>\n\n`/tmp` disk-backed system-wide\nFor systemd-based distributions, inspect first:\n\n```\n# Mount unit and any overrides\nsystemctl cat tmp.mount --no-pager\n\n# Explicit /tmp configuration; no output means no matching entry\nfindmnt --fstab --mountpoint /tmp\n\n# Root filesystem, mount options, and free space\nfindmnt -T / -o TARGET,SOURCE,FSTYPE,OPTIONS\ndf -hT /\n```\n\n`tmp.mount` is one name, with a dot.<sup>11</sup>\n\nUse 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>\n\n```\nsudo systemctl mask tmp.mount\n```\n\nThis 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>\n\nAfter reboot, verify:\n\n```\nfindmnt -T /tmp -o TARGET,SOURCE,FSTYPE\n```\n\n`/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>\n\nThis 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>\n\nNative 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>\n\nThis is not a reason to disable tmpfs everywhere. It is a reason to put multi-gigabyte workspaces on storage chosen deliberately.\n\n**“Temporary” describes how long data is needed—not where it belongs.**\n\n[Linux kernel: Tmpfs](https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html). ↩\n\n[Ubuntu: Data Driven Analysis — /tmp on tmpfs](https://ubuntu.com/blog/data-driven-analysis-tmp-on-tmpfs). ↩\n\n[systemd: Using /tmp/ and /var/tmp/ Safely](https://systemd.io/TEMPORARY_DIRECTORIES/). ↩\n\n[GCC: Environment Variables](https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html). ↩\n\n[findmnt(8)](https://man7.org/linux/man-pages/man8/findmnt.8.html). ↩\n\n[df(1)](https://man7.org/linux/man-pages/man1/df.1.html). ↩\n\n[du(1)](https://man7.org/linux/man-pages/man1/du.1.html). ↩\n\n[free(1)](https://man7.org/linux/man-pages/man1/free.1.html). ↩\n\n[mkdir(1)](https://man7.org/linux/man-pages/man1/mkdir.1.html). ↩\n\n[chmod(1)](https://man7.org/linux/man-pages/man1/chmod.1.html). ↩\n\n[systemctl(1)](https://man7.org/linux/man-pages/man1/systemctl.1.html). ↩\n\n[systemd: upstream tmp.mount](https://raw.githubusercontent.com/systemd/systemd/main/units/tmp.mount). ↩\n\n[Apple: File System Basics](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html). ↩\n\n[Microsoft: GetTempPath2](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a). ↩\n\n[Microsoft: File Caching](https://learn.microsoft.com/en-us/windows/win32/fileio/file-caching). ↩", "url": "https://wpnews.pro/news/ai-agents-consume-all-your-memory-in-linux-by-default", "canonical_source": "https://dev.to/leanid_piliptsevich_7c592/ai-agents-consume-all-your-memory-in-linux-by-default-47ph", "published_at": "2026-09-19 00:10:27+00:00", "updated_at": "2026-09-19 00:25:33.974514+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools"], "entities": ["Linux", "systemd", "tmpfs", "GCC", "macOS", "Windows"], "alternates": {"html": "https://wpnews.pro/news/ai-agents-consume-all-your-memory-in-linux-by-default", "markdown": "https://wpnews.pro/news/ai-agents-consume-all-your-memory-in-linux-by-default.md", "text": "https://wpnews.pro/news/ai-agents-consume-all-your-memory-in-linux-by-default.txt", "jsonld": "https://wpnews.pro/news/ai-agents-consume-all-your-memory-in-linux-by-default.jsonld"}}