Linux Command free detailed explanation from: houfeng http://qa.taobao.com/blogs/qa? Bid = 2265
Some time ago, a project was written in C, and memory leakage was found during performance tests. Free is a useful command for observing memory usage.
Bash-3.00 $ free
Total used free shared buffers cached
Mem: 1572988 1509260 63728 0 62800 277888
-/+ Buffers/cache: 1168572 404416
Swap: 2096472 16628 2079844
Mem: physical memory statistics
-/+ Buffers/cached: indicates the cache statistics of physical memory.
Swap: indicates the usage of swap partitions on the hard disk.
The total physical memory of the system is 255268kb (256 MB), but the actually available memory B of the system is not 16936kb In the first line, which only indicates the unallocated memory.
Row 3 mem: Total: total physical memory.
Used: indicates the total quantity allocated to the cache (including buffers and cache), but some of the caches are not actually used.
Free: unallocated memory.
Shared: shared memory, which is generally not used by the system and will not be discussed here.
Buffers: Number of buffers allocated by the system but not used.
Cached: Number of cache allocated by the system but not used. The difference between buffer and cache is described later.Total = used + freeRow 3-/+ buffers/cached: Used: Used-Buffers-cached in the first line is also the total memory used.
Free: The sum of unused buffers, cache, and unallocated memory. This is the actual available memory of the system.Free 2 = buffers1 + cached1 + free1 // free2 indicates the second row, and buffers1 indicates the first row.
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 Row 3: The third row refersSlave ApplicationProgramFor applications, buffers/cached
Yes, because buffer/cached is used to improve file read performance. When the application needs to use the memory, buffer/cached will be quickly recycled.
From the application perspective, the available memory = system free memory + buffers + cached.
Next, we will explain when the memory will be exchanged and by which side.
When the available memory is less than the rated value, a meeting will be held for exchange.
Rating (rhel4.0 ):
# Cat/proc/meminfo
Switching reduces the number of physical pages used in the system in three ways:
1. Reduce the buffer and page cache size,
2. swap out the V-type memory page of the system,
3. Swap out or discard the page. (The Memory Page occupied by the application, that is, the physical memory is insufficient ).
In fact, using swap in a small amount affects the system performance.
The following is the difference between buffers and cached.
Buffers is the buffer size for Block devices. It only records the metadata and tracking in-flight pages of the file system.
Cached is used to buffer files.
That is to say: buffers is used for storage. What content and permissions are contained in the directory.
While cached is directly used to remember the files we opened.If you want to know whether it is actually effective, you can give it a try and execute the command # Man x twice. Then you can obviously feel that the second start is much faster.
Experiment: it is obvious on a machine with no application. Remember that the experiment can only be performed once. If you want to do more, change the file name.
# Free
# Man x
# Free
# Man x
# Free
You can compare the size of buffers after free.
Another experiment:
# Free
# Ls/dev
# Free
You can compare the two sizes. Of course, the buffers are increasing at any time, but if you have ls, the increase will be faster. This is the difference between buffers and chached.
Because Linux uses the memory that you do not currently use as the file and data cache to improve system performance, the system will automatically release the memory when you need it (unlike windows, even if you have a lot of idle memory, you need to access pagefiles on the disk)
Use the free command
The value of used minus the value of buffer and cache is your current real memory usage.----- PairOperating SystemIt is the mem parameter. buffers/cached are all used, so it is considered that free only16936.
Pair Applications (-/+ Buffers/cach). buffers/cached is equivalent to available, because buffer/cached is Improved Program execution performance, When the program uses the memory, buffer/cached will be quickly used. So, let's take a look at the application, with (-/+
The free and used of buffers/cache are the main ones. So let's take a look at this. Some common sense. In order to improve disk and memory access efficiency, Linux has made a lot of careful design, in addition to caching dentry ( VFS, acceleration file path name to inode conversion), also adopted two main cache Methods: buffer cache and page cache. The former is used to read and write disk blocks, and the latter is used to read and write inode files. These caches can effectively shorten
The time when the I/O system calls (such as read, write, getdents. Remember that the memory is used, not for reference.Unlike windows, hard disk swap is required no matter how much physical memory you have File Reading. This is why Windows often prompts insufficient virtual space. You can think about how boring it is, there is still a majority In this case, a part of the hard disk space is used as the memory. How can the hard disk be faster than the memory? Space, you don't have to worry about too little memory. If swap often uses a lot, you may have to consider adding physical memory. Whether the memory is enough.
---------------
Syntax: Free [-bkmotv] [-S <interval seconds>]
Note: The free command displays the memory usage, including the physical memory, virtual swap file memory, shared memory segments, and the system core buffer.
Parameters:
-B displays memory usage in bytes.
-K displays memory usage in KB.
-MB: memory usage is displayed in MB.
-O does not display the buffer adjustment column.
-S <interval seconds> continuous observation of memory usage.
-T: displays the total memory column.
-V displays the version information.