最新资讯
dev.to 精简 MCP server 工具数量:更少工具、更小影响面,双重收益 dev.to 为什么 git checkout 无法撤销 AI 编码 agent 的改动? wechat AI短剧门槛降降降!实测即梦短剧工作室:剧本分镜预演一条龙,伙伴计划长期护航 dev.to 让模型改写文档前,先量化事实保真度 dev.to 回放 153 个 Claude Code 与 Codex 会话,审计 Agent 的生产影响范围 dev.to 银行 77 意图分类最便宜 LLM:GPT-6.1 Terra 每次成功任务 $0.000727 theinformation.com Chesky的副业:Airbnb向CEO新设AI实验室出售IP theverge.com OpenAI 宣布数据中心项目不再与公职人员签署保密协议 dev.to NVIDIA 发布四个开放 Cosmos 3 仿真模型 dev.to 真实 MCP 客户端击穿我们服务器的五种方式 theverge.com Airbnb 正在开发 AI 旅行 agent,计划 2027 年上半年推出 wechat 这可能是美国AI最魔幻的一天。
多元动态
登录 注册
智能体 dev.to · @Leanid Piliptsevich

Linux 上 AI Agent 默认会吃光你的内存

原文 我的收藏

作者描述其 64GB Linux 工作站在编码 Agent 处理多个项目时反复卡死:4GB swap 被占满、应用被杀死,而近半内存看起来像缓存。最终发现 tmpfs 支撑的 /tmp 中有 22GB 由 Agent 创建的文件。文章指出 tmpfs 将文件内容存放在 RAM 或 swap 中,与磁盘支撑的干净缓存不同,这些内容不能简单丢弃;部分内存监控工具把 tmpfs 计入缓存类统计,容易误判内存压力。作者强调这并非 AI 独有问题(GCC 也会生成临时中间文件),只是并行 Agent 工作让该权衡更明显,并给出在 Linux 终端检查 /tmp 所在文件系统等排查命令。

AI推荐理由 开发者第一手排查经验:64GB Linux 工作站因编码 Agent 在 tmpfs 支撑的 /tmp 中生成 22GB 文件而内存耗尽,指出 tmpfs 内容不可简单丢弃、内存监控易误读,并给出排查命令,对运行本地 Agent 的开发者有实用价值。

62

正文

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. Not all cache is disposable 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.1 Memory-backed temporary storage can offer fast I/O, fewer storage writes, and cleanup on reboot. But swapping can undermine those benefits.2 The distinction is workload size. Systemd recommends /tmp for small, bounded files and /var/tmp for larger data.3 This is not uniquely an AI problem: GCC also creates temporary intermediate files.4 Parallel agent work simply made the trade-off visible on my machine. Check your 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 Enter fullscreen mode Exit fullscreen mode Look for tmpfs under FSTYPE. Keep -T: plain findmnt /tmp can return nothing when /tmp is not a separate mount.5 df measures the containing filesystem; du measures the directory tree.67 In free, focus on available.8 Large tmpfs usage alongside low available memory deserves investigation—not automatic blame for every crash. Option 1: redirect heavy workloads 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" Enter fullscreen mode Exit fullscreen mode mkdir -p creates missing directories; chmod 700 restricts ordinary access to the owner.910 Confirm the directory is disk-backed before proceeding. export TMPDIR="$HOME/.local/tmp" Enter fullscreen mode Exit fullscreen mode 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.3 Verify the path and filesystem inside the agent’s actual execution environment, especially with containers or sandboxes.5 Clean up completed scratch data yourself; this directory does not inherit /tmp’s cleanup policy.3 Option 2: make /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 / Enter fullscreen mode Exit fullscreen mode tmp.mount is one name, with a dot.11 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.511 sudo systemctl mask tmp.mount Enter fullscreen mode Exit fullscreen mode This prevents future activation without unmounting the current /tmp.11 Save your work, copy anything needed out of /tmp, then reboot when ready. Existing tmpfs files disappear; they do not migrate to disk.1 After reboot, verify: findmnt -T /tmp -o TARGET,SOURCE,FSTYPE Enter fullscreen mode Exit fullscreen mode /tmp should now belong to the disk-backed root filesystem. To reverse the mask, run sudo systemctl unmask tmp.mount, then reboot.11 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.123 Why macOS and Windows usually avoid this trap Native macOS and Windows normally use disk-backed temporary directories, so large temporary trees primarily consume disk space.1314 They can still exhaust memory; disk-backed does not mean cache-free.15 For Linux containers or virtual machines, check inside that environment.5 The takeaway 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. ↩ Ubuntu: Data Driven Analysis — /tmp on tmpfs. ↩ systemd: Using /tmp/ and /var/tmp/ Safely. ↩ GCC: Environment Variables. ↩ findmnt(8). ↩ df(1). ↩ du(1). ↩ free(1). ↩ mkdir(1). ↩ chmod(1). ↩ systemctl(1). ↩ systemd: upstream tmp.mount. ↩ Apple: File System Basics. ↩ Microsoft: GetTempPath2. ↩ Microsoft: File Caching. ↩

来源报道 · 1 篇 · 以下链接均前往原始媒体

Leanid Piliptsevich Linux 上 AI Agent 默认会吃光你的内存 09-19 · 原文发布
← 返回精选动态 原文

更多内容