Memory Management Methods in Linux Embedded Systems

Source: Internet
Author: User
Article Title: memory management methods for Linux Embedded Systems. 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.

1. Requirements for memory allocation in Embedded Systems

① Fast.

The real-time guarantee in embedded systems requires that the memory allocation process be as fast as possible. Therefore, in embedded systems, it is impossible to adopt complex and perfect memory allocation policies in general operating systems. Generally, simple and fast memory allocation solutions are adopted. Of course, there are different allocation schemes for different programs with different requirements on implementation. For example, VxWorks adopts a simple first matching method such as instant aggregation; VRTX adopts multiple fixed-size binning schemes.

② Reliability.

That is, the request for memory allocation must be satisfied. If the allocation fails, it may have disastrous consequences. Embedded system application environments are ever-changing, some of which have extremely high reliability requirements. For example, in the auto-Driving System of a car, the system detects that the car is about to crash. If the memory allocation fails and cannot be operated, the car will crash. This is intolerable.

③ Efficiency.

Memory allocation should be minimized. It is impossible to increase the memory size to meet all memory allocation requests. On the one hand, the cost requirements of embedded systems make the internal existence only a very limited resource; on the other hand, even if you do not consider the cost, the limited space and area of the system determine that the configurable memory capacity is limited.

2. Static and Dynamic Allocation

Whether applications use static or dynamic allocation remains a constant debate in the design of embedded systems.

Of course, the most appropriate answer is to adopt different solutions for different systems. If the system has extremely high requirements on real-time performance and reliability (hard real-time system), it cannot tolerate a delay or a allocation failure. Of course, the static allocation scheme must be used, that is, the memory required for program compilation has been allocated. For example, the embedded system on the Mars detector must adopt a static allocation scheme. In addition, a real-time operating system OSEKWorks dedicated for automotive electronics and industrial automation does not support dynamic memory allocation. In such applications, the cost does not support dynamic memory allocation. In such applications, cost is not a priority, and real-time and reliability must be ensured.

Of course, it is inevitable that the system loses flexibility to adopt static allocation. In the design phase, the required memory must be known and allocated in advance; all possible situations must be taken into account in advance during the design phase, as the system will not be able to handle any situations that are not taken into account. Such a allocation scheme must cause a great waste, because the memory allocation must be configured according to the worst case. In fact, only a small part of the allocation scheme may be used during the operation; in addition, without changing the hardware platform, it is impossible to flexibly add functions to the system, making it difficult to upgrade the system. Most systems are integrated with hard real-time systems and soft real-time systems.

That is to say, some tasks in the system have strict time limit requirements, while the other part only requires the faster the completion, the better. According to the RMS (Rate Monotoin Scheduling) theory, such a system must adopt preemptive task Scheduling. In such a system, dynamic memory allocation can be used to meet tasks with low reliability and real-time requirements. The advantage of dynamic memory allocation is that it gives designers great flexibility to easily transplant Programs originally running on non-embedded operating systems to embedded systems. For example, network protocol stacks used in many embedded systems. If static memory allocation is required, porting such a protocol stack is much more difficult. In addition, the use of dynamic memory allocation allows the designer to adjust the system functions flexibly without changing the basic hardware platform, and to make a balance between the functions of the system. For example, you can adjust the number of supported VLANs and the number of supported route entries, or different versions support different protocols. After all, the dynamic memory is allocated to embedded system programmers with less restrictions and greater freedom. Therefore, most real-time operating systems provide dynamic memory allocation interfaces, such as malloc and free functions.

3. Memory Allocation interface provided by RTOS

Different RTOS adopt different memory allocation policies for different locations.

For example, in VRTX, a memory allocation scheme similar to the Binning algorithm developed by Doug Lea In gnu c is used. The system memory is divided into some fixed-size memory block algorithms, the system memory is divided into a set of fixed-size memory blocks. The advantage of this method is that the search speed is fast and no memory fragments are generated. However, its disadvantage is also obvious, that is, it is easy to cause waste, because the size of the memory block is only limited, the allocation can only take a large memory block to meet a small demand, in addition, the memory allocation table managed by the operating system is also a huge burden.

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.