了解linux`free -m`中的缓冲区/缓存 [英] Understanding buffers/cache in linux `free -m`

查看:152
本文介绍了了解linux`free -m`中的缓冲区/缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只需寻找有关Linux上free -m输出的快速帮助.这是我的一台服务器上的示例:

Just looking for some quick help regarding free -m output on Linux. Here's an example on one of my servers:

  $free -m
               total       used       free     shared    buffers     cached
  Mem:         14881      14813         68          0        262        883
  -/+ buffers/cache:      13667       1213
  Swap:         4095        240       3855

我了解内核可以并且将使用可用内存进行磁盘缓存以加快系统速度.

I understand the kernel can and will use available memory for disk caching to speed up the system.

通常,我在免费"列中查看第二个值,在上述情况下,它是1213.通常比这个值高很多.

Normally, I look at the second value in the "free" column, in the above case it's 1213. It's normally a lot higher than this.

我想我想了解-/+缓冲区/缓存"旁边的两个输出是什么意思.从我所看到的来看,系统确实内存不足(只有1213MB的空间可供应用程序使用),而操作系统实际上需要 13GB进行缓存吗?

I guess I am looking to understand what the two outputs next to '-/+ buffers/cache' mean. From what I can see, the system truly is low on memory (only 1213MB available for applications to use) and the OS actually needs 13GB for caching?

推荐答案

已在serverfault中得到答复.以下是相关摘录:

total = used + free

  • shared/buffers/cached:显示特定用途的内存使用情况,这些值包含在used的值中.
  • shared / buffers / cached: This shows memory usage for specific purposes, these values are included in the value for used.

第二行给出调整后的第一行值.它给出了used 减去的总和buffers+cached的原始值,并且给出了free plus 的总和buffers+cached的原始值,因此得到了标题.这些新值通常比第一行更有意义.

The second line gives first line values adjusted. It gives the original value for used minus the sum buffers+cached and the original value for free plus the sum buffers+cached, hence its title. These new values are often more meaningful than those of first line.

[摘录结束]

关注您的情况

  • 14813(已用内存)-262(已缓冲)-883(已缓存)= 13668(由应用程序使用).

如果应用程序需要更多内存,则可以从可用内存中获取,也可以从缓存/缓冲中获取,因此:

In the event an application needs more memory, it can be taken either from free memory or from cached/buffered, so:

  • 262(缓冲的)+ 883(缓存的)+ 68(根本不使用)= 1213(适用于应用程序).

该系统实际上并不需要缓存和缓冲区262 + 883 = 1145(不是13GB),但是由于它已经存在,因此可以使用它(但是如果应用程序需要更多,则将其退还).看看 Linux吞噬了我的RAM!页面.

The system does not really need 262+883=1145 (not 13GB) for cache and buffers, but since it's there, it takes it (but gives it back if applications need more). Take a look at the Linux ate my RAM! page.

您还可以使用top(我个人更喜欢htop)查看内存状态以及哪些应用程序占用了最多的RAM.

You can also use top (I personally prefer htop) to see the memory status and which applications are taking most RAM.

作为示例,这是在我的RaspberryPi中运行的htop和free -h执行的屏幕截图:

As an example, here is a screenshot of htop running in my RaspberryPi and the free -h execution:

raspberry ~ # free -h
             total       used       free     shared    buffers     cached
Mem:          183M       178M       5,3M         0B        63M        42M
-/+ buffers/cache:        72M       111M
Swap:           0B         0B         0B

这篇关于了解linux`free -m`中的缓冲区/缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