Linux Server Memory monitoring methods

Source: Internet
Author: User
Article Title: Linux Server Memory monitoring methods. 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.

Memory is one of the most important resources managed by the Linux kernel. The memory management system is the most important part of the operating system, because the physical memory of the system is always less than the amount of memory required by the system. Virtual Memory is the strategy used to overcome this conflict. By sharing memory among processes, the system's virtual memory seems to have more memory than the actual memory. Linux supports Virtual Memory, that is, the disk is used as the RAM Extension, so that the available memory can be effectively expanded accordingly. The core stores unused memory blocks on the hard disk to free up memory for other purposes. When the original content is used again, it is read back to the memory.

 I. memory usage monitoring

(1) monitor memory usage in real time

Use the "Free" command on the command line to monitor memory usage

     
      #free             total       used       free     shared    buffers     cachedMem:        256024     192284      63740          0      10676     101004-/+ buffers/cache:      80604     175420Swap:       522072          0     522072
     

The above shows a 256 mb ram and a 512 MB swap space system. The third row of output (Mem :) displays the physical memory. The total column does not display the core physical memory (usually about 1 MB ). The used column shows the total memory used (the second row does not count as a buffer ). The free column shows all unused memory. The Shared column displays the total memory Shared by multiple processes. The Buffers column displays the current disk cache size. The information displayed on the fifth line (Swap :) is similar to the above. If the behavior is 0, no swap space is used. By default, the free command displays memory usage in kilobytes (that is, 1024 bytes. You can use the-h parameter to Display memory usage in bytes, or use the-m parameter to Display memory usage in MB. You can also use the-s parameter to continuously monitor memory usage:

# Free? B? S2

This command continuously reports memory usage in the terminal window and updates every 2 seconds.

(2) watch combination? The free command is used to monitor memory usage in Real Time:

     
      #watch -n 2 -d freeEvery 2.0s: free                                        Fri Jul 6 06:06:12 2007             total       used       free     shared    buffers     cachedMem:        233356     218616      14740          0       5560      64784-/+ buffers/cache:     148272      85084Swap:       622584       6656     615928
     

The watch command runs free once every two seconds. The screen is cleared before execution and data is displayed in the same position. Because the watch command does not scroll the screen, it is suitable for monitoring memory usage for a long time. You can use the-n option to control the execution frequency. You can also use the-d option to display commands in different places each time. The Watch command is executed until you press [Ctrl]-[C.

  Ii. concept of virtual memory

(1) Linux virtual memory Implementation Mechanism

The implementation of Linux virtual memory requires support of six mechanisms: Address ing mechanism, memory allocation and recycling mechanism, cache and refresh mechanism, request page mechanism, swap mechanism, and Memory sharing mechanism.

First, the memory manager maps the Logical Address of the user program to the physical address through the ing mechanism. When the user program runs, if the virtual address used in the program does not have the corresponding physical memory, the request page request is issued. If there is idle memory available for allocation, the request is to allocate the memory (so the memory is allocated and recycled ), and record the physical pages in use in the cache (the cache mechanism is used ). If there is not enough memory for allocation, call the swap mechanism to free up some memory. In addition, in address ing, you need to use TLB (translation back-to-back storage) to find physical pages. In the switching mechanism, the swap cache is also used, after switching the physical page content to the swap file, you must modify the page table to map the file address.

(2) virtual memory capacity setting

Someone may tell you that you should allocate 2 times the virtual memory of the physical memory, but this is an unfixed rule. If your physical storage is small, you can set it like this. If you have 1 GB physical memory or more, you can reduce the virtual memory. Linux uses a large amount of memory for Cache, but recycles it when resources are insufficient .. As long as you see that swap is 0 or very small, you can rest assured, because the memory is not used is the biggest waste.

[1] [2] [3] Next page

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.