linux memory

free -m

             total       used       free     shared    buffers     cached

Mem:   15947      15707        240          0        473       2034

-/+ buffers/cache:  13200       2747

 

Swap:         8191        274       7917

 Mem: Indicates physical memory statistics 

-/+ buffers/cached: Indicates the cache statistics of physical memory 
Swap: Indicates the usage of the swap partition on the hard disk, we don't care here.
The total physical memory of the system: 255988Kb (256M), but the currently available memory of the system is not the 24284Kb marked by the first line of free, it only represents the unallocated memory.

We use names such as total1, used1, free1, used2, free2 to represent the values ​​of the above statistics, and 1 and 2 represent the data in the first and second rows, respectively.

total1: Indicates the total amount of physical memory. 
used1: Indicates the total amount allocated to the cache (including buffers and cache  ), but some of the cache may not be actually used. 
free1: Unallocated memory. 
shared1: Shared memory, which is generally not used by the system, and will not be discussed here. 
buffers1: The number of buffers allocated by the system but not in use. 
cached1: The number of caches allocated by the system but not in use  . The difference between buffer  and cache  is described later. 
used2: The total amount of buffers and caches  actually used, and also the total amount of memory actually used. 
free2: The sum of unused buffers, cache  and unallocated memory, which is the actual available memory of the system.


The following equation can be sorted out:

total1 = used1 + free1

total1 = used2 + free2

used1 = buffers1 + cached1 + used2 = 473+2034+ 13200=15707

free2 = buffers1 + cached1 + free1 =473+2043+240=2747 (real available memory)

buffer 与cache 的区别
buffer  is something that has yet to be "written" to disk. A  cache  is something that has been "read" from the disk and stored for later use.
 
Both are data in RAM. Simply put, the buffer is about to be written to the disk, and the cache is read from the disk.
A buffer is an area used to store data transferred between devices with different speeds or with different priorities. Buffers are designed according to the read and write of the disk, and the scattered write operations are centralized to reduce disk fragmentation and repeated hard disk seeks, thereby improving system performance.
Cache is often used for disk I/O requests. If multiple processes need to access a file, the file is made into a cache to facilitate the next access, which can improve system performance. The cache (cached) is to save the read data. If it hits (find the required data) when re-reading, don't read the hard disk. If it doesn't hit, read the hard disk. The data will be organized according to the reading frequency, the most frequently read content will be placed in the easiest place to find, and the content that is no longer read will continue to be placed in the back until it is deleted.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326353171&siteId=291194637