/proc/meminfo详解
/proc/meminfo Explained
"Free," "buffer," "swap," "dirty." What does it all mean? If you said, "something to do with the Summer of '68", you may need a primer on 'meminfo'.
The entries in the /proc/meminfo can help explain what's going on with your memory usage, if you know how to read it.
Example of "cat /proc/meminfo":
root: total: used: free: shared: buffers: cached:
Mem: 1055760384 1041887232 13873152 0 100417536 711233536
Swap: 1077501952 8540160 1068961792
MemTotal: 1031016 kB
MemFree: 13548 kB
MemShared: 0 kB
Buffers: 98064 kB
Cached: 692320 kB
SwapCached: 2244 kB
Active: 563112 kB
Inact_dirty: 309584 kB
Inact_clean: 79508 kB
Inact_target: 190440 kB
HighTotal: 130992 kB
HighFree: 1876 kB
LowTotal: 900024 kB
LowFree: 11672 kB
SwapTotal: 1052248 kB
SwapFree: 1043908 kB
Committed_AS: 332340 kB
The information comes in the form of both high-level and low-level statistics. At the top you see a quick summary of the most common values people would like to look at. Below you find the individual values we will discuss. First we will discuss the high-level statistics.
High-Level Statistics
MemTotal: Total usable ram (i.e. physical ram minus a few reserved bits and the kernel binary code)
MemFree: Is sum of LowFree+HighFree (overall stat)
MemShared: 0; is here for compat reasons but always zero.
Buffers: Memory in buffer cache. mostly useless as metric nowadays
Cached: Memory in the pagecache (diskcache) minus SwapCache
SwapCache: Memory that once was swapped out, is swapped back in but still also is in the swapfile (if memory is needed it doesn't need to be swapped out AGAIN because it is already in the swapfile. This saves I/O)
Detailed Level Statistics
VM Statistics
VM splits the cache pages into "active" and "inactive" memory. The idea is that if you need memory and some cache needs to be sacrificed for that, you take it from inactive since that's expected to be not used. The vm checks what is used on a regular basis and moves stuff around.
When you use memory, the CPU sets a bit in the pagetable and the VM checks that bit occasionally, and based on that, it can move pages back to active. And within active there's an order of "longest ago not used" (roughly, it's a little more complex in reality). The longest-ago used ones can get moved to inactive. Inactive is split into two in the above kernel (2.4.18-24.8.0). Some have it three.
Active: Memory that has been used more recently and usually not reclaimed unless absolutely necessary.
Inact_dirty: Dirty means "might need writing to disk or swap." Takes more work to free. Examples might be files that have not been written to yet. They aren't written to memory too soon in order to keep the I/O down. For instance, if you're writing logs, it might be better to wait until you have a complete log ready before sending it to disk.
Inact_clean: Assumed to be easily freeable. The kernel will try to keep some clean stuff around always to have a bit of breathing room.
Inact_target: Just a goal metric the kernel uses for making sure there are enough inactive pages around. When exceeded, the kernel will not do work to move pages from active to inactive. A page can also get inactive in a few other ways, e.g. if you do a long sequential I/O, the kernel assumes you're not going to use that memory and makes it inactive preventively. So you can get more inactive pages than the target because the kernel marks some cache as "more likely to be never used" and lets it cheat in the "last used" order.
Memory Statistics
HighTotal: is the total amount of memory in the high region. Highmem is all memory above (approx) 860MB of physical RAM. Kernel uses indirect tricks to access the high memory region. Data cache can go in this memory region.
LowTotal: The total amount of non-highmem memory.
LowFree: The amount of free memory of the low memory region. This is the memory the kernel can address directly. All kernel datastructures need to go into low memory.
SwapTotal: Total amount of physical swap memory.
SwapFree: Total amount of swap memory free.
Committed_AS: An estimate of how much RAM you would need to make a 99.99% guarantee that there never is OOM (out of memory) for this workload. Normally the kernel will overcommit memory. That means, say you do a 1GB malloc, nothing happens, really. Only when you start USING that malloc memory you will get real memory on demand, and just as much as you use. So you sort of take a mortgage and hope the bank doesn't go bust. Other cases might include when you mmap a file that's shared only when you write to it and you get a private copy of that data. While it normally is shared between processes. The Committed_AS is a guesstimate of how much RAM/swap you would need worst-case.
在Linux下查看内存我们一般用free命令:
[root@scs-2 tmp]# free
total used free shared buffers cached
Mem: 3266180 3250004 16176 0 110652 2668236
-/+ buffers/cache: 471116 2795064
Swap: 2048276 80160 1968116
下面是对这些数值的解释:
total:总计物理内存的大小。
used:已使用多大。
free:可用有多少。
Shared:多个进程共享的内存总额。
Buffers/cached:磁盘缓存的大小。
第三行(-/+ buffers/cached):
used:已使用多大。
free:可用有多少。
第四行就不多解释了。
区 别:第二行(mem)的used/free与第三行(-/+ buffers/cache) used/free的区别。这两个的区别在于使用的角度来看,第一行是从OS的角度来看,因为对于OS,buffers/cached 都是属于被使用,所以他的可用内存是16176KB,已用内存是3250004KB,其中包括,内核(OS)使用+Application(X, oracle,etc)使用的+buffers+cached.
第三行所指的是从应用程序角度来看,对于应用程序来说,buffers/cached 是等于可用的,因为buffer/cached是为了提高文件读取的性能,当应用程序需在用到内存的时候,buffer/cached会很快地被回收。
所以从应用程序的角度来说,可用内存=系统free memory+buffers+cached。
如上例:
2795064=16176+110652+2668236
接下来解释什么时候内存会被交换,以及按什么方交换。 当可用内存少于额定值的时候,就会开会进行交换。
如何看额定值:
cat /proc/meminfo
[root@scs-2 tmp]# cat /proc/meminfo
MemTotal: 3266180 kB
MemFree: 17456 kB
Buffers: 111328 kB
Cached: 2664024 kB
SwapCached: 0 kB
Active: 467236 kB
Inactive: 2644928 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 3266180 kB
LowFree: 17456 kB
SwapTotal: 2048276 kB
SwapFree: 1968116 kB
Dirty: 8 kB
Writeback: 0 kB
Mapped: 345360 kB
Slab: 112344 kB
Committed_AS: 535292 kB
PageTables: 2340 kB
VmallocTotal: 536870911 kB
VmallocUsed: 272696 kB
VmallocChunk: 536598175 kB
HugePages_Total: 0
HugePages_Free: 0
Hugepagesize: 2048 kB
用free -m查看的结果:
[root@scs-2 tmp]# free -m
total used free shared buffers cached
Mem: 3189 3173 16 0 107 2605
-/+ buffers/cache: 460 2729
Swap: 2000 78 1921
查看/proc/kcore文件的大小(内存镜像):
[root@scs-2 tmp]# ll -h /proc/kcore
-r-------- 1 root root 4.1G Jun 12 12:04 /proc/kcore
备注:
占用内存的测量
测量一个进程占用了多少内存,linux为我们提供了一个很方便的方法,/proc目录为我们提供了所有的信息,实际上top等工具也通过这里来获取相应的信息。
/proc/meminfo 机器的内存使用信息
/proc/pid/maps pid为进程号,显示当前进程所占用的虚拟地址。
/proc/pid/statm 进程所占用的内存
[root@localhost ~]# cat /proc/self/statm
654 57 44 0 0 334 0
输出解释
CPU 以及CPU0。。。的每行的每个参数意思(以第一行为例)为:
参数 解释 /proc//status
Size (pages) 任务虚拟地址空间的大小 VmSize/4
Resident(pages) 应用程序正在使用的物理内存的大小 VmRSS/4
Shared(pages) 共享页数 0
Trs(pages) 程序所拥有的可执行虚拟内存的大小 VmExe/4
Lrs(pages) 被映像到任务的虚拟内存空间的库的大小 VmLib/4
Drs(pages) 程序数据段和用户态的栈的大小 (VmData+ VmStk )4
dt(pages) 04
查看机器可用内存
/proc/28248/>free
total used free shared buffers cached
Mem: 1023788 926400 97388 0 134668 503688
-/+ buffers/cache: 288044 735744
Swap: 1959920 89608 1870312
我们通过free命令查看机器空闲内存时,会发现free的值很小。这主要是因为,在linux中有这么一种思想,内存不用白不用,因此它尽可能的cache和buffer一些数据,以方便下次使用。但实际上这些内存也是可以立刻拿来使用的。
所以 空闲内存=free+buffers+cached=total-used
转载于:https://my.oschina.net/alfredliukai/blog/488346
相关推荐
在Linux操作系统中,`/proc`目录是一个非常特殊且至关重要的目录,它并不像其他常规目录那样存储实际的文件...通过阅读《Linux中proc目录下文件详解.pdf》这样的文档,可以更深入地理解这些概念并提高系统管理能力。
3. **/proc/meminfo**: 显示系统的内存使用情况,包括物理内存、交换内存、缓冲区和缓存的大小等。 4. **/proc/version**: 展示当前运行的Linux内核版本。 5. **/proc/filesystems**: 列出了系统支持的所有文件系统...
**proc 文件系统详解** 在Linux操作系统中,proc文件系统是一个非常特殊的虚拟文件系统,它并不直接存储磁盘上的数据,而是作为一个接口,提供了对系统内核状态的实时访问。proc目录下包含了大量的文件和目录,它们...
### Linux_procfs详解 #### 一、引言 在Linux操作系统中,有一个非常重要的伪文件系统,名为`procfs`。这个特殊的文件系统为用户提供了一种简单而直接的方式来访问正在运行的内核的状态以及进程信息。它允许用户...
Linux 内核系统文件详解 Linux 内核系统文件是 Linux 操作系统的核心组件之一,负责管理系统的硬件资源、进程调度、内存管理、网络通信等多方面的功能。在 Linux 系统中,有许多重要的系统文件,掌握这些文件的作用...
### Linux /proc 目录详解及其子文件或子文件夹的作用 #### 一、Linux /proc 目录简介 在Linux系统中,`/proc` 是一个特殊的文件系统,它实际上是一个虚拟的文件系统,其内容全部存在于内存之中,不占用实际的磁盘...
- **/proc/meminfo**:提供有关物理内存和交换分区的信息。 - **/proc/modules**:列出已加载的内核模块。 - **/proc/net**:提供网络相关统计信息。 - **/proc/self**:指向当前进程的目录。 总之,/proc 目录是...
### Linux Proc 文件系统详解 #### 引言 在深入探讨`proc`文件系统之前,我们首先需要理解`proc`在Linux系统中的独特地位。`proc`并非一个真正的磁盘文件系统,而是一种特殊的虚拟文件系统,它存在于内存中,提供...
【Linux proc 文件系统详解】 Linux proc 文件系统是一个虚拟文件系统,它并不占用磁盘空间,而是作为内核和用户空间之间通信的一个接口。通过 proc 文件系统,用户可以在运行时查看和修改内核的状态,获取系统及...
1. **/proc目录详解**: `/proc`目录是一个伪文件系统,不占用磁盘空间,而是直接反映了内核的状态。其中包含了大量关于系统硬件和软件状态的文件,如`/proc/cpuinfo`(CPU信息)、`/proc/meminfo`(内存信息)和`/...
- /proc/meminfo文件包含了系统内存总量和当前可用内存的详细信息。 - 通过循环读取/proc/loadavg来获取每分钟的平均负载。 实验步骤与调试记录: 1. 对于不同的命令行参数,程序会执行相应的操作,如-b参数显示...
### Linux常用命令详解 Linux作为一款强大的开源操作系统,在服务器领域占据着极其重要的地位。对于Linux用户来说,熟练掌握一系列常用命令是必不可少的技能之一。本文将详细介绍标题与描述中所提及的一些关键Linux...
例如,`/proc/meminfo` 提供了内存使用情况的信息,而 `/proc/cpuinfo` 提供了关于CPU的详细信息。 - **free**: 查看内存的使用情况。使用 `free -m` 可以看到以MB为单位的内存使用详情。 - **df**: 查看硬盘使用...
### Linux常用命令详解 #### 一、系统管理与设置 **1. 信息显示命令** - **`man & info`**: 提供了两种查看命令帮助的方式。`man` 是手册(manual)的缩写,而 `info` 则提供更详细的帮助文档。 - **示例**: `man ...
# grep MemTotal /proc/meminfo # 查看内存总量 # grep MemFree /proc/meminfo # 查看空闲内存量 # uptime # 查看系统运行时间、用户数、负载 # cat /proc/loadavg # 查看系统负载 三、磁盘与分区: # mount | ...
### Linux常用命令详解 在Linux操作系统中,熟练掌握各种命令行工具是进行高效系统管理和日常操作的基础。本文将详细介绍一系列常用的Linux命令,帮助用户更好地理解并应用这些命令来完成特定任务。 #### 系统信息...
- `/proc/meminfo`:提供内存使用情况的统计。 #### 软件挂载实例 - **软盘挂载**:对于MS-DOS格式的软盘,使用`#mount -t msdos /dev/fd0 /mnt/floppy`命令挂载;对于Linux格式的软盘,直接使用`#mount /mnt/...
- `/proc/meminfo`:提供内存和交换空间的详细统计。 - `/proc/stat`:包含CPU使用情况、进程统计等大量信息。 5. 集群管理系统设计: 针对集群管理的挑战,需要设计出一种能够适应Linux集群发展的管理框架,...