【linux命令】 free

上图是在ubuntu16.04上执行free命令的输出信息,-m是让其以MB为单位进行显示。下面让我们来看看每个字段具体的意思。

total:代表内存总数

used:代表的是当前使用的内存

free:代表现在还有多少内存可以使用(不包括buffers和cached中的)

shared:代表共享的内存(共享的,在linux里面有很多共享内存,比如一个libc库,很多程序调用,但实际只存一份。这里是别人博客写的,目前不知对错)

buffers:代表要写入磁盘的数据

cached:代表从磁盘中读到内存中的数据

swap:代表交换分区的内存

buffers和cached

buffers:当应用程序往磁盘中写数据时(如调用write),并不会立马把数据写入到磁盘中,而是把数据写到buffers中,等到后面再刷入到磁盘中。如果没有buffers,那么每调用一次write就要进行一次IO操作。使用buffers后就可以使原来需要多次IO操作合并为一次IO操作。

cached:也是用来减少IO操作的,只不过这个是用来减少读IO操作,操作系统每次读取数据的时候就把读取后的数据放到cached中去,如果后面还有进程要读取同一个文件,那么直接从cached中读就可以了,不用再去访问磁盘。

由于可能cached和buffers会保存同一份数据,所以从2.6内核之后就把cached和buffers合并了。

各种空间的计算

空闲空间:很多人会认为free就是总的可用的空闲空间,其实当内存不够用时,操作系统会把buffers和cached中的空间清理出来给应用程序使用,如上图所示,总的可用空间就是free+buffers+cached(上图中还加上了shared,不知道为什么要加上这个)

used内存:这里used内存包含了应用程序使用的内存加上buffers、cached和shared的内存。

 

 

上面的是旧版free显示的信息,下面是新版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, available 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)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值