跳到主要內容

為什麼 free 很小,Linux 卻還能開程式?看懂 MemFree 與 MemAvailable / Why a Tiny free Column Does Not Mean Linux Cannot Start Programs

現象:free 很小,不代表開不了程式 / A tiny free column is not “cannot start”

假設你在 Linux 終端機打出 free,free 欄只剩幾十 MB,used 卻佔了一大半。很容易先想到「記憶體爆了,得重開或加 RAM」。先停一下:這個畫面常常不是實體記憶體已經沒了,而是把「完全沒被用到的頁」,當成「還能開新程式的空間」。

Suppose you run free in a Linux terminal and the free column is down to a few dozen megabytes, while used takes most of the row. It is easy to jump to “memory is exhausted; reboot or add RAM.” Pause first: that picture often does not mean physical memory is gone. It means idle pages have been mistaken for the space still available to start a new program.

/proc/meminfo 的 MemFree,依 Linux 7.4-rc1 的 proc 文件,是目前的 free RAM;在 highmem 系統上,它是 LowFree 與 HighFree 的和。它變小,只表示幾乎沒有完全閒置的頁。核心會把讀過的檔案留在記憶體裡,這份快取叫 page cache,也就是頁快取。那些頁還佔著 RAM,所以 MemFree 下降,但它們不是某個程式私有、放不掉的佔用。[1]

In Linux 7.4-rc1’s proc documentation, MemFree in /proc/meminfo is the current free RAM; on highmem systems it is the sum of LowFree and HighFree. A small value only means there are almost no completely idle pages. The kernel keeps files it has read in memory; that cache is the page cache. Those pages still occupy RAM, so MemFree falls, but they are not private, unreleasable use by a particular program. [1]

MemAvailable 是估計,不是空白 / MemAvailable is an estimate, not empty space

要看「還能不能開新程式」,文件給的欄位是 MemAvailable。man-pages 6.19 註明它自 Linux 3.14 起出現,定義是:在不換頁的前提下,估計還能用來啟動新應用程式的記憶體。換頁(swapping)是把記憶體頁暫存到交換空間。這份估計由 MemFree、SReclaimable、file LRU 清單的大小,以及各 zone 的 low watermark 算出,並承認系統仍需留一些 page cache 才能好好運作,也不是所有可回收的 slab 都真的收得回來。所以它是估計,不是量到的空白,機器之間的差距也會不一樣。[1][2]

The field for “can a new program still start” is MemAvailable. man-pages 6.19 notes that it has existed since Linux 3.14, and defines it as an estimate of memory available for starting new applications without swapping. Swapping means parking memory pages in swap space. The estimate is calculated from MemFree, SReclaimable, the size of the file LRU lists, and the low watermarks in each zone. It allows that the system still needs some page cache to function well, and that not all reclaimable slab can actually be reclaimed because items are in use. It is an estimate, not measured empty space, and the gap varies from machine to machine. [1][2]

MemFree 只是閒置頁;MemAvailable 是不換頁就能開新程式的估計,不會把全部快取都算進去 / MemFree is only idle pages; MemAvailable estimates memory for new programs without swapping, and does not count all cache
圖一|三層不要加成一個數字:閒置頁、只能讓出一部分的快取、以及 MemAvailable 這個估計。原創示意圖,非產品或實測截圖。 / Figure 1 | Do not add the three layers into one number: idle pages, cache that can only partly be returned, and the MemAvailable estimate. Original diagram, not a product or test screenshot.

還有一個容易加錯的欄位。同一份核心文件寫,Cached 是從磁碟讀入的 page cache,也包含 tmpfs 與 shmem,但不含 SwapCached。man7 的 proc_meminfo 頁只寫 page cache、不含 SwapCached,沒有寫出 tmpfs 與 shmem。兩邊都排除 SwapCached;是否包含 tmpfs,以核心文件為準。把 MemFree 直接加上整個 Cached,會把不一定能立刻讓出來的共用記憶體也算進去。[1][2]

Another field is easy to add in the wrong way. The same kernel document says Cached is the in-memory cache for files read from disk, the page cache, and also includes tmpfs and shmem, but not SwapCached. The man7 proc_meminfo page says page cache and excludes SwapCached, without mentioning tmpfs or shmem. Both exclude SwapCached; for whether tmpfs is included, the kernel document is the one to follow. Adding all of Cached to MemFree counts shared memory that cannot necessarily be given back at once. [1][2]

used 欄要對版本 / The used column depends on the version

