Linux free command details

Source: Internet
Author: User
The free command is provided by procps. *. rpm (on the OS of the Redhat series ). All the output values of the free command are explained from/proc/me about the output of the free command on Linux.
The following is the free running result. There are 4 rows in total. For convenience, we add the column number. In this way, we can regard the free Output as a two-dimensional array FO (Free Output ). For example:
? FO [2] [1] = 999212
? FO [3] [2] = 305404
1 2 3 4 5 6
1 total used free shared buffers cached
2 Mem: 999212 967476 31736 0 50668 223000
3-/+ buffers/cache: 693808 305404
4 Swap: 2048276 154524 1893752
Copy code
There are four rows of free output, and the information in the fourth behavior swap zone is the total number of exchanges (total), the used amount (used), and the number of idle swap zones (free). This is clear, not to mention too much.
The second and third rows of free output locations are confusing. Both of these lines describe the memory usage. The first column is "free", the second column is "free", and the third column is "free ). The output in the first line is from the operating system (OS. In other words, from the OS perspective, there are a total of computers:
? 999212KB (unit: KB) physical memory, I .e., FO [2] [1];
? 967476KB (I .e. FO [2] [2]) in these physical memory is used;
? 31736KB (FO [2] [3]) is also available;
Here we get the first equation:
? FO [2] [1] = FO [2] [2] + FO [2] [3]
FO [2] [4] indicates the memory shared by several processes. The value of deprecated is always 0 (of course, it may not be 0 on some systems, depends on how the free command is implemented ).
FO [2] [5] indicates the memory occupied by the OS buffer. FO [2] [6] indicates the memory cached by the OS. In some cases, the buffer and cache terms are often mixed. However, in some lower-layer software, we need to distinguish these two words. look at the Foreign Languages of foreigners:
? 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.
That is to say, the buffer is used to store the data to be output to the disk (block device), while the cache is used to store the data read from the disk. These two are designed to improve IO performance and are managed by the OS.
Linux and other mature operating systems (such as windows) always need to cache more data to improve IO read performance, this is why FO [2] [6] (cached memory) is large, while FO [2] [3] is small. We can perform a simple test:
1. release the data occupied by the system cache;
Echo 3>/proc/sys/vm/drop_caches
2. read a large file and record the time;
3. close the file;
4. repeat the large file and record the time;
The second read should be much faster than the first one. I used to perform a read operation on the BerkeleyDB, which roughly reads 5 GB of files and tens of millions of records. In my environment, the second read is about 9 times faster than the first read.
The second line of free output shows the system memory usage from the perspective of an application.
? For FO [3] [2], that is,-buffers/cache, it indicates how much memory an application deems the system to be used;
? For FO [3] [3], that is, + buffers/cache, it indicates the amount of memory that an application thinks the system has;
Because the memory occupied by system cache and buffer can be quickly recycled, FO [3] [3] is much larger than FO [2] [3.
Two equations are also used here:
? FO [3] [2] = FO [2] [2]-FO [2] [5]-FO [2] [6]
? FO [3] [3] = FO [2] [3] + FO [2] [5] + FO [2] [6]
Both of them are hard to understand.
The free command is provided by procps. *. rpm (on the OS of the Redhat series ). All output values of the free command are read from/proc/meminfo.
In the system, meminfo (2) can be used to parse/proc/meminfo. The procps package implements the meminfo () function. You can download a tar package of procps to see the specific implementation. The latest version is 3.2.8.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.