Linux Memory Usage Tuning

Source: Internet
Author: User

Some time ago in the player's time, encountered a problem, took a long time, to make a record, hoping for the need to help people:

Player's broadcast video, whether it is to manually switch video or video playback completed, automatically switch video, a certain number of times after the black screen phenomenon, occasionally there is a sound, the problem occurs, unrecoverable, kernel output the following log:

DMA free:71672kb min:616kb low:768kb high:924kb active_anon:0kb inactive_anon:0kb active_file:0kb Inactive_file:0kB UNEVICTABLE:0KB isolateds

Lowmem_reserve[]: 0 1244 1593 1593

Normal free:1249804kb min:4212kb low:5264kb high:6316kb active_anon:0kb inactive_anon:0kb Active_file:0kB inactive_ FILE:0KB unevictable:0kb o

Lowmem_reserve[]: 0 0 2794 2794

Highmem free:223000kb min:348kb low:640kb high:936kb active_anon:39248kb inactive_anon:140kb Active_file:61020kB INACTIVE_FILE:34108KB Unevio

Lowmem_reserve[]: 0 0 0 0

DMA:22*4KB 90*8kb 21*16kb 82*32kb 7*64kb 137*128kb 69*256kb 3*512kb 8*1024kb 5*2048kb 3*4096kB 0*8192kB 0*16384kB 0*32768 KB = 71672kB

NORMAL:1*4KB 53*8kb 16*16kb 6*32kb 6*64kb 4*128kb 1*256kb 1*512kb 2*1024kb 2*2048kb 3*4096kb 2*8192kB 4*16384kB 35*32768k B = 1249772kB

HIGHMEM:14*4KB 10*8kb 437*16kb 386*32kb 374*64kb 27*128kb 10*256kb 7*512kb 8*1024kb 7*2048kB 4*4096kB 2*8192kB 1*16384kB 3*32768KB = 223000B

23829 Total Pagecache Pages

0 pages in swap cache

Swap Cache Stats:add 0, delete 0, find 0/0

Free swap = 0kB

Total Swap = 0kB

524288 pages of RAM

387015 free Pages

73287 reserved Pages

1169 Slab Pages

8545 pages Shared

0 pages Swap Cached

Physical memory allocation error!

Physical memory allocation error!

Through log, the position to the output is the decoding driver, the driver after the DMA request failed, output the above information. In view of this phenomenon, according to the following several ideas of investigation:

1. Memory leaks

Some logs are added to the drive, and as the video is switched on, the assigned address will grow to a certain extent until the final allocation fails. But careful study found that allocation and release are paired, the memory usage information recorded in the drive is completely correct, and there is no indication that a memory leak has occurred.

2. Memory fragmentation

The official theory has the same problem to log on, but without a clear conclusion, the authorities should not reproduce. Some people point out that the problem is that the continuous block of memory that drives the request is larger, but the system has no memory to allocate, that is, memory fragmentation. At the same time, some people give two scenarios: cache each request of memory, after allocation, no longer return to the system, this scenario I test, the discovery will cause other video drivers have the same problem, not available, another scenario is to think that the cause of memory fragmentation is due to the file system cache mechanism, to solve this problem, The memory consumed by the cache needs to be cleared, as follows:

Echo 3 >/proc/sys/vm/drop_caches

After the test, really effective, testing the hands of the test case thousands of times, sent a test software, the results of the tragedy, the development department test cases several times to measure the same problem, the scheme is not acclimatized.

3. Investigate Linux Memory usage

From the idea of memory fragmentation, analyze what caused the DMA space fragmentation of the drive. Some data have been found, the memory partition of Linux is divided into 3 blocks: Dma,low and high memories. General 32-bit PC configuration is DMA zone located in 0x00010000-0x00ffffff, about 16mb,low Memory is 0x01000000-0x37bfdfff, about 800 MB, and then up to the space to high Memory, This part of the visit to jump, performance than DMA zone and low Memory zone fast. The memory allocation strategy is allocated from the top down, and once the high memory space is low, the memory is requested to the lower address space. In our products, the total memory size is 512MB, some drivers reserved 128MB,DMA zone configuration is 184MB, then the actual remaining low Memory zone only 200MB, and this 200MB to run the UI, media management, interconnection and a series of processes. Once the low memory zone is not available, the system will request memory from the DMA zone, resulting in the memory fragmentation of the DMA space! At this point, the free command is not able to see the correct memory information, because the space to see also, but one is the cache occupied, the second is the total count, rather than the real continuous memory, then the view memory should use the system provides buddy info to see the real remaining memory block:

$cat/proc/buddyinfo

Node 0, Zone DMA 3 1 3 4 1 2 2 0 1 2 0 3 2 2

Node 0, Zone Normal 74 36 29 8 6 4 3 2 1 2 3 2 0 2

The output of the data from the left is the number of 4K memory block, multiply by 2 to the right of 32M, in the case of problems, the system basically only a small block of memory, and the problem is because some file access operation caused the DMA zone space is used by the cache.

4. Controlling the memory allocation algorithm

After you find the cause of the problem, investigate how you can prevent the system from allocating memory from the DMA zone. Find to be able to set lowmem_reserve_ratio, to tell the system, DMA zone reserved space. There are 3 parameters (system default: 256,32,32), and DMA zone is the first, the value is a divisor, the DMA zone size divided by 256, the basic is the size of the reservation. After doing a few tests, it was found that only set to 1 to effectively protect the DMA zone is not occupied,:(! After setting to 1, the video no longer appears black screen, but other problems occur quickly, because the system available memory is reduced, the memory recovery algorithm is frequently executed, the performance drops sharply.

5. Final plan

Since the total memory of the product is too small and the DMA zone reserved is too large, you need to adjust the space reserved by the DMA zone, but Lowmem_reserve_ratio has no space to adjust, so consider adjusting the kernel up and down. Finally, the total size of the DMA zone in the kernel is adjusted from 184MB to the original 3/4, that is, 138MB, to obtain an approximate reasonable configuration, guaranteed DMA and low memory can be applied to enough space, after a long period of testing, not reproduce the related problems.

Linux Memory Usage tuning

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.