First, we will introduce how the memory is used in linux.
When an application needs to read and write disk data, the system reads the relevant data from the disk to the memory. If the physical memory is insufficient, some data in the memory is imported to the disk, in this way, part of the disk space is used as virtual memory, also known as Swap. If enough memory is allocated to all applications and the physical memory is still available, linux will try its best to use the idle memory to improve the overall I/O efficiency, the method is to divide the remaining memory into cache and buffer for utilization.
After the data read from the disk to the memory is read by the relevant application, if the remaining memory exists, the data will be stored in the cache for 2nd reads to avoid re-reading the disk. After an application modifies data in the memory, because the write speed to the disk is relatively low, in the case of idle memory, the data is first stored in the buffer and then written to the disk at a later time, therefore, the application can continue subsequent operations without waiting for the data to be written to the disk.
If the system requires more memory at a certain time point, the cache part will be erased, and the buffer content will be written to the disk, so that the two parts of memory will be released to the system for use, in this way, you need to read the content from the disk again.
Through the above analysis, we can know that the idle physical memory is not much, which does not necessarily indicate that the system is in poor running status, because the cache and buffer of the memory can be reused at any time. In a sense, these two parts of memory can also be viewed as additional idle memory for poetry. If swap is frequently called and bi and bo are not 0 for a long time, it is the basis for memory resource shortage.
Original article: http://jar-c.blog.163.com/blog/static/1164012502010325115534699/