Introduction
Memory (memory) is an important indicator of operating system management. Monitoring memory usage helps to find memory problems in advance and avoid failures caused by memory exhaustion.
If the memory is almost exhausted, OOM will generally occur.
Command view
Use the free command to view
free
total used free shared buff/cache availableMem: 16045460 2493184 10043920 568668 3508356 12683216Swap: 0
View statistics
free -t
free -t total used free shared buff/cache availableMem: 16189224 3981536 7458680 1902204 4749008 10029104Swap: 0 0 0Total: 16189224 3981536 7458680
The default is to use the byte unit, you can also use -k or -m or -g to switch the value unit
Detailed indicators
The Linux kernel is responsible for counting the memory usage and exposing it to the /proc pseudo file system, the path is /proc/meminfo. Generally speaking, the indicators that need to be focused on are as follows: Memory usage indicators (bytes):
total 物理内存总量free 空闲内存(未使用)buffers 内核缓冲区cached 文件缓冲页slab 内核 slab 数据结构cache cached 以及 slab 之和g_free 广义空闲内存used 已使用内存active 活跃内存inactive 非活跃内存available 可用内存
total
total represents the total amount of physical memory, in bytes, corresponding to the MemTotal field of /proc/meminfo.
free
free represents the amount of free memory, in bytes, corresponding to the MemFree field of /proc/meminfo.
buffers
Buffers represents the kernel buffer, in bytes, corresponding to the Buffers field of /proc/meminfo.
cached
cached represents the file buffer page, in bytes, corresponding to the Cached field of /proc/meminfo.
slab
slab represents the kernel slab data structure, in bytes, corresponding to the Slab field of /proc/meminfo.
cache
The cache is the same as the cache in the free command, that is, the sum of cached and slab:
cache = cached + slab
g_free
g_free represents generalized free memory (generalized free), the unit is byte, and the calculation method is as follows:
g_free = free + buffers + cache
Buffers and cache are caches used by the system to improve performance, and can be recycled for other purposes at any time when the memory is tight. Therefore, this part of the memory can be considered free in a sense, which is the origin of the generalized free memory.
used
used means used memory, the unit is byte, the calculation method is as follows:
used = total - g_free = total - free - buffers - cache
active
active means active memory, in bytes, corresponding to the Active field of /proc/meminfo.
Active memory refers to memory that has been frequently accessed recently, and is usually not reallocated unless it is necessary.
inactive
inactive means inactive memory, in bytes, corresponding to the Inactive field of /proc/meminfo.
Inactive memory refers to memory that has been seldom accessed recently. When new memory needs to be allocated, this part is preferred.
available
Starting from the 3.14 kernel version, it is provided in the MemAvailable field of /proc/meminfo. Available means available memory, in bytes.
Available memory refers to the memory that can be used to start a new application process. This indicator is an estimate provided by the kernel. It also combines free and cache two parts of memory, but takes into account the situation that the cache cannot be released due to use. Therefore, it can be considered that:
free <= available <= g_free
to sum up
On CentOS 7, the available memory is basically judged based on available memory.