Correctly Understand the high memory usage in Linux

Source: Internet
Author: User

Most of them may use top to check the current memory usage. I have a question: why is the memory usage too short when I start the machine or basically no program is enabled?

This result is often given, and the memory usage is suspected to be 90%:
Mem: 4146788 k total, 3825536 K used, 321252 K free, 213488 K Buffers
Swap: 2650684 k total, 80 K used, 2650604 K free, 3006404 K cached

This suspicion is common because many people are familiar with windows. In Windows, you can use the task manager to view the memory consumption of the current process. In my opinion, Windows physical memory always leaves a certain amount of space. Even if the physical memory is idle at this time, some programs will use the virtual memory to start new programs in windows, allocate idle physical memory directly, so that the new program can start quickly, but not Linux.

In Linux, use the top command to view memory usage:

Mem: 4146788 k total, 3825536 K used, 321252 K free, 213488 K Buffers
Swap: 2650684 k total, 80 K used, 2650604 K free, 3006404 K cached

Here the result shows that the 90% GB used is used, and the usage reaches. You can also compare the free results:
$ Free-m
Total used free shared buffers cached
Mem: 4049 3784 265 0 208 2939
-/+ Buffers/cache: 636 3413
Swap: 2588 0 2588

Although mem displays used of about 636 GB, but (-/+ buffers/cache) minus buffers and cache, we can see that the actual memory occupied by the current process is MB, the available free memory is 3.4 GB.

It can be understood that in the memory allocation mechanism of Linux, the physical memory is preferentially used. When the physical memory is idle (enough), the occupied memory is not released, even if the program that occupies the memory has been disabled, the memory occupied by the program is used for Cache Usage. It is faster for the program that has been enabled or to read the data that has just been accessed.

In the preceding example, 4 GB memory is used, and GB memory is occupied. However, the buuffer and cached parts are used as cache, And the hit rate can be used to improve the efficiency, in addition, this part of cache can be released at any time according to commands. We can think that this part of memory is not actually used, or that it is idle.

ThereforeView the memory currently in use by the process, which is used-(buffers + cache)You can also think that if swap is not used in large quantities, Mem is enough. Swap is used only when mem is actually occupied by the current process (without buffers and cache.

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.