Original link: http://os.51cto.com/art/200709/56603.htm
Let's start with the free order.
Free
The free command provides a more concise view of system memory usage relative to top:
$ free
Total used free shared buffers cachedmem:255268 238332 16936 0 85540 126384-/+ buffers/cache:26408 228860swap:265000 0 265000
Mem: Indicates physical memory statistics
-/+ buffers/cached: Cache statistics representing physical memory
Swap: Indicates the usage of the swap partition on the hard disk, we don't care about it here.
Total physical memory of the system: 255268Kb (256M), but the system is currently really available memory B is not the first line of the free Mark 16936Kb, it represents only unallocated memory.
We use names such as Total1, Used1, Free1, Used2, and free2 to represent the values of the above statistics, and 1 and 2 represent the data for the first row and the second row respectively.
Total1: Represents the total amount of physical memory.
Used1: Represents the amount that the total is allocated to the cache (including buffers and cache), but may not be actually used in some of the caches.
FREE1: Memory that has not been allocated.
SHARED1: Shared memory, the general system will not be used, nor discussed here.
Buffers1: The number of buffers that are allocated but not used by the system.
Cached1: The number of caches that the system allocates but has not been used. The difference between buffer and cache is shown later.
USED2: The total amount of buffers and caches actually used, as well as the amount of memory actually used.
Free2: The sum of unused buffers with the cache and unallocated memory, which is the current actual memory available to the system.
You can sort out the following equation:
Total1 = used1 + free1 total1 = used2 + free2 used1 = buffers1 + cached1 + used2 free2 = buffers1 + Cach Ed1 + free1
The difference between buffer and cache
A buffer is something that have yet to being "written" to disk. A cache is something that have been "read" from the disk and stored for later use.
For a more detailed explanation reference: difference between Buffer and Cache
For shared memory, which is primarily used to share data between different processes in a UNIX environment, is a method of interprocess communication, and the general application does not request the use of shared memory, nor does the author verify the effect of shared memory on the above equation. If you are interested, please refer to: What is Shared Memory?
The difference between cache and buffer:
Cache : Caching is a small but high-speed memory that sits between the CPU and the main memory. because the CPU speed is much higher than the main memory, the CPU accesses the data directly from memory to wait for a certain period of time, the cache holds the CPU has just used or recycled part of the data, when the CPU re-use the part of the data can be directly called from the cache, This reduces the CPU wait time and improves the efficiency of the system. The cache is also divided into one-level cache (L1 cache) and level two cache (L2 cache), L1 cache is integrated within the CPU, L2 cache is usually soldered to the motherboard, and is now integrated into the CPU, with a common capacity of 256KB or 512KB L2 Cache.
Buffer: An area where data is transferred between devices that are not synchronized or that have different priority levels. through buffers, you can reduce the number of waits between processes, so that when you read data from a slow device, the operating process of a fast device is uninterrupted.
Buffer and cache in free: (They are all memory-intensive):
Buffer: Memory as buffer cache, which is the read and write buffer of the block device
Cache: As the page cache memory, the file system cache
If the cache has a large value, it indicates that the cache has a high number of files. If frequently accessed files can be cache, then the disk read IO must be very small.
The difference between memory buffer and cache in Linux operating system--from the free command (GO)