了解“缓冲区"和“已缓存"来自自由命令 [英] Understanding "Buffers" and "Cached" from free command

查看:133
本文介绍了了解“缓冲区"和“已缓存"来自自由命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早些时候已经问过这个问题,但是不想再次更新同一线程,因为它是一个旧线程.

This has been asked earlier but don't want to update the same thread again as it was a old thread .

想在free命令输出中的缓冲区"和缓存"列中阐明自己.

Want to clarify myself on the "buffers" and "cache" column from the output of free command.

这就是我的理解...

This is what my understanding...

缓冲区是内存中有数据但尚未刷新到磁盘的东西. 数据将由bdflush守护程序定期刷新到磁盘,或者我们可以通过运行sync命令手动进行.

Buffer is something where data is there in memory but yet to be flushed to disk . The data will be flushed to disk by bdflush daemon periodically or we can do it manually by running sync command .

缓存是程序/数据,它已加载到内存中但保留在内存中,因此,如果再次需要,它将可以快速使用.

Cache on the other hand is program/data which is loaded into memory but is retained in memory so that if is needed again , it will be quickly available.

要了解缓冲区的概念,我尝试了以下实验...

To understand the concept of buffers , I tried the following experiment...

这是我的桌面上free命令的内容

This is the reading of free command in my desktop


[zama@localhost ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:          2897        465       2431          0         30        230
-/+ buffers/cache:        204       2692
Swap:         4000          0       4000

[zama@localhost ~]$ sync

[zama@localhost ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:          2897        466       2431          0         30        230
-/+ buffers/cache:        205       2691
Swap:         4000          0       4000

在这里,我看不到执行sync命令后缓冲区减少.

Here I cannot see buffer getting reduced after executing the sync command.

接下来,我尝试了以下方法...试图将大文件写入磁盘.

Next I tried the following...Tried to write a huge file to the disk .


[zama@localhost ~]$ dd if=/dev/zero of=test bs=1024k 

如预期的那样,缓存的值应该增加,并且free可以确认这一点.

As expected , the cached value should increase and free is confirming this..


@localhost ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          2897       1466       1430          0         32       1127
-/+ buffers/cache:        306       2590
Swap:         4000          0       4000

我再次执行了sync命令,然后使用free进行了检查.我可以看到缓冲区值从free命令的输出中减少了.缓存没有减少.这意味着在我执行dd coomand之后,RAM中的脏页已被刷新到磁盘上.

I again executed the sync command and then checked using free . I can see that the buffer value getting decreased from the output of free command . There was no reduction in the cache . This means that the dirty pages in RAM after my execution of dd coomand has been flushed to disk .


@localhost ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          2897       1466       1430          0         10       1127
-/+ buffers/cache:        306       2590
Swap:         4000          0       4000

然后我更新了drop_cache内核参数,以便删除缓存vlaue

Then I updated the drop_cache kernel parameter so that the cache vlaue is dropped


[root@localhost ~]# cat /proc/sys/vm/drop_caches 
0

[root@localhost ~]# echo "1" > /proc/sys/vm/drop_caches 

[root@localhost ~]# cat /proc/sys/vm/drop_caches 
1

free现在确认缓冲区和高速缓存值均已删除.

free now confirms that both buffer and cache value is dropped.


[root@localhost ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          2897        299       2597          0          1         74
-/+ buffers/cache:        224       2672
Swap:         4000          0       4000

因此,我最初的说法是缓冲区"是尚未刷新到磁盘的RAM数据,看起来是正确的.

So , my initial statement that "Buffer" is RAM data which is yet to be flushed to disk looks to be correct .

请指导我是否朝着正确的方向

Please guide me whether I am in the right direction.

推荐答案

free命令中的列标题至少在Linux用户(与开发人员相对)的角度上被贴错了标签.以下是标题含义的说明:

The column headers in the free command are somewhat mislabeled, at least from the point of view of a linux user (as opposed to developer). Below is a clarification of what the headings mean:

总计:是的,这是总内存.

total: Yes, this is total ram.

使用过的:这可能是最混乱的列.这是应用程序使用的内存和其他临时"(缓冲区+缓存)使用的内存(如果需要的话)的混合物.因此,从技术上讲,内存是真正使用的内存,但是如果应用程序需要,则可以使用很多内存.如果Linux系统可用,则借用临时"使用的内存,以帮助提高系统性能,否则系统将更频繁地从磁盘读取数据.此类存储器的大部分显示在已缓存"列下.如果应用程序需要内存,则linux系统会放弃此内存.

used: This is probably the most confused column. This is a mix of application used memory and other 'temporarily' (buffer + cache) used memory that is actually available if needed. So technically the memory is truly being used, but much of this memory is available if an application needs it. The 'temporarily' used memory is borrowed if available by the linux system to help speed up system performance, otherwise the system would have read from disk more often. Much of this type of memory is shown under the 'cached' column. This memory is given up by the linux system if an application need memory.

免费:是的,这是完全免费且未曾改变的内存.

free: Yes, this pure free and untouched memory.

共享:专门分配给多个进程使用的内存

shared: Memory specifically allocated for use by multiple processes

缓冲区:为帮助某些进程而预留的临时内存

buffers: Temporary memory that is set aside to help some processes

缓存:操作系统可用和借用"的内存,以帮助加速许多Linux OS操作.如果应用程序需要,该内存将由系统放弃.

cache: Memory that is available and 'borrowed' by the operating system to help speed up many linux OS operations. This memory is given up by the system if an application need it.

-/+ buffers/cache 开头的行通常比 Mem 的第一行更有帮助. 免费-/+缓冲区/高速缓存的交集本质上就是您拥有可用"内存的条件.

The line that starts with -/+ buffers/cache is typically more helpful than the first Mem line. The intersection of free and -/+ buffers/cache is essentially what you have for 'available' memory.

这篇关于了解“缓冲区"和“已缓存"来自自由命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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