Memory Management for Linux

Source: Internet
Author: User

Linux memory management, in fact, and Windows memory management has a very similar place, are using the concept of virtual memory, said here have to scold MS, why in many times there is a lot of physical memory, but still use the pagefile. So often to argue with a bunch of people say the size of the pagefile, and how to assign this problem, in Linux we do not have to fight what swap size problem, I personally think, swap set a 512M is enough, if you ask that 512M swap is not enough to do? Can only say eldest brother you still add memory bar, or check your application, is not really appear memory leak.
The night is also deep, no longer talk nonsense.

View memory under Linux We generally use command free
[[email protected] ~]# free
Total used free shared buffers Cached
mem:386024 377116 8908 0 21280 155468
-/+ buffers/cache:200368 185656
swap:393552 0 393552
Here is an explanation of these values:
Second line (MEM):
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.
There is not much to explain in line four.
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 8908KB, the used memory is 377116KB, which includes, the kernel (OS) uses + The +buffers+cached used by Application (X,ORACLE,ETC).
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.
As in the above example:
185656=8908+21280+155468
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 look at the rated value (RHEL4.0):
#cat/proc/meminfo
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 usage does not affect system performance.

Note: Why used is so high in Linux systems

This is related to the principles of Linux system memory management: Use Cache+buffer as much as possible and reduce the use of swap partitions to improve performance.

For example, read a file from disk, when the kernel found the first time the file read, the data will be placed in the cache, then the process from the cache read, when the process to access the data just now, the kernel read directly from the cache, and no longer access the disk. Not as much as the copy of our large files, the kernel is through the file cache (Page Cache->buffer cache) to operate, while processing the file, the kernel VM in memory for each page when reading the file (4K) to establish the corresponding page Cache linked list ,

Cache usage increases the virtual memory hit rate, which improves system performance. Therefore, after the system has been running for a period of time, the memory is cached occupied, used naturally increased. If you want to release cached, you can use the following methods:

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

Memory usage

In the system monitoring, the system memory consumption is often monitored, the purpose is to avoid the system because in the dynamic allocation of memory because the actual memory is not enough to use swap space, the use of swap space will use system performance degradation, system instability.

In a Linux system, the system memory footprint can be calculated using the free command:

/home/jcxia> Free

Total used free shared buffers Cached

mem:24672800 17895600 6777200 0 232996 14706928

-/+ buffers/cache:2955676 21717124

swap:21727904 0 21727904

which

Total-refers to the size of the system's physical memory

used-The amount of physical memory already in use

Free-Idle physical memory size

buffers-The amount of physical memory consumed by the file system cache, which is the memory used to write the data to the physical disk.

cached-the physical memory occupied by the file system cache, which is the memory used to read from the physical disk for later use.

In the real system, the file system cache can consume a lot of physical memory, and when computing the physical memory idle rate underLinux , buffers and cached memory are usually treated as memory that can be used. That is, the actual system memory occupancy rate calculation:

(total– (free + buffer + cached)) * 100/total

Memory Management for Linux

Related Article

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.