Back-to-original series ------ micro kernel and macro Kernel

Source: Internet
Author: User

I found that I have always been a person to learn about. I don't know whether my mind is impetuous or I can't be so knowledgeable. Fortunately, I am a good thinker. Now I have come up with a new idea to differentiate these two concepts. It will not be confused. After understanding the following issues, it is more conducive to understanding the Linux architecture.

In general, we will think that all modules that can serve processes should be placed in the kernel of the operating system. For example, the file management module serves processes, so it is placed in the kernel. Various driver modules serve processes, so they must be placed in the kernel. The process module must be placed in the kernel. As process service requests increase, the operating system kernel will become larger and larger, and a series of problems will emerge.

First, the kernel is resident memory, so the storage space occupied by the large kernel is large. In this way, the hardware system is relatively small and the memory resources are insufficient. Second, it is difficult to maintain the system. If a service module in the kernel is modified, it is inconvenient to compile the entire system after the modification, it means that the processor runs for a long time in the kernel, which is not suitable for applications with high speed requirements.

In short, after the operating system kernel reaches a certain level, there will be a series of problems arising from the large kernel. To solve these problems, people have come up with a series of ways to make the kernel smaller while meeting the services required by the application. An effective method is to move part of the content in each service program module of the kernel to the outside of the kernel as a process. In the kernel, only the interfaces of the kernel service and user processes are retained. The kernel is only used as a message transfer station, so that the kernel is greatly reduced. Such a kernel is called a microkernel.

The macro kernel and micro kernel are not judged by anyone at the cainiao level. However, if I bring these representatives up, you may have your own comments.

The micro-kernel systems include the kernel-based systems such as kernel-based, minix, Mac, and etc. Macro kernel systems such as UNIX, Linux, and etc. An interesting phenomenon is that UNIX is a macro kernel, while Mac is a micro kernel. In addition, minix and Linux have not convinced each other.

The two system kernels are compared through the fork creation of processes, because process creation involves the main aspects of systems such as system calls, memory management, and file management. Therefore, you can compare fork to get a rough idea of the differences in the kernel.

Minix

In minix, the operating system kernel, memory management, and system management all have their own Process Tables. Each part of the table contains the domain they need. Tables are exactly matched. To maintain synchronization, you must update the tables at the Process Creation and end. Coordinated by the Memory Manager.

After the system is started, the kernel, mm, and FS processes run the main () function in their respective spaces to wait for messages cyclically.

While (true)

{

......

Receive (any, & mm_in );

......

}

When a fork is passed to mm main (), main () calls do_fork (), do_fork () the function creates an exact copy of the data, segment, and stack segment of the parent I function to the child process, and shares the text segment of the parent process with the child process, then, add a new process in the MM progress table mproc [] and set the attributes. Send a message to the kernel (sys_fork (...)) and FS (tell_fs (...)), the function sys_task () in the kernel receives the system message, calls do_fork (Message * m_ptr), and copies the proc of the parent process.
Struct to the child process, and set the attributes of the process in the kernel table. Tell_fs () is the interface between the memory manager and the file system. Tell_fs (...) call _ taskcall (...), the file manager receives the fork system message, calls the do_fork () function, copies the fproc struct of the parent process to the child process, and sets the attributes of the process in the file table. In this way, the attributes of the entire process are set.

When creating a new process in minix, we can see that the entire system is divided into several parts by function, and each module uses the message mechanism for communication, functions of other modules must be called through the daemon process of the target module.

Representative of macro kernel: Linux

In Linux, the process structure is as follows:

Struct task_struct {

Pid_t PID;

Pid_t pgrp;

...

/* Filesystem information */

Struct fs_struct * FS;

/* Memory Management Info */

Struct mm_struct * mm;

...

};

In the structure definition of a Linux Process, task_struct contains all information, including the memory and file system of the process. When creating a process, the system calls sys_fork to call the do_fork (...) function.

Int do_fork (unsigned long clong_flags ,...)

{

Struct task_struct * P;

P-> pid = get_pid (clone_flags );

....

/* Copy all the process information */

Copy_files (clone_flags, P );

Copy_fs (clone_flags, P );

Copy_mm (NR, clone_flags, P );

...

}

When creating a process, the do_fork function completes all the work and assigns a PID... Copy the data segment and stack segment of the parent process. The process creation process in Linux is a complete process. It directly calls functions of other modules instead of passing messages.

Compared with the process of creating a new process in Linux, minix can see the difference between the two. minix is based on the sub-modules, and the modules are connected by information transmission. Linux is divided into modules, but it is an independent Binary large image when running, and the communication between modules is directly implemented by calling functions in other modules. The difference between the macro kernel and the micro kernel is also found here. The microkernel is an information transfer station with few functions completed by itself. It mainly transmits the function requests from one module to another, while the macro kernel is a big supervisor who manages the memory, all files are managed.

Theoretically, the idea of the microkernel is better. The microkernel divides the system into small functional modules, reducing the design difficulty and making system maintenance and modification easier, however, the loss of communication efficiency is a problem. The coupling between functional blocks of the macro kernel is too high, resulting in a high cost of modification and maintenance, but it is not a big problem in the current Linux, because the current Linux is not too complex, the macro kernel is directly called, so the efficiency is relatively high.

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.