MemFree 和 MemAvailable 之间的区别
Difference Between MemFree and MemAvailable
使用 Ubuntu 14.02 和 运行 命令 cat /proc/meminfo,我得到以下信息:
MemTotal: 1007796 kB
MemFree: 64248 kB
MemAvailable: 64876 kB
我想知道 MemFree 和 MemAvailable 之间的确切区别。此外,任何有关如何更有效地使用系统资源的提示都将不胜感激。我订购了一台新笔记本电脑,但目前,我正在一台配备 1Gb RAM 的机器上进行开发。
注意:我是运行两个终端和eclipse的,所以你可以看到多任务是多么困难。
提前致谢。
Rik van Riel 的 comments when adding MemAvailable to /proc/meminfo:
/proc/meminfo: MemAvailable: provide estimated available memory
Many load balancing and workload placing programs check /proc/meminfo
to estimate how much free memory is available. They generally do this
by adding up "free" and "cached", which was fine ten years ago, but is
pretty much guaranteed to be wrong today.
It is wrong because Cached includes memory that is not freeable as
page cache, for example shared memory segments, tmpfs, and ramfs, and
it does not include reclaimable slab memory, which can take up a large
fraction of system memory on mostly idle systems with lots of files.
Currently, the amount of memory that is available for a new workload,
without pushing the system into swap, can be estimated from MemFree,
Active(file), Inactive(file), and SReclaimable, as well as the "low"
watermarks from /proc/zoneinfo.
However, this may change in the future, and user space really should
not be expected to know kernel internals to come up with an estimate
for the amount of free memory.
It is more convenient to provide such an estimate in /proc/meminfo.
If things change in the future, we only have to change it in one
place.
MemAvailable:内存量,可用于启动新的应用程序,无需交换.
MemFree:物理 RAM 的数量,以千比字节为单位,系统未使用。
虽然我们读的是英文,但对用户来说定义不够清楚。 MemAvailable 是指软件还是用户space? 应用程序 是什么意思?除了交换,还包括 hugepage? directmap呢?还有 kernelpage?
又是类比问题,也就是说"The name that can be named is not a Constant Name."
回到现实,我们真正想知道的是如何计算或者至少是哪个更大。
基于 ARM 的样本
# cat /proc/meminfo
MemTotal: 1053938048 kB
MemFree: 1050967832 kB
MemAvailable: 1047631704 kB
Buffers: 14972 kB
Cached: 125416 kB
SwapCached: 0 kB
基于英特尔的样本
$ cat /proc/meminfo
MemTotal: 65960628 kB
MemFree: 37493412 kB
MemAvailable: 64537424 kB
Buffers: 5899700 kB
Cached: 19890832 kB
SwapCached: 8672 kB
可惜开了两台包月服,问题更复杂了,有没有CPU相关?
好的,又回到英文了。 https://www.merriam-webster.com/dictionary/
免费:不收取任何费用
可用:存在或可立即使用
所以以表格为例进行记忆。当我们去 restraut 时,有时有免费桌子,但没有;并且有可用的桌子,但没有更多的免费桌子。
Free ram实际上是内核留下的,没有注册那个内存块使用
Available Memory是内核注册的内存块,可以立即使用。
结论:我们应该将可用内存视为空闲内存。 运行 更多应用程序的额外空间。
使用 MemAvailable 比使用 MemFree 更好。在当前的实现中,如果页面缓存很大,MemAvailable
可能比 MemFree
大得多。
作为 Rik van Riel commented when adding MemAvailable to /proc/meminfo,内核最好估计有多少空闲内存可用(它通过 MemAvailable 进行),因为计算方法可能会随着内核实现的变化而变化。
在上面链接的提交中,MemAvailable 计算为
MemAvailable = MemFree - low water mark + min(page cache/2 + low water mark)
+ some other reclaimable stuff
对我来说,这似乎不能比 MemFree 少。但我们必须记住,不同的内核可能有不同的实现,因为正如 Rik van Riel 提醒我们的那样,每个内核都知道它有多少 space 最好的。
所以使用 MemAvailable 来查看新进程可以使用多少内存。
man proc
告诉我们:
MemAvailable %lu (since Linux 3.14)
An estimate of how much memory is available for starting new applications, without swapping.
这是通俗的解释。
使用 Ubuntu 14.02 和 运行 命令 cat /proc/meminfo,我得到以下信息:
MemTotal: 1007796 kB
MemFree: 64248 kB
MemAvailable: 64876 kB
我想知道 MemFree 和 MemAvailable 之间的确切区别。此外,任何有关如何更有效地使用系统资源的提示都将不胜感激。我订购了一台新笔记本电脑,但目前,我正在一台配备 1Gb RAM 的机器上进行开发。
注意:我是运行两个终端和eclipse的,所以你可以看到多任务是多么困难。
提前致谢。
Rik van Riel 的 comments when adding MemAvailable to /proc/meminfo:
/proc/meminfo: MemAvailable: provide estimated available memory
Many load balancing and workload placing programs check /proc/meminfo to estimate how much free memory is available. They generally do this by adding up "free" and "cached", which was fine ten years ago, but is pretty much guaranteed to be wrong today.
It is wrong because Cached includes memory that is not freeable as page cache, for example shared memory segments, tmpfs, and ramfs, and it does not include reclaimable slab memory, which can take up a large fraction of system memory on mostly idle systems with lots of files.
Currently, the amount of memory that is available for a new workload, without pushing the system into swap, can be estimated from MemFree, Active(file), Inactive(file), and SReclaimable, as well as the "low" watermarks from /proc/zoneinfo.
However, this may change in the future, and user space really should not be expected to know kernel internals to come up with an estimate for the amount of free memory.
It is more convenient to provide such an estimate in /proc/meminfo. If things change in the future, we only have to change it in one place.
MemAvailable:内存量,可用于启动新的应用程序,无需交换.
MemFree:物理 RAM 的数量,以千比字节为单位,系统未使用。
虽然我们读的是英文,但对用户来说定义不够清楚。 MemAvailable 是指软件还是用户space? 应用程序 是什么意思?除了交换,还包括 hugepage? directmap呢?还有 kernelpage?
又是类比问题,也就是说"The name that can be named is not a Constant Name."
回到现实,我们真正想知道的是如何计算或者至少是哪个更大。
基于 ARM 的样本
# cat /proc/meminfo
MemTotal: 1053938048 kB
MemFree: 1050967832 kB
MemAvailable: 1047631704 kB
Buffers: 14972 kB
Cached: 125416 kB
SwapCached: 0 kB
基于英特尔的样本
$ cat /proc/meminfo
MemTotal: 65960628 kB
MemFree: 37493412 kB
MemAvailable: 64537424 kB
Buffers: 5899700 kB
Cached: 19890832 kB
SwapCached: 8672 kB
可惜开了两台包月服,问题更复杂了,有没有CPU相关?
好的,又回到英文了。 https://www.merriam-webster.com/dictionary/
免费:不收取任何费用
可用:存在或可立即使用
所以以表格为例进行记忆。当我们去 restraut 时,有时有免费桌子,但没有;并且有可用的桌子,但没有更多的免费桌子。
Free ram实际上是内核留下的,没有注册那个内存块使用
Available Memory是内核注册的内存块,可以立即使用。
结论:我们应该将可用内存视为空闲内存。 运行 更多应用程序的额外空间。
使用 MemAvailable 比使用 MemFree 更好。在当前的实现中,如果页面缓存很大,MemAvailable
可能比 MemFree
大得多。
作为 Rik van Riel commented when adding MemAvailable to /proc/meminfo,内核最好估计有多少空闲内存可用(它通过 MemAvailable 进行),因为计算方法可能会随着内核实现的变化而变化。
在上面链接的提交中,MemAvailable 计算为
MemAvailable = MemFree - low water mark + min(page cache/2 + low water mark)
+ some other reclaimable stuff
对我来说,这似乎不能比 MemFree 少。但我们必须记住,不同的内核可能有不同的实现,因为正如 Rik van Riel 提醒我们的那样,每个内核都知道它有多少 space 最好的。
所以使用 MemAvailable 来查看新进程可以使用多少内存。
man proc
告诉我们:
MemAvailable %lu (since Linux 3.14) An estimate of how much memory is available for starting new applications, without swapping.
这是通俗的解释