The most important thing is the meaning of each parameter in the result, here the simple list is as follows:
①mem is your physical memory, such as my server is 8G, that total is: 8107;used + free = total.
Note here the understanding of used and free, used indicates the memory used by the system (not the actual memory used), free represents the remaining contents of the system
②-/+ Buffers/cache, this line can truly reflect the server memory usage
–buffers/cache represents the memory that is actually used by the program, while the + Buffers/cache represents the remaining available memory
In fact, memory in both buffers and cached can be used, and they are just caching designed to improve performance.
Buffers are buffers designed for block devices, such as disk I/O operations, and can be buffered by buffers.
Cached is cached read content, because the cache space is limited, a period of time useless cache data will be moved to the swap partition, so sometimes see a lot of physical memory, but the swap partition has been used.
As can be seen from the above description, in fact, the memory (-Buffers/cache) that is actually used by the program is removed from the used part of the mem buffers and cached, while the actual remaining memory (+ Buffers/cache) You need the MEM free plus buffers and cached.
The use of ③swap, it is relatively simple.
As can be seen from the above summary, in fact, we need to pay attention to the-/+ Buffers/cache when we check the memory usage.
Here is the result of the free run, a total of 4 lines. For the convenience of the explanation, I added the column number. This can be viewed as a two-dimensional array fo (free output). For example:
- FO[2][1] = 24677460
- FO[3][2] = 10321516
--> 1 2 3 4 5 6
1 total used free shared buffers Cached
2 mem:24677460 23276064 1401396 0 870540 12084008
3-/+ buffers/cache:10321516 14355944
4 swap:25151484 224188 24927296
Free output A total of four lines, the fourth behavior Exchange area of information, respectively, the total amount of exchange, the amount of use (used) and how many idle swap area (freed), this more clear, not too much.
The second and third lines of the free output are more confusing than others. Both of these lines describe memory usage. The first column is total, the second column is Usage (used), and the third column is available (free).
The first line of output is viewed from the operating system (OS). That is, from an OS point of view, there is a common computer:
- 24677460KB(the default unit of free is KB) physical memory, that is, fo[2][1];
- In these physical memory there are 23276064KB(i.e. fo[2][2]) are used;
- Also used 1401396KB(ie fo[2][3]) is available;
Here we get the first equation:
- FO[2][1] = fo[2][2] + fo[2][3]
FO[2][4] represents memory that is shared by several processes and is now deprecated, and its value is always 0 (of course it may not be 0 on some systems, depending on how the free command is implemented).
FO[2][5] represents memory that is in the OS buffer. FO[2][6] represents memory that has been cache by the OS. In some cases the two words buffer and cache are often mixed. But in some relatively low-level software is to distinguish these two words, look at the foreigner's Foreign Language:
- A buffer is something which has yet to be "written" to disk.
- A Cache is something this has been "read" from the disk and stored for later use.
That is, the buffer is used to store data to be output to disk (block device), and the cache is to store the data read from disk. Both are designed to improve IO performance and are managed by the OS.
Linux and other mature operating systems (such as Windows), in order to improve IO read performance, always need to cache some data, which is why Fo[2][6] (cached memory) larger, and fo[2][3] relatively small reasons. We can do a simple test:
- Releasing data that is occupied by the system cache;
Echo 3 >/ proc / SYS / VM / drop_caches
- Read a large file and record the time;
- Close the file;
- Reread the large document and record the time;
The second reading should be much faster than the first time. Originally I did a berkeleydb read operation, about to read 5G file, tens of millions of records. In my environment, the second reading is about 9 times times faster than the first time.
The second line of free output is the use of system memory from an application perspective.
- For fo[3][2], i.e.-buffers/cache, indicates how much memory an application thinks the system is being consumed;
- For fo[3][3], i.e. +buffers/cache, indicates how much memory an application thinks the system has;
Because memory occupied by the system cache and buffer can be quickly recycled, it is usually fo[3][3] much larger than fo[2][3.
Here are two more equations:
- FO[3][2] = fo[2][2]-fo[2][5]-fo[2][6]
- FO[3][3] = fo[2][3] + fo[2][5] + fo[2][6]
Neither of these is difficult to understand.
The free command is provided by PROCPS.*.RPM (on the OS of the Redhat series). All output values for the free command are read from the/proc/meminfo.
There may be a meminfo (2) function on the system, which is to parse the/proc/meminfo. Procps The package itself implements the Meminfo () function. Can download a Procps tar package look at the specific implementation, now the latest layout 3.2.8.