Free command and buffer and cache differences
The free command displays the idle, used physical memory and swap memory in the Linux system, and the buffer used by the kernel. In Linux system monitoring tools, the free command is one of the most frequently used commands.
1. command format:
free [parameters]
2. Command function:
The free command displays system usage and idle memory conditions, including physical memory, interactive area memory (swap), and kernel buffer memory. Shared memory will be ignored
3. Command parameters:
-B Displays memory usage in bytes.
-K displays memory usage in kilobytes.
-m displays memory usage in megabytes.
-G displays memory usage in gigabytes.
-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.
4. usage Examples:
Example 1: Show memory usage
Command:
Free
Free-g
Free - m
Output:
[[email protected] service]# free total used free shared buffers cachedmem: 32940112 30841684 2098428 0 4545340 11363424-/+ buffers/cache: 14932920 18007192Swap: 32764556 1944984 30819572
[[email protected] service]# free -g total used free shared buffers cachedMem: 31 29 2 0 4 10-/+ buffers/cache: 14 17Swap: 31 1 29
[[email protected] service]# free -m total used free shared buffers cachedMem: 32168 30119 2048 0 4438 11097-/+ buffers/cache: 14583 17584Swap: 31996 1899 30097
Description
Here is an explanation of these values:
Total: The amount of physical memory.
Used: How large is used.
Free: How much is available.
Shared: The total amount of memory shared by multiple processes.
Buffers/cached: The size of the disk cache.
Third line (-/+ buffers/cached):
Used: How large is used.
Free: How much is available.
Line four is swap partition swap, which is what we usually call virtual memory.
Difference: The used/free of the second line (MEM) differs from the third row (-/+ Buffers/cache) used/free. The difference between the two is that the first line is from the OS point of view, because for the os,buffers/cached are all belong to be used, so his available memory is 2098428KB, the used memory is 30841684KB, which includes, the kernel (OS) uses + Application (X, ORACLE,ETC) uses the +buffers+cached.
The third line refers to the application from the point of view, buffers/cached is equal to the availability of the application, because buffer/cached is to improve the performance of the file read, when the application needs to use memory, buffer/cached will be quickly recycled.
So from the application's point of view, available memory = System Free memory+buffers+cached.
If the available memory for this machine condition is:
18007156=2098428kb+4545340kb+11363424kb
Next, explain when the memory will be exchanged, and by what side.
When the available memory is less than the rated value, a meeting is exchanged. How to see the rating:
Command:
Cat/proc/meminfo
Output:
[[email protected] service]# cat /proc/meminfomemtotal: 32940112 kbmemfree: 2096700 kbbuffers: 4545340 kBCached: 11364056 kbswapcached: 1896080 kbactive: 22739776 kBInactive: 7427836 kBHighTotal: 0 kBHighFree: 0 kBLowTotal: 32940112 kBLowFree: 2096700 kBSwapTotal: 32764556 kBSwapFree: 30819572 kBDirty: 164 kbwriteback: 0 kbanonpages: 14153592 kbmapped: 20748 kbslab: 590232 kBPageTables: 34200 kBNFS_Unstable: 0 kBBounce: 0 kBCommitLimit: 49234612 kbcommitted_as: 23247544 kbvmalloctotal: 34359738367 kbvmallocused: 278840 kBVmallocChunk: 34359459371 kBHugePages_Total: 0HugePages_Free: 0HugePages_Rsvd: 0hugepagesize: 2048 kb
The exchange will reduce the number of physical pages used in the system in three ways:
1. Reduce the buffer and the size of the page cache,
2. Swap out the memory page of the System V type
3. Swap out or discard the page. (Application occupies a memory page, that is, insufficient physical memory).
In fact, a small amount of swap use does not affect the performance of the system.
That buffers and cached are caches, what's the difference between them?
In order to improve disk access efficiency, Linux has done some careful design, in addition to the Dentry cache (for VFS, speed up the file path name to Inode conversion), but also adopted two main cache mode: Buffer cache and Page cache. The former is for the disk block read and write, the latter for the file inode read and write. These caches effectively shorten the time for I/O system calls (such as read,write,getdents).
The operations of a disk are logical (file system) and physical (disk blocks), which are caches of logical and physical-level data, respectively.
The page cache is actually for the file system, the file cache, and the data at the file level is cached to page cache. The logical layer of the file needs to be mapped to the actual physical disk, and this mapping is done by the file system. When the page cache data needs to be refreshed, the data in the page cache is given to buffer cache because the buffer cache is the cached disk block. But this kind of processing after the 2.6 version of the kernel has become very simple, there is no real sense of the cache operation.
Buffer cache is a caching of disk blocks that, in the absence of a filesystem, caches data directly into the buffer cache, for example, the file system's metadata is cached in buffer cache.
In short, page cache is used to cache file data, and buffer cache is used to cache disk data. In the case of a file system, the data is cached to the page cache, and if the disk is read and written directly using tools such as DD, the data is cached to buffer cache.
So we look at Linux, as long as no swap swap space, there is no need to worry about their memory too little. If you use a lot of swap, you might want to consider adding physical memory. This is also the standard for Linux to see if the memory is adequate.
In the case of an application server, the general only looks at the second line, +buffers/cache, which is too little memory for the application, and it is time to consider optimizing the program or adding memory.
Example 2: Displaying memory usage information as a sum
Command:
free-t
output:
[[email protected] desktop]# free -t total used free shared buffers cachedMem: 3140564 556484 2584080 3260 75600 186256-/+ buffers/cache: 294628 2845936swap: 2031612 0 2031612Total: 5172176 556484 4615692
Description
Example 3: Periodic query Memory usage information
Command:
Free-s 10
Output:
[Email protected] desktop]# free-t total used free shared buffers Cachedmem: 3140564 557352 2583212 3164 75384 186156-/+ buffers/cache:295812 2844752swap:2031612 0 2031612total:5172176 557352 4614824
Description
Execute one command per 10s
This article is from the "Liang blog" blog, make sure to keep this source http://7038006.blog.51cto.com/7028006/1829027
Free command and buffer and cache differences