free 這個指令是在整理 /proc/meminfo,不是另一套記憶體帳。兩邊手冊都寫:available 對應 MemAvailable,會把 page cache 算進去,也承認並非所有可回收 slab 都會被收回。used 的算法卻要看版本。Debian bookworm 的 procps 2:4.0.2-3 寫成 total 減 available;這台 WSL2 的 procps-ng 3.3.17 手冊則寫成 total 減 free 減 buffers 減 cache。同一欄名字,兩套說明不是同一個數。看「還能不能開程式」,對的是 available,不是把 used 當成唯一答案。[3][4]

The free command formats /proc/meminfo; it is not a second set of memory accounts. Both manuals say available corresponds to MemAvailable, takes page cache into account, and accepts that not every reclaimable slab will be reclaimed. The formula for used depends on the version. Debian bookworm’s procps 2:4.0.2-3 describes it as total minus available. The procps-ng 3.3.17 manual on this WSL2 describes it as total minus free minus buffers minus cache. The same column name is not the same number in the two manuals. For “can a new program start,” read available, not used as the only answer. [3][4]

唯讀對一下 / A read-only check

在 Linux 上,唯讀對一下就夠:用 grep 讀 /proc/meminfo 的 MemFree、MemAvailable 與 Cached,再跑 free -k,最後用 man free 看這台機器的 used 是哪一種算法。這些指令不改系統。本文的數字只來自 2026-11-03 在這台 Windows 的 WSL2(Linux 6.6.87.2-microsoft-standard-WSL2)做的一次觀察,不是壓力測試,也不代表別台機器。當時 free -k 的 Mem 列是 total 16253080、used 1131716、free 11766204、buff/cache 3355160、available 14804828,單位 KiB;同一串指令稍後讀到 MemFree 11765956 kB、MemAvailable 14804588 kB。兩次讀取隔了幾秒,所以不會完全相同。這組快照的 free 本來就不低,沒有示範「free 快見底」,只核對 3.3.17 的算法:used、free、buff/cache 三者相加等於 total。

On Linux, a read-only check is enough: grep MemFree, MemAvailable, and Cached from /proc/meminfo, run free -k, then read man free to see which used formula that machine documents. These commands do not change the system. The numbers here come from one observation on 2026-11-03 in WSL2 on this Windows machine (Linux 6.6.87.2-microsoft-standard-WSL2). It was not a stress test, and it does not describe other machines. At that moment the Mem row of free -k was total 16253080, used 1131716, free 11766204, buff/cache 3355160, available 14804828, all in KiB. A moment later in the same command, MemFree was 11765956 kB and MemAvailable was 14804588 kB. The two reads were seconds apart, so they do not match exactly. Free was not low in this snapshot, so it does not demonstrate “free is nearly gone.” It only checks the 3.3.17 formula: used, free, and buff/cache add up to total.

# Linux;只讀,不寫入 / read-only, no writes
grep -E '^(MemTotal|MemFree|MemAvailable|Cached|SReclaimable):' /proc/meminfo
free -k
man free    # 先看這台機器的 used 算法 / read this machine's used formula

回到那個「記憶體快用完」的畫面,可以分開三件事。MemFree 低,表示閒置頁少;MemAvailable 仍夠,表示估計還能在不換頁的情況下開新程式;若 available 也一起掉,而且系統開始大量換頁,那是另一個問題,本文不把它說成同一個原因。下次看到 free 很小,先讀 MemAvailable,再決定要不要處理。

Back to the “memory is almost gone” screen, three things can be kept apart. Low MemFree means few idle pages. MemAvailable still being large means the estimate says a new program can start without swapping. If available falls too, and the system starts swapping heavily, that is a different problem; this article does not treat it as the same cause. Next time free looks tiny, read MemAvailable before deciding whether anything needs to be done.

來源與查核 / Sources and verification

查核日期 / Checked: 2026-11-03。核心文件取 Linux 7.4-rc1 的 proc.rst;man-pages 6.19 與 Debian bookworm procps 2:4.0.2-3 為公開手冊。WSL2 數字是這台機器一次唯讀快照,不是每台機器的常態,也沒有示範 free 快見底。 / Kernel text is proc.rst from Linux 7.4-rc1; man-pages 6.19 and Debian bookworm procps 2:4.0.2-3 are public manuals. The WSL2 numbers are one read-only snapshot on this machine, not a norm for every machine, and they do not demonstrate a nearly empty free column.
  1. Linux 7.4-rc1 Documentation/filesystems/proc.rst(MemFree、MemAvailable、Cached)
  2. proc_meminfo(5),Linux man-pages 6.19(MemAvailable 自 3.14)
  3. free(1),Debian bookworm procps 2:4.0.2-3(used = total − available)
  4. 本機 WSL2 的 free(1) 手冊,procps-ng 3.3.17(used = total − free − buffers − cache)

留言

這個網誌中的熱門文章

text-to-cad: 讓 AI 驅動的參數化 CAD 建模成為現實 / text-to-cad: Bringing AI-Driven Parametric CAD Modeling to Reality

一個讓 AI 代理能生成、預覽並迭代 3D CAD 模型的開源框架 / An open-source harness for AI agents to generate, preview, and iterate 3D CAD models. 🔎 工具速覽 / AT A GLANCE Category AI-Powered CAD Tooling / AI 驅動 CAD 工具 Pricing Free (Open Source) / 免費(開源) BestFor Robotics engineers and product designers using AI coding agents / 使用 AI 程式碼代理的機器人工程師與產品設計師 GitHub Stars ⭐ 93 🚀 引言 / Introduction text-to-cad 是一個強大的開源框架,旨在填補大型語言模型(LLM)與專業 3D 建模之間的鴻溝。它允許開發者利用 Claude Code 或 Codex 等 AI 代理,透過程式碼生成精確的參數化幾何模型,並提供即時預覽與迭代能力。 text-to-cad is a powerful open-source harness designed to bridge the gap between Large Language Models (LLMs) and professional 3D modeling. It enables developers to leverage AI agents like Claude Code or Codex to generate precise parametric geometry via code, providing real-time preview and iteration capabilities. 🛠️ 核心功能 / Key Features 與 Codex 或 Claude Code 等代理...

kimiflare:將 Moonshot Kimi-K2.6 直接部署於 Cloudflare 的終端 AI 編碼助手 | kimiflare: A Terminal Coding Agent Powered by Moonshot Kimi-K2.6 on Cloudflare

無需中繼,在你的 Cloudflare 帳戶中直接運行強大的 Kimi 終端編碼智能體。 | No middleman, run the powerful Kimi terminal coding agent directly on your own Cloudflare account. 🔎 工具速覽 / AT A GLANCE Category AI Coding Agent / Developer Tool Pricing Free (Open-weight model / Cloudflare Workers AI pricing) BestFor Developers seeking a private, high-context terminal AI assistant with direct infrastructure control. GitHub Stars ⭐ 36 🚀 引言 / Introduction kimiflare 是一款為開發者量身打造的終端編碼智能體,它將 Moonshot 的 1 兆參數開源模型 Kimi-K2.6 與 Cloudflare Workers AI 完美結合。不同於傳統 AI 工具,kimiflare 讓流量直接在你的 Cloudflare 帳戶中流動,徹底擺脫第三方代理或 AI 閘道的束縛,實現最高等級的控制力與隱私。 | kimiflare is a terminal coding agent tailored for developers, seamlessly combining Moonshot's 1T-parameter open-source model Kimi-K2.6 with Cloudflare Workers AI. Unlike traditional AI tools, kimiflare routes traffic directly through your Cloudflare account, eliminating the n...

Orca Skills: 開源賦能,加速雲安全工作流

加速雲安全工作流 - Orca Skills 整合多種工具與插件,打造高效安全環境 | Accelerate Cloud Security Workflows with Orca Skills, a Suite of Tools and Plugins 🔎 工具速覽 / AT A GLANCE Category 开源安全工具 Pricing 开源免费 BestFor 雲安全团队、DevSecOps工程师 GitHub Stars ⭐ 33 🚀 引言 / Introduction 在雲端環境中,確保安全不僅是一種技術挑戰,更是對工作效率的一場考驗。Orca Skills 是一款專為加速 Orca 云平台安全工作流而設計的开源插件工具包。透過整合多種工具和插件,幫助我們在複雜的安全環境下保持高效率。 🛠️ 核心功能 / Key Features Orca Skills 提供了一系列功能強大的安全工作流工具,包括警報處理、影響分析、配置源頭追溯等。這些工具不僅能夠幫助我們快速定位問題,還能確保在解決問題時避免造成不必要的後續問題。 💡 技術亮點 / Tech Highlights Orca Skills 真正的亮點在于其開放性與兼容性。它不僅支持Anthropic Claude Code、Cursor 和 Codex,還能夠與 MCP(Orca Security)集成,為安全團隊提供全面的支持。 📦 快速上手 / Quick Start 要快速開始使用 Orca Skills,首先需要安裝所需環境和工具。接下來,配置 MCP 以實現與 Orca Cloud Platform 的集成。最後,測試各個技能插件以確保其正常運行。 中英文對照: 要快速開始使用 Orca Skills 首先需要安裝所需環境和工具 接著配置 MCP 以實現與 Orca 云平台的集成 最...