Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of linux RTOS memory Management

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the "linux RTOS memory management method" related knowledge, small series through the actual case to show you the operation process, the operation method is simple and fast, practical, I hope this "linux RTOS memory management method" article can help you solve the problem.

(i)"Heap" and "Stack"

Readers who have studied the principles of microcomputers may know that in x86 architecture machines, there are two registers specifically related to stack management, one called the stack segment register SS and the other called the stack pointer register SP. I think this is where you first came into contact with the stack.

However, careful readers may find that I am writing here to separate "heap" from "stack," which means that "heap" and "stack" here do not mean "stack" in the above. The stack here, to put it simply, refers to the data structure inside the operating system. We call English "Stack" as "Stack Area" and English "Heap" as "Heap Area." We emphasize that the "stack" in the microcontroller or processor refers to a special memory, while the "stack" and "stack" in the operating system are two different data structures.

The following examples are based on the assumption that there is an operating system. Suppose we define a variable "int a = 0xfe;" in C language. When this statement goes to system operation, where does variable a exist in the end, and how much storage area is given to it, it is automatically allocated and released by the compiler. The above storage place is called "stack area". In addition, the parameter values of the function, the values of local variables, etc. are also stored in the stack.

Suppose you use "malloc" to create a memory area. This memory area is actually composed of contiguous or discontinuous blocks of memory. It is similar to a linked list of data storage areas. This operation is called "heap" to create memory.

In addition, the variables stored in the "stack area" will be allocated by the system every time they are used and automatically recycled when they are not used, so why there is such a keyword static is also the reason; and the memory of the "heap area" must be manually released if it is not used after it is opened, because the system will not automatically recycle it. If multiple tasks allocate memory dynamically without recycling, it will easily cause memory overflow, which will have serious consequences. The memory in the heap area is only automatically freed in one case, that is, when the system is forced to stop.

With the above knowledge, we can explain the memory allocation problem of operating system tasks. All operating system memory management is to allocate a piece of memory to memory in the "heap area" when the system will be in operation. The specific memory size is set by the user himself in FreeRTOS. In this way, as long as we allocate it properly, our task can allocate the most reasonable memory size to the running task in any case, because the non-running task can free up a lot of memory.

(2) Virtual memory technology

Linux is said to be very portable, and you can port Linux to almost any platform with MMU. This sentence seems a bit problematic, because to port Linux, first ensure that your platform is with MMU. The point is, what is "MMU."

"MMU", Memory Manage Unit, it is the key hardware component to realize "virtual memory technology", so what is "virtual memory technology"? Why Virtual Memory Technology?

Virtual memory is a technique for memory management in computer systems. It makes an application think it has contiguous memory available (a contiguous complete address space), when in reality it is usually divided into physical memory fragments, with portions temporarily stored on external disk storage for data exchange when needed. For a detailed description of virtual memory, please refer to our later reprinted article.

The real benefits of virtual memory are twofold: first, it avoids direct access to physical memory by applications, so that even if a careless programmer forgets to free memory, the system will only recycle the corresponding task rather than crash the entire system. Second, you can expand the limited physical memory to the highest level. For example, if your computer's address bus is 32 bits, you can expand 2GB of physical memory to 2^32.

Unfortunately, it was not a big problem to run Linux on STM32, but due to MMU restrictions, I could only run FreeRTOS regretfully, which is the farthest distance. However, a few years ago, some kernel hackers rewritten Linux's memory management code, limited its MMU, and used software to simulate it, named uCLinux, but the effect was really not good, so it slowly declined.

About "Linux RTOS memory management method" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report