Linux system crash and memory optimization under embedded/x86

Source: Internet
Author: User
Tags valgrind

I. High CPU or deadlock causes the system to die

1. High CPU consumption

(1) Too many threads lead to high CPU consumption, the system card is dead

Solution: Optimize application layer business logic, some businesses do not have to open the thread

(2) Frequent clearing of the cache results in frequent read Spi-flash, causing high CPU

Workaround: The file system portion of the kernel is processed, the cache is not cleared, and the cache is cleared at the application layer with the background service process. This may result in insufficient system memory, which requires further optimization of system memory

2. CPU Deadlock

(1) spinlock+ death lead to deadlock

(2) Application layer Pthread_mutex_lock deadlock

3. System boot failure due to CPU overheating

(1) The kernel boot failure is caused by CPU exceeding the BIOS setting threshold

(2) CPU is too hot, add fan, fan hot sheet, or optimize the structure

4. Too much dust, poor environment and other factors cause power anomalies

Two Memory problems causing system panic

1. Virtual Memory exhaustion

(1) Line hydroforming too much, causing virtual memory to reach 3G, the main program hangs dead, but the system does not panic

Confirmation method: If the system process number is PID, then view/proc/pid/status can see the number of threads open and virtual, physical memory. In addition to the top can also see virtual memory or physical memory, some busybox compilation problems, see no physical memory consumption, so it is necessary according to/proc/pid/status, or view the following fields:

Cat/proc/pid/stat | Awk-f "" ' {print ' virt: ' $23} '

Cat/proc/pid/stat | Awk-f "" ' {print ' RSS: ' $24} '

Workaround: Adjust the application layer policy, the non-open thread will not open

2. Physical memory exhaustion (OOM)

(1) This is generally a memory leak.

Confirmation Method:

A. Confirming physical memory growth with top

B. Statistics of physical memory growth through/proc/pid/status, or/proc/pid/stat

Workaround:

(1) Through review malloc/free to solve

(2) Tools for inspecting Valgrind, Oprofile, perf, etc. through tools

(3) Static check tool: Flint, pclint

(2) True physical memory is not enough

Workaround: Memory optimization

3. Too many memory fragments, the partner system is depleted of large chunks of memory

This is the memory of the system will be oom, through oom or/proc/sysrq-tigger can see the partner system, slab cache memory distribution, based on the use of local optimization.

We have a problem, the CPU is too high to generate a lot of memory fragmentation, and CPU is too high because the CPU read Flash after the cache, the CPU read Flash to memory will produce memory fragmentation, so that the CPU can be cleared by the time to resolve the cache, or not to clear the cache.

Other memory fragment processing methods:

Three Hardware issues

(1) External serial port on the other end of the antenna effect caused by excessive serial interrupt

(2) Sio signal interference resulting in a large number of interrupts, the system jammed

Four Boot Speed Optimization method

(1) Streamline the kernel business, no use of modules can not be compiled into, this module is still a lot of

(2) The driver that can be loaded after boot is compiled into KO to load separately

(3) Optimization by compiler compilation option

(4) Increase the read speed of flash, adjust the flash clock

(5) Using non-compressed cores

(6) Turn off the serial print output

(7) XIP Technology (EXecute in place)

Kernel XIP: Run the kernel directly in Flash/rom, or use a non-compressed kernel vmlinux must be faster than Zimage, uimage

File system Xip: For example, Cramfs file system, only use the portion of the read into RAM, than JIFFS2 save time

(8) graphical interface system using direct write Framebuff, without c++/qt GUI

Five Memory optimization Methods

(1) Physical memory is not enough, even if there is no memory leak, consider swapping memory

(2) Optimization of data structure, reasonable application of memory

(3) Memory recycling at the right time

(4) The minimum heap memory unit is 16 bytes so you should minimize the need for small chunks of memory to avoid wasted memory

(5) Adjust the m_mmap_threshold, reduce the threshold of MMAP, will reduce the risk of memory hole, but also increase system calls, reduce performance.

(6) Adjust the m_trim_threshold, reduce the heap top continuous memory threshold, release more heap top memory.

(7) Use Ptmalloc tools, Oprofile, Valgrind, perf and other tools to optimize

Linux system crash and memory optimization under embedded/x86

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.