Let's start with the Free command.
Free
Compared with top, the free command provides a more concise view of the system memory usage:
$ Free
Total used free shared buffers cachedMem: 255268 238332 16936 85540 0 126384-/+ buffers/cache: 26408 228860 265000 Swap: 265000 0
Mem: physical memory statistics
-/+ Buffers/cached: indicates the cache statistics of physical memory.
Swap: indicates the usage of Swap partitions on the hard disk.
Total physical memory of the system: 255268Kb256M), but the actually available memory B of the system is not the first line of free labeled 16936Kb, it only indicates the unallocated memory.
We use names such as total1, used1, free1, used2, and free2 to represent the values of the preceding statistics. 1 and 2 represent the data of the first and second rows respectively.
Total1: total physical memory.
Used1: indicates the total quantity allocated to the cache including buffers and cache. However, some of the caches are not actually used.
Free1: unallocated memory.
Shared1: shared memory, which is not used by the general system and is not discussed here.
Buffers1: Number of buffers allocated by the system but not used.
Cached1: Number of cache allocated by the system but not used. The difference between buffer and cache is described later.
Used2: the total amount of actually used buffers and cache, which is also the total amount of actually used memory.
Free2: The sum of unused buffers, cache, and unallocated memory, which is the actual available memory of the system.
The following equations can be sorted out:
Total1 = used1 + free1total1 = used2 + free2used1 = buffers1 + cached1 + used2free2 = buffers1 + cached1 + free1
Difference between buffer and cache
A 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.
For more details, see Difference Between Buffer and Cache.
Shared memory) is mainly used to share data between different processes in a UNIX environment. It is a method for inter-process communication. Generally, applications do not apply to use Shared memory, I have not verified the effect of shared memory on the above equation. If you are interested, see: What is Shared Memory?
Differences between cache and buffer:
Cache: high-speed Cache is a memory with a small capacity but high speed located between the CPU and the main memory.Because the CPU speed is much higher than the master memory, it takes a certain period of time for the CPU to directly access data from the memory. The Cache stores part of the data that has just been used by the CPU or is used cyclically, when the CPU uses this part of data again, it can be called directly from the Cache, which reduces the CPU wait time and improves the system efficiency. Cache is divided into Level 1 Cache (L1 Cache) and level 2 Cache (L2 Cache). L1 Cache is integrated into the CPU, and L2 Cache is usually soldered to the motherboard in the early stages, it is also integrated into the CPU. The common capacity is 256KB or 512KB L2 Cache.
Buffer: a Buffer used to transmit data between devices with Different Storage speeds or between devices with different priorities.Through the buffer zone, mutual waits between processes can be reduced, so that when reading data from a slow device, the operation process of the fast device will not interrupt.
Buffer and cache in Free: they both occupy memory ):
Buffer: the memory used as the buffer cache. It is the read/write buffer of Block devices.
Cache: Memory Used as the page cache, the cache of the file system
If the cache value is large, the number of files in the cache is large. If files frequently accessed can be cached, the disk read IO is very small.
Related Articles]
- How to adjust Buffer Credits
- Configuration of Apache Proxy and Cache in Linux
- Cache query tool Jofti 2 beta2 released