Linux free command explanation (Popular Science)

Source: Internet
Author: User

In Linux, the free command is commonly used. Do you know the meaning of all rows output by free and the relationship between them?

[Root @ localhost ~] # Free
Total used free shared buffers cached
Mem: 4038116 4010292 27824 0 205228 1343276
-/+ Buffers/cache: 2461788 1576328
Swap: 8289500 254076 8035424

The first line:
Total physical memory: 4038116
Used memory used: 4010292
Free idle memory: 27824
Shared is no longer used. It is always 0.
Buffers: buffer cache memory: 205228
Cached (page cache memory): 1343276

Link: Total = used + free

Row 2:
-/+ Buffers/cache means:
-Buffers/cache memory: 2461788 (equivalent to 1st rows of used-Buffers-cached), which is actually the memory used by the application.
+ Buffers/cache memory: 1576328 (equal to 1st rows free + buffers + cached), which is the remaining memory for the application.

It can be seen that-Buffers/cache reflects the memory actually eaten by the program, while + buffers/cache reflects the total number of memories that can be used.
For the operating system, buffers/cached are both used, so it is considered that free is only 27824.
For applications (-/+ buffers/cach ). buffers/cached is equivalent to available, because buffer/cached is used to improve the performance of program execution. When the program uses memory, buffer/cached will be quickly used.

The third line is the swap partition swap, which lists used and idle swap.

So what is the difference between buffers and cached?
In order to improve disk access efficiency, Linux has made some careful designs, in addition to caching dentry (for VFS, accelerating the conversion of file path names to inode ), two major cache methods are also adopted: 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 effectively shorten the time for I/O system calls (such as read, write, getdents.
Disk operations include logical level (File System) and physical level (Disk block). These two types of cache are logical and physical level data respectively.
The page cache is actually for the file system, and is the File Cache. Data at the file level is cached in the page cache. The logic layer of the file needs to be mapped to the actual physical disk. This ing relationship is completed by the file system. When the page cache data needs to be refreshed, the data in the page cache is handed over to the buffer cache, because the buffer cache is the cache disk block. However, this kind of processing becomes simple after the kernel version 2.6, and there is no real cache operation.
Buffer cache is the cache for disk blocks, that is, if no file system is available, data directly operated on the disk will be cached in the buffer cache. For example, the metadata of the file system is cached in the 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, operations on the file will cache the data to the page cache. If you directly use dd or other tools to read and write the disk, the data will be cached to the buffer cache.

Therefore, in Linux, as long as the swap space of swap is not used, we don't have to worry about having too little memory. if many swap instances are used, you may need to add physical memory. this is also the Standard for Linux to check whether the memory is sufficient.
If it is an application server, it generally only looks at the second row, + buffers/cache, that is, the free memory for the application is too small, it is also necessary to consider the optimization program or add memory.

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.