Comparison between Linux and uClinux

Source: Internet
Author: User

Standard Linux is designed for MMU processors. On such a processor, virtual addresses are sent to MMU to map virtual addresses to physical addresses. By assigning different virtual-physical address translation mappings to each task, protection between different tasks is supported.

UClinux is an embedded linux operating system in the control field. It is derived from the Linux 2.0/2.4 kernel and inherits most of the mainstream Linux features. Suitable for Microprocessor/microcontroller that does not have memory management units (MMU. The absence of MMU support is a basic difference between uClinux and mainstream Linux.

UClinux has a very small kernel and user software space. Developers familiar with mainstream Linux will notice minor differences in working in uClinux, but they can also quickly get familiar with some uclinux features. For developers who design applications in the kernel or system space, pay special attention that uClinux does not have memory protection or virtual memory models. In addition, some kernel system calls are also different.

For uCLinux, it is designed for a processor without MMU and cannot use the virtual memory management technology of the processor. UCLinux still uses paging Management of memory, and the system paging the actual memory at startup. The program is loaded by page when the application is loaded. However, since MMU management is not available, uCLinux uses a real-memory management policy. In uCLinux, memory access is direct, and the addresses accessed in all programs are physical addresses. The operating system does not protect the memory space. Each process actually shares a runtime space. Before a process is executed, the system must allocate sufficient contiguous address space for the process and load all the data into the contiguous space of the primary memory.

1.1 memory Protection

An operation without Memory Protection will result in an address error even if an Invalid Pointer is called by a non-privileged process, and may cause program crashes, or even system suspension. Obviously, the code running on such a system must be carefully programmed and thoroughly tested to ensure robustness and security.

For general Linux systems, different user programs need to be run. Without memory protection, the system security and availability will be greatly reduced. However, for Embedded uClinux systems, because the running programs are often solidified before leaving the factory, there is no risk of program intrusion endangering system security. Therefore, as long as the application passes a complete test, the probability of a problem can be controlled within a limited range.

1.2 virtual memory

The absence of Virtual Memory mainly results in the following consequences:

First, the processes loaded by the kernel must be able to run independently, regardless of their location in the memory. The first way to achieve this is that once the program is loaded into RAM, the baseline address of the program will be "fixed; the other method is to generate a Code that only uses relative addressing, called "location-Independent Code", Position Independent Code (PIC ). UClinux supports both modes.

Second, we need to solve the problem of memory allocation and release in flat memory models. Very dynamic memory allocation can cause memory fragmentation and may exhaust system resources. For applications that use dynamic memory allocation, one way to improve robustness is to replace malloc () calls with a pre-allocated buffer pool (Preallocated buffer pool.

Since uclinux does not use virtual memory, page switching between inbound and outbound memory is not implemented, because the page cannot be loaded to the same location in RAM. On a general computer, the operating system allows applications to use a larger memory space than the physical memory (RAM), which is often achieved by setting up swap partitions on the hard disk. However, in embedded systems, FLASH memory is usually used to replace hard disks, making it difficult to efficiently implement access to Memory Page exchanges. Therefore, all running applications have limited their allocable space not greater than the system's RAM space.

Note that the multi-task is not affected. Which of the old and widely used fork () network background programs daemon need to be modified. Because the child process runs in the same address space as the parent process, in some cases, you also need to modify the behavior of the two processes.

Many modern programs rely on sub-processes to execute basic tasks, so that when the process load is very heavy, the system can still maintain a "interactive" state, these programs may need to be substantially modified to complete the same task in uClinux. If a key application is very dependent on such a structure, You have to rewrite it.

Assume that there is a simple network backend Program (daemon) that uses fork () in large quantities (). This daemon Director listens to a well-known port or socket) and waits for the network client to connect. When the client connects, this daemon gives it a new connection information, a new socket number), and CALLS fork (). The child process is connected to the client on the new socket, and the parent process is released. You can continue to listen for new connections.

UClinux does not have an automatic growth stack or brk () function. In this way, the user space program must use the mmap () command to allocate memory. For convenience, the implemented malloc () in the C language library of uclinux is essentially an mmap (). You can specify the stack size of a program during compilation.

Finally, the uClinux target board processor lacks hardware units for memory management, which makes the Linux system interface need to be changed. The biggest possible difference is that fork () and brk () systems are not called. Call fork () to copy the process to create a child process. In Linux, fork () is implemented using the copy-on-write page. Without MMU, uclinux cannot completely copy a process or access copy-on-write. To make up for this defect, uClinux implements vfork (). When the parent process calls vfork () to create a child process, the two processes share all their memory space, including the stack. The sub-process either runs in place of the parent process. At this time, the parent process has sleep) until the sub-process calls exitI () to exit, or it calls exec () to execute a new process, in this case, an executable file is generated. This process cannot be avoided even if it is just a copy of the parent process. After the child process executes exit () or exec (), the child process uses wakeup to wake up the parent process, and the parent process continues to run.

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.