当前位置: 首页>>技术教程>>正文


如何解释“free -m”命令的输出?

, , ,

问题描述

free -m的输出是:

                     total    used    free    shared  buffers  cached
Mem:                  595      482     112         0       63     324
-/+ buffers/cache:              93     501
swap:                   0        0       0

使用内存的哪个值是正确的,482还是93?

最佳解决办法

你有112 MB的完全空闲内存,但你看到的501 MB没有’cached’内存。这意味着操作系统在你的 memory 中加入了一些东西以便更快。它称之为”used”(因此您的’free’号码仅为112),但如果您需要,它实际上可供您使用。

这是一件好事,因为未使用的内存是无用的内存。如果需要,可以清除缓存的内存。旧的“我需要清理内存”人们过去常常为Windows 95做的事情在这里不需要:它一切都很好,很开心:)

您要查找的数字是501免费(因为-m,以兆字节为单位)。

参考这些页面:

http://www.linuxatemyram.com/ http://www.itworld.com/it-managementstrategy/280695/making-sense-memory-usage-linux

次佳解决办法

解释free的输出:free输出的第一行列出:

  • total您的总体,物理(假设没有虚拟化)内存

  • used当前使用了多少(按任何方式)

  • free多少是完全免费的(根本不使用)

  • shared(从来没有任何东西,忽略该列)

  • buffers内核缓冲区使用的内存

  • cached用于缓存的内存

最后两项(缓存和缓冲区)是未分配给特定用户进程的内存。它是由内核保留的内存以提高整体性能,但不是”application”内存。这些区域将根据缓存,内存压力,应用程序I /O模式等内核策略而增长或缩小。

由于这两列不是user-allocated内存,并且区域可以缩小(实际上为零),如果用户分配需要它,它们在某种意义上是”free” – 如果您的应用程序主动需要它,那么内核可以释放RAM。

这就是第二行告诉你的。它从used列中删除缓冲区和缓存内存(这就是-的含义),并将它们(+)添加到free列。 (舍入问题将会发生。)

(最后一行显示交换空间的状态。)

礼貌:https://unix.stackexchange.com/a/33549/14497

因此,在您的情况下,112MB是完全可用的内存,如果您考虑用于缓存的内存,可以根据需要分配给用户应用程序;然后501 MB是可供使用的实际最大内存。

第三种解决办法

@ saji89的答案非常好,但是现在free -m不再打印-/+ buffers/cache线,而是将可用RAM的数量放在第一行的新available列中,例如:

ubuntu@pg_master:~$ free -m
              total        used        free      shared  buff/cache   available
Mem:          61406        1571         506       17131       59328       42150
Swap:             0           0           0
ubuntu@pg_master:~$ free -V
free from procps-ng 3.3.10

您可以读取删除行in their repo的提交(1)。还提交添加新的available列。

第四种办法

free命令显示有关未使用和已用内存和交换空间的信息。

以下是http://www.linfo.org/free.html提供的解释

The first row, labeled Mem, displays physical memory utilization, including the amount of memory allocated to buffers and caches. A buffer, also called buffer memory, is usually defined as a portion of memory that is set aside as a temporary holding place for data that is being sent to or received from an external device, such as a HDD, keyboard, printer or network.

The second line of data, which begins with -/+ buffers/cache, shows the amount of physical memory currently devoted to system buffer cache. This is particularly meaningful with regard to application programs, as all data accessed from files on the system that are performed through the use of read() and write() system calls1 pass through this cache. This cache can greatly speed up access to data by reducing or eliminating the need to read from or write to the HDD or other disk.

The third row, which begins with Swap, shows the total swap space as well as how much of it is currently in use and how much is still available.

让我们分析一下系统的内存使用情况

您已使用带有’-m’选项的free命令,该选项用于以兆字节为单位显示结果

-m, --mega
              Display the amount of memory in megabytes.

总内存为595(二手+免费)

使用:482免费:112

您的系统使用了595MB中的482MB,其中活动程序仅使用93MB而缓存中剩余324MB

因此,当您将来运行任何程序时,请说需要120MB以上。所有112MB(目前免费)将被提供,剩余的8MB将从non-active程序缓冲区/缓存中获取。

编辑:找到这个link,它提供了很好的解释。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/2212.html,未经允许,请勿转载。