Linux memory usage experience

Source: Internet
Author: User
Article Title: Linux operating system memory usage experience. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Linux memory management is similar to Windows Memory Management. It uses virtual memory. But why does Pagefile still be used when Windows still has a large amount of physical memory? So we often have to argue with a group of people about the size of Pagefile and how to allocate it, in Linux, there is no need to argue about the SWAP size. a m swap is generally enough. If it is small, you can consider adding a block of memory, check whether your application has a memory leak.

In Linux, we usually use command free to view memory.

  

[root@nonamelinux ~]# freetotal used free shared buffers cachedMem: 386024 377116 8908 0 21280 155468-/+ buffers/cache: 200368 185656Swap: 393552 0 393552   

The following is an explanation of these values:

Row 2 (mem ):

Total: total physical memory size.

Used: used.

Free: available.

Shared: The total memory Shared by multiple processes.

Buffers/cached: disk cache size.

Row 3 (-/+ buffers/cached ):

Used: used.

Free: available.

The fourth line won't be explained much.

Differences:

The difference between used/free of the second row (mem) and used/free of the third row (-/+ buffers/cache.

The difference between the two is that from the usage perspective, the second line is from the OS perspective, because for OS, buffers/cached is used, so its available memory is 8908KB, the used memory is kb, including the + buffers + cached used by the kernel (OS) + Application (X, oracle, etc.

The third line indicates that, from the application perspective, for applications, buffers/cached is equivalent to available, because buffer/cached is designed to improve file read performance, when the application needs to use the memory again, the buffer/cached will be quickly recycled.

From the application perspective, the available memory = system free memory + buffers + cached.

For example:

185656 = 8908 + 21280 + 155468

Next we will explain when the memory will be exchanged and how it will be exchanged.

When the available memory is less than the rated value, the swap starts.

Rating (RHEL4.0 ):

# Cat/proc/meminfo

Switching reduces the number of physical pages used in the system in three ways:

1. Reduce the buffer and page cache size,

2. swap out the V-type memory page of the system,

3. Swap out or discard the page. (The Memory Page occupied by the Application, that is, the physical memory is insufficient ).

In fact, using swap in a small amount affects the system performance.

The following is the difference between buffers and cached.

Buffers is the buffer size for Block devices. It only records the metadata and tracking in-flight pages of the file system.

Cached is used to buffer files.

That is to say: buffers is used for storage. What content and permissions are contained in the directory.

Cached is used directly to remember the files we opened. If you want to know whether the files take effect, you can try and execute two commands one by one # man X, you can obviously feel that the second start is much faster.

Experiment: it is obvious on a machine with no application. Remember that the experiment can only be performed once. If you want to do more, change the file name.

  

#free#man X#free#man X#free  

You can compare the size of buffers after free.

Another experiment:

  

#free#ls /dev#free 

You can compare the two sizes. Of course, this buffers is increasing at any time, but if you have used ls, the increase speed will become faster. This is the difference between buffers and chached.

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.