Cache memory Memory for Linux (summary) __linux

Source: Internet
Author: User

A friend asked me the other day why my Linux system didn't run many programs and showed so little 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 are no programs running, but using the top or free commands to see that the available memory is very small, when you view 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 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 conditions used by the system in a global perspective:
total--Total Physical Memory
used--has used memory, this value will be larger in general, because this value includes the memory used by the cache+ application
free--memory that is completely unused
shared--Application Shared Memory
buffers--cache, mainly used in the directory, Inode value, etc. (LS Large directory can see this value increase)
cached--cache, for open files
Summarize:
Total=used+free
Used=buffers+cached (maybe add shared also)

The second line describes the application's memory usage:
The previous value represents the memory size used by the-buffers/cache--application, used minus the cached value
The latter value represents the amount of memory that +buffers/cache--can use for the application, free plus the cached value
Summarize:
-buffers/cache=used-buffers-cached
+buffers/cache=free+buffers+cached

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

What is cache Memory (cached memory):

When you read and write files, the Linux kernel in order to improve read and write performance and speed, the file will be cached in memory, this part of memory is the cache Memory (cached memory). The Cache memory will not be released automatically even after your program is finished running. This can cause you to read and write files frequently in Linux systems, and you will find that there are few physical memory available.

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

How to release cache Memory (cached 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 that it is best to sync before releasing to prevent loss of data.

Summary: Personal experience that there is no need to manually release, this memory management is one of the better than win place. Because Linux kernel memory management mechanism, generally do not need to deliberately release the cache already used. These cache content can improve file and disk read and write speed.

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.