Grammar free (options)
1. Command format:
free [parameters]
2. Command function:
The free command displays the system's use and idle memory, including physical memory, interactive area memory (swap), and kernel buffer memory. Shared memory will be ignored
3. Command parameters:
-B Displays memory usage in byte.
-K displays memory usage in kilobytes.
-m displays memory usage in MB.
-G displays memory usage in GB.
-O does not display buffer throttling columns.
-s< interval seconds > Continuous observation of memory usage.
-T displays the memory sum column.
-V Displays version information.
Above 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] = 790920 fo[3][2] = 55000
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:
-790920KB (the default unit of free is KB) physical memory, that is, fo[2][1];
-93200KB (i.e. fo[2][2]) is used in these physical memory;
-also 697720KB (i.e. Mem/free) is available;
Men:tootal=used+free
Mem/shared: The memory that is shared by several processes 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).
Mem/buffers: Represents memory that is occupied by OS buffer. Mem/cached 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 buffer is something that has not been "written" to disk.) )
A cache is something that has been "read" to the disk and stored for later use. (Caching is something "read" from disk and stored for later usage.) )
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:
1. Release the data occupied by the system cache;
Echo 3>/proc/sys/vm/drop_caches
2. Read a large document and record the time;
3. Closure of the document;
4. 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], the-buffers/cache, represents how much memory an application thinks the system is being consumed;
For Fo[3][3], the +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.