Linux "free -m":总内存、已用内存和可用内存值不相加

Linux "free -m": Total, used and free memory values don't add up

在 linux 系统上,使用 "free" 时,以下是值:

         total      used      free    shared  buff/cache   available
Mem:  26755612    873224    389320    286944    25493068    25311948
Swap:        0         0         0

总值、已用值和免费值不相加。我预计总计 = 使用 + 免费。

问题: 我在这里错过了什么?

对于主内存,内存的实际大小可以计算为used+free+buffers+cache OR used+free+buffers/cache因为 buffers/cache = buffer+cache.

free 的手册页将 used 突出显示为 Used memory (calculated as total - free - buffers - cache)

正如 free 的手册页所说:-

total Total installed memory (MemTotal and SwapTotal in /proc/meminfo)

used Used memory (calculated as total - free - buffers - cache)

free Unused memory (MemFree and SwapFree in /proc/meminfo)

shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo, on kernels 2.6.32, displayed as zero if not available)

buffers Memory used by kernel buffers (Buffers in /proc/meminfo)

cache Memory used by the page cache and slabs (Cached and Slab in /proc/meminfo)

buff / cache Sum of buffers and cache

available Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)

在你的情况下,


873224(used) + 389320(free) + 25493068(buff/cache) = 26755612(total)


Linux 喜欢缓存它打开的每个文件。每次您打开一个文件进行读取时,Linux 都会对其进行缓存,但如果它需要内存来处理更重要的事情,它会删除这些缓存——比如当系统上的进程想要分配更多内存时。当一遍又一遍地使用相同的文件时,内存中的这些缓存只会使 Linux 更快。它不是每次要读取文件时都去磁盘,而是从内存中获取文件,而内存比磁盘快得多。这就是为什么您的系统显示 25493068 used in buff/cache 但也显示 25311948 available 的原因。如果系统需要,可以释放大部分缓存数据。