Linux cache memory Parsing

Source: Internet
Author: User

PS: I was asked the day before yesterday, why is there so little memory available in my Linux system? In fact, different from Windows Memory Management, Linux will try to cache memory to improve read/write performance, usually called cache memory.

Sometimes you will find that no program is running, but using the top or free command, you can see that there are few items available in memory free. In this case, you can view the/proc/meminfo file of the system, cached memory:

Enter CAT/proc/meminfo to View Details:

Memtotal: 16425996 KB
Memfree: 5698808 KB
Buffers': 380904 KB
Cached: 9389356 KB
Swapcached: 212 KB
Active: 6569200 KB
Inactive: 3725364 KB
Hightotal: 0 KB
Highfree: 0 KB
Lowtotal: 16425996 KB
Lowfree: 5698808 KB
Swaptotal: 8273464 KB
Swapfree: 8273252 KB
Dirty: 980 KB
Writeback: 0 KB
Anonpages: 524108 KB
Mapped: 24568 KB
Slab: 381776 KB
Pagetables: 7496 KB
Nfs_unstable: 0 KB
Bounce: 0 KB
Commitlimit: 16486460 KB
Committed_as: 2143856 KB
Vmalloctotal: 34359738367 KB
Vmallocused: 267656 KB
Vmallocchunk: 34359469303 KB
Hugepages_total: 0
Hugepages_free: 0
Hugepages_rsvd: 0
Hugepagesize: 2048 KB

Memory indicators in the free command:

Total used free shared buffers cached
Mem: 16425996 10727220 5698776 0 380904 9389832
-/+ Buffers/cache: 956484 15469512
Swap: 8273464 212 8273252

The first line describes the memory usage of the system from a global perspective:
Total -- total physical memory
Used -- memory used. Generally, this value is relatively large because it includes the memory used by the cache + application.
Free -- completely unused memory
Shared-application shared memory
Buffers -- cache, mainly used for directories and inode values (this value can be seen in large ls Directories)
Cached-Cache for opened files
Summary:
Total = used + free
Used = buffers + cached (maybe add shared also)

The second line describes the memory usage of the application:
The previous value indicates-Buffers/cache-the memory size used by the application, and used minus the cache Value
The last value indicates + buffers/cache-all memory sizes available for the application, free and cache values
Summary:
-Buffers/cache = used-Buffers-cached
+ Buffers/cache = free + buffers + cached

The third line indicates the usage of swap:
Used -- used
Free -- unused

What is cache memory ):

When you read and write files, the Linux kernel caches the files in the memory to improve the Read and Write Performance and speed. This part of the memory is cache memory ). The cache memory will not be automatically released even after your program runs. This will cause your program to read and write files frequently in Linux, and you will find that there is very little available physical memory.

In fact, this cache memory will be automatically released when you need to use the memory, so you do not have to worry about no memory available. You can also manually release the cache memory.

How to release cache memory ):

Use the following command to release the cache memory:

To free pagecache:
Echo 1>/proc/sys/Vm/drop_caches
To free dentries and inodes:
Echo 2>/proc/sys/Vm/drop_caches
To free pagecache, dentries and inodes:
Echo 3>/proc/sys/Vm/drop_caches

Note: It is best to sync before release to prevent data loss.

Conclusion: In my personal experience, there is no need to manually release the memory. This memory management method is also one of the advantages over win! Because of the Linux kernel memory management mechanism, you generally do not need to release the used cache. The cached content can speed up reading and writing files and disks.

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.