Linux command Daquan memory analysis tool introduced

In the Linuxsystems it is often used as a server system. When the server memory is tight, the freecommand is memory analysis tool we use most often.

freeUse presentation #

freeCommand to display Linuxidle in the system, have been used in physical memory and swapmemory, and is used by the kernel buffer. In the Linuxtool monitoring system, the freecommand is one of the most frequently used commands.

free command very simple to use.

Copy
# 命令格式
free [参数]
# 可选参数
-b  以Byte为单位显示内存使用情况。 
-k  以KB为单位显示内存使用情况。 
-m  以MB为单位显示内存使用情况。
-g   以GB为单位显示内存使用情况。
-h   根据内存大小自动选择合适的单位显示
-o  不显示缓冲区调节列。 
-s<间隔秒数>  持续观察内存使用状况。
-c<显示次数>   和-s配合使用
-t  显示内存总和列。 
-V  显示版本信息。

Here are the most commonly used one of my command format

Copy
#显示所有的内存信息,每隔两秒显示一次,一共显示两次
free -ah -s 2 -c 2

Output shown below

Copy
             total       used       free     shared    buffers     cached  available
Mem:          6.6G       5.5G       1.0G       1.1M 247M 3.5G 0B -/+ buffers/cache: 1.8G 4.8G Swap: 5.0G 106M 4.9G 

The following description of these parameters do next.

freeOutput Parameter Description #

First data on the above red box do the next instructions. MenShows a specific physical memory, freethe statistics from the physical memory where the plurality of dimensions, each dimension the following meaning:

  • total: total physical memory size.
  • used: the size of the physical memory has been used.
  • free: how much of the available physical memory.
  • shared: multiple processes to share memory total.
  • buffers: the size of the write buffer memory disk (disk IO efficiency is often relatively low, so the first to be written to disk files for a certain amount of buffer, the buffer data reaches a certain size, etc. is a one-time written to disk, increase efficiency)
  • cached: read the contents of the cache size from the disk (the principle is similar).
  • available: The following will be introduced.

  • -buffers / cache: represents real eaten program memory, such as the image above usedmemory is 5.5G, but the real memory used by an application only 1.8G, the other occupied by the main memory used to cache data, and also It is above 3.5G.
  • + Buffers / cache: indicates the total memory applications can also be filed.

The last line of the figure above is the use of the swap partition, will be described in detail below.

free parameters and available parameters the difference between #

Free command output, there is a free column, as well as an available column. What's the difference both in the end?

free is the amount of physical memory really has not been used. As available is more interesting, it is the amount of memory available from the application point of seeing. Linux kernel in order to enhance the performance of disk operations will consume some memory to cache disk data, and cache buffer that we introduce. So for kernels, buffer and cache memory are all already in use. When an application needs memory, if there is not enough free memory can be used, the kernel buffer and recovered from the cache memory to satisfy the request of the application. So from the perspective of the application for, available = free + buffer + cache. Please note, this is a very ideal method of calculation, the actual data tend to have large errors.

However, the above argument why the available output is 0 then? See the instructions of the official documentation

The -a switch shows the available memory (if supported by the running kernel and enabled with sysctl -w vm.meminfo_legacy_layout=0 ; shows zero when unsupported or disabled). The produced output is wider than 80 characters.

This output parameter requires operating system kernel support, if the kernel does not support it on a fixed output 0.

Swap space (swap space) #

swap space is an area on the disk, may be a partition, it can be a file. Therefore, the specific implementation can be swap partitions can be swap file. When the system is tight physical memory (so-called tight, it should refer when released and Buffer Cache memory, the memory is still not enough ~), Linux will save the data in memory infrequently accessed to the swap, so that the system will have more more physical memory for each process service, and when the system needs to access content stored on the swap, and then load the data on the swap into memory, it is often said that swapped out and swapped. Swap space can be alleviated to some extent out of memory, but it needs to read and write disk data, so performance is not very high.

Now the machines are generally not very short memory, or if the system uses a default swap is not a drag on the performance of the system? Theoretically yes, but in fact the likelihood is not great. And a parameter called the kernel provides swappiness for the degree of urgency of the need to configure the memory not used to move the data in the swap. This parameter ranges from 0 to 100, 0 to tell the kernel memory as much as possible not to move the data to the swap, that is only in compelling circumstances to do so, but to tell the kernel 100 as long as possible, the memory infrequently accessed data is moved to the swap. In ubuntu system, the default value is 60 swappiness. If we felt enough memory, you can set swappiness in the /etc/sysctl.conf file:

Copy
vm.swappiness=10

If memory system, it is necessary to set the size of the swap space according to the size of physical memory.

Guess you like

Origin www.cnblogs.com/itps/p/12334216.html