怎么理解Linux内存管理中Buffer和Cache
发表于:2025-11-06 作者:千家信息网编辑
千家信息网最后更新 2025年11月06日,本篇内容介绍了"怎么理解Linux内存管理中Buffer和Cache"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,
千家信息网最后更新 2025年11月06日怎么理解Linux内存管理中Buffer和Cache
本篇内容介绍了"怎么理解Linux内存管理中Buffer和Cache"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
在Linux中,一般使用free命令查看内存的使用情况
[root@localhost ~]# free total used free shared buff/cache availableMem: 3873760 143548 3322324 8788 407888 3453708Swap: 1048572 0 1048572[root@localhost ~]#
通过命令man free可查看以上输出项所代表的意思
DESCRIPTION free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo. The displayed columns are: 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+, oth‐ erwise the same as free)
free命令显示了空闲+物理使用+交换区等信息,通过解析/proc/meminfo获得,该文件中的内容如下:
[root@localhost ~]# cat /proc/meminfoMemTotal: 3873760 kBMemFree: 3322052 kBMemAvailable: 3453436 kBBuffers: 3252 kBCached: 320316 kBSwapCached: 0 kBActive: 256968 kBInactive: 124468 kBActive(anon): 58264 kBInactive(anon): 8392 kBActive(file): 198704 kBInactive(file): 116076 kBUnevictable: 0 kBMlocked: 0 kBSwapTotal: 1048572 kBSwapFree: 1048572 kBDirty: 0 kBWriteback: 0 kBAnonPages: 57868 kBMapped: 27384 kBShmem: 8788 kBSlab: 84320 kBSReclaimable: 42580 kBSUnreclaim: 41740 kBKernelStack: 3120 kBPageTables: 4492 kBNFS_Unstable: 0 kBBounce: 0 kBWritebackTmp: 0 kBCommitLimit: 2985452 kBCommitted_AS: 293568 kBVmallocTotal: 34359738367 kBVmallocUsed: 180372 kBVmallocChunk: 34359326716 kBHardwareCorrupted: 0 kBAnonHugePages: 4096 kBHugePages_Total: 0HugePages_Free: 0HugePages_Rsvd: 0HugePages_Surp: 0Hugepagesize: 2048 kBDirectMap4k: 81728 kBDirectMap2M: 3063808 kBDirectMap1G: 3145728 kB[root@localhost ~]#
total - 总内存大小
used - 使用的内存大小
free - 未使用内存大小
shared - tmpfs使用的内存
buffers - 内核缓存大小(/proc/meminfo中的Buffers)
cache - 页面缓存和slabs(/proc/meminfo中的Cached和Slab)
buff/cache - buffers + cache
available - 可用内存大小(剔除交换区)
buffers和cache在man free中仍没有详细解释清楚,通过查看kernel doc进一步获得相关的解释
...Buffers: Relatively temporary storage for raw disk blocks shouldn't get tremendously large (20MB or so)Cached: in-memory cache for files read from the disk (the pagecache). Doesn't include SwapCachedSlab: in-kernel data structures cacheSReclaimable: Part of Slab, that might be reclaimed, such as cachesSUnreclaim: Part of Slab, that cannot be reclaimed on memory pressure
Buffers - 裸磁盘块的临时存储(通常不会不大,20MB左右)
Cached - 从磁盘上读取文件的缓存(即页面缓存).不包括SwapCached
Slab - 内核中的数据结构缓存
SReclaimable - Slab中的一部分,可回收
SUnreclaim - Slab中的另一部分,不能回收
使用vmstat可监控内存的使用情况
[root@localhost ~]# echo 3 > /proc/sys/vm/drop_caches[root@localhost ~]# vmstat 1procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 1 0 3648060 0 96964 0 0 4 5158 151 174 5 6 89 0 0 0 0 0 3648248 0 97424 0 0 296 0 311 331 0 1 99 0 0...
"怎么理解Linux内存管理中Buffer和Cache"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
内存
大小
缓存
内容
命令
情况
管理
内核
文件
更多
知识
磁盘
页面
解释
实用
清楚
学有所成
接下来
不大
代表
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库加群速度
数据库的er图实例
电子信息包括软件开发吗
辣苹果网络技术有限公司
对于数据库的管理权限最大的用户
风险数据库是什么
搭建服务器用什么路由器
网络安全共建网
修改后台数据库的数据
腾讯云服务器激活码
数据库的表的字段默认值怎么修改
ubuntu镜像清华服务器配置
提供软件开发厂家价格
上海交通大学icsd数据库
镇海手机软件开发工具
查询数据库用户下表名
软件开发语言指什么意思
软件开发刚到公司做
系统软件开发保密期限
一网科技网络技术有限公司
广州荔支网络技术有限公司职友集
反邪教网络安全主题班会教案
网络技术二是啥
赞皇软件开发设计
数据库只存日期的年
沙盒游戏服务器能进多少人
数据库完整性分为三种
软件开发麻将游戏的论文
技能高考网络安全分数分布
数据库参考文献怎么写