Linux Cache Memory Caches detailed

Source: Internet
Author: User

Http://www.ha97.com/4337.html

PS: The day before yesterday, children's shoes asked me, why my Linux system is not running how many programs, showing less available memory? In fact, Linux and win memory management is different, will try to cache memory to improve read and write performance, usually called cache memory.

Sometimes you will find that there is no program running, but using the top or the free command to see the available memory is very small, when viewing the system's/proc/meminfo file, you will find a Cached memory:

Enter Cat/proc/meminfo view:

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

Description of the various memory metrics 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 state used by the system in a global perspective:
total--Total Physical Memory
used--already uses memory, this value is generally larger because this value includes the memory used by the cache+ application
free--memory that is not fully used
shared--Application Shared Memory
buffers--cache, mainly used for directory aspects, Inode value, etc. (LS Large directory can see this value increase)
cached--cache, for files that have been opened
Summarize:
Total=used+free
Used=buffers+cached (maybe add shared also)

The second line describes the memory usage of the application:
The previous value indicates the memory size used by the-buffers/cache--application, used minus the cached value
The latter value indicates the amount of memory +buffers/cache--all available to the application, free plus the cached value
Summarize:
-buffers/cache=used-buffers-cached
+buffers/cache=free+buffers+cached

The third line represents the use of swap:
used--already in use
free--not used

What is cache memory (cached RAM):

When you read and write files, the Linux kernel caches the files in memory in order to improve read and write performance and speed, which is the memory (cache memory). The Cache memory will not be released automatically even after your program has finished running. This will cause you to read and write files frequently in your Linux system, and you will find that there is little physical memory available.

In fact, this cache memory is automatically released when you need to use memory, so you don't have to worry about not having memory available. If you want to release the cache memory manually, there is a way.

How to release the cache memory (cached RAM):

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 that it is best to sync before releasing to prevent data loss.

Summary: Personal experience that there is no need to manually release, this memory management method is also better than win one of the places! Because of the kernel memory management mechanism of Linux, it is generally not necessary to deliberately release the cache that is already in use. These cache contents can improve the read and write speed of files and disks.

Linux Cache Memory Caches detailed

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.