1. Memory leak

    Definite phenomenon :

     linux Memory leak , You can view it slabinfo
And the other one proc lower ( seemingly meminfo), Information about memory , You can see if memory is decreasing , And the speed of reduction .

    vxworks system , Does the memory have relevant information ???

    If memory leaks quickly , It is easier to judge . If it's very slow , After a certain period of time, the scene will reappear , You can see that, too .

    linux After running out of memory , There will be log Printing . Easy to judge .vxworks To be tested .


    After confirming that there is a memory leak , How to identify the source of the leak ?

    malloc Make changes , Make it record relevant information ---- Is this feature currently available . If you don't, don't say it .

    Reappear scene . In what scenario will the leak occur , Specific points , Which task is running will leak , It is hereby confirmed .


【  Specific method supplement 】

Linux The principle of memory usage is : If there is enough memory , No need, no need , Try to use memory to cache some files , So as to speed up the process , When there is not enough memory , It will be recovered through the corresponding memory recovery policy cache Memory , For process use .

This can be done by proc Under the process of analysis of the relevant files , Accurately evaluate the amount of memory consumed by the system , It can also provide a positioning method to solve the problem of memory leakage .

One , Analysis of system total memory

It can be downloaded from proc Directory meminfo File to learn about the current system memory usage summary , The physical memory available =memfree+buffers+cached, When memfree When not enough , The kernel uses a write back mechanism (pdflush thread ) hold cached and buffered Memory write back to backup memory , This frees the relevant memory for use by the process , Or it can be released manually cache Memory :
echo 3 > /proc/sys/vm/drop_caches
adopt cat /proc/meminfo View memory usage .

  Two , Statistics of process memory usage

stay 32 Bit operating system , Each process has 4G Virtual memory space for , among 0~3GB Is the private user space for each process , This space is not visible to other processes in the system .3~4GB yes linux Kernel space , Shared by all processes and the kernel . By visiting
/proc/{pid}/ Related documents , You can understand the usage of virtual memory space for each thread , To understand how much memory each thread consumes .

Because our products are implemented in a multithreaded way , Multiple threads share a process's user state virtual address space , The virtual address space contains several regions , There are mainly the following areas :

1, The code snippet of the current execution file , This code segment is called text paragraph .

2, Data segment of execution file , It mainly stores the global variables used by the execution file , Static variable .

3, A heap that stores global variables and dynamically generated data .

4, A stack for holding local variables and implementing function calls .

5, use mmap Mode is mapped to a memory segment in the virtual address space

Therefore, you only need to check the virtual address space allocation of any thread to know the total memory occupied by all threads belonging to the same process . You can view the /proc/{pid}/maps File to get the relevant virtual address space content

If in the actual debugging process , A memory leak is suspected somewhere , You can view the maps surface , Look at the heap segment of the process or mmap Does the segment's virtual address space continue to grow , If it is , Indicates that a memory leak is likely to occur , If mmap Segment virtual address space continues to grow , You can also see the size of the virtual address space for each segment , So we can determine how much memory has been applied , It can play a good role in debugging memory leak class .



2. Step on memory .

    1) Pre allocated memory is stepped on . Like shared memory ,axi_mem. It may be different start-up stages of other cores or current cores .

        First confirm if there is a problem with the allocation , Does the allocation space overlap . If it's at the boundary , Then we should focus on the adjacent areas .

    It may also be public IP Register of resources , It's been tampered with , If the current core does not write , Register changed “ write ”, It should be other nuclear stem .

    2) Inside the system , System operation of a core , Normal memory .

       It's not easy to do . You can try a conditional breakpoint . What is the wrong value after being stepped on , What is the reasonable value .

        Is it because the array in its own module is out of bounds .

If it is because of initializing pointer access for , Cause to write to random address , Don't worry too much , Because it's more likely to be data abort.


  It's not very useful ..


©2019-2020 Toolsou All rights reserved,
java Four functional interfaces ( a key , simple )os Simple use of module Browser kernel ( understand ) Some East 14 Pay change 16 salary , Sincerity or routine ?HashMap Explain in detail It's unexpected Python Cherry tree (turtle The gorgeous style of Library )html Writing about cherry trees , Writing about cherry trees