👋👋Original link: I talked about macro kernel and micro kernel, and blew a wave of Linux
The kernel is a very important part of the operating system, and it is also the core of the operating system. The kernel manages system resources. The kernel connects applications upwards and hardware downwards. It is a bridge between applications and hardware.
The kernel can be further divided into macro kernel and micro kernel .
The biggest difference between the macro kernel and the micro kernel is that macro kernel are stored in the same address space, and they are all managed by the kernel, while the user services and kernel services of the micro kernel are stored in different addresses. address space, the following figure can explain this well.
In fact, the translation of the macro kernel here is a bit far-fetched, in fact it should be called single-core or single-core. In this single-core design, the kernel is a big whole, which can be said to be a big process. In this big process, all kernel services run in an address space, and there are few call links between functions. Communication simple and efficient .
The function of the microkernel is divided into independent processes, and the processes IPC , which is highly modular, and the failure of one service will not affect another service. However, due to the influence of modularity, the calling link between functions is too long, and processes will not communicate directly, but communicate with each other through kernel services.
From the kernel size above, the size of the micro-kernel is smaller and only contains services related to the user process, while the size of the single-core is much larger than the micro-kernel. This is easier to understand, because the macro-kernel incorporates too much Service and drive.
From the execution efficiency , the execution efficiency of the micro-kernel is relatively slow because it involves cross-module calls, while the macro-kernel execution efficiency is high because functions are directly called.
After the microkernel modularizes , it is easy to expand, because the kernel space and user space are isolated from each other. In user mode (applications running in user space) application crashes generally do not affect the data in the kernel. . The scalability of the macro core is poor.
After the above description, we can easily imagine the characteristics of the macro and micro kernels as the monolithic architecture and architecture 16180dd3b68a0b in software development.
The biggest feature of the monolithic architecture is that it is convenient to call functions, and there is almost no call link. One project solves all problems. The project contains database drivers, various interceptors, controllers, and access control, and its scalability is very poor.
The call link between the microservice architecture will be relatively long, and the responsibilities between the modules are separated and dependent on each other, such as the permission control module, the routing module, and the bus communication module. The scalability is relatively strong.
These two different kernel structures have different supporters, just as some people think that the monolithic architecture is good, and some people think that the microservice architecture model is good.
This is like an argument over programming languages. Which language is better, Python, Go, Java, or other languages? No matter which one is better, he will end up jokingly saying that PHP is the best language in the world . Therefore, these arguments are meaningless, but it is very interesting that such arguments often remind people of the struggle between RISC and CISC in the CPU field in previous years.
Modern and successful CPU designs include either of these two technologies, just as the Linux kernel is a hybrid product of micro and macro kernels. Some people may think that Linux is not just a macro kernel structure, but in fact Linux is not just a purely integrated kernel.
Why does Linux use a single kernel (single kernel here is a bit suitable) structure? I guess there are several factors.
From Linus's point of view, the development and selection of a single core is easier because it avoids the work related to the message passing architecture and the calculation module loading method. Moreover, the reason for the birth of Linux is that Linus is very dissatisfied with MINIX (a UNIX-like operating system) that is only allowed to be used in education, and Linus was originally interested in the operating system, so he began to write the Linux operating system, so I think it was Linus's development of Linux originated from interest, and did not go through a detailed and thoughtful design, nor did it consider its scalability. Of course, this is just a superficial guess.
This is the same as our graduation project in college. Do you consider scalability for the system your graduation project made? Unless you want to make it as a product, but why bother?
Another reason is sufficient development time. Linux has no time limit for development and no release schedule. Any restriction can only modify and extend the kernel alone. The core single design is completely modularized inside, and in this case it is not very difficult to modify or add. The problem is that there is no need to rewrite the Linux kernel in pursuit of a small increase in unproven maintainability. Linus has repeatedly emphasized the following point: It is not worth losing speed for this benefit.
Linux is a macro kernel structure that draws on the essence of microkernels. Linux supports modular design, preemptive kernel, support for kernel threads, and the ability to dynamically load kernel modules. Not only that, but Linux also avoids the performance loss of its micro-kernel design, allowing everything to run in kernel mode and directly call functions without message passing.
So overall, Linux is a modular, multi-threaded, and kernel-schedulable operating system.
Modular design: Linux supports dynamic loading of kernel modules. Although the Linux kernel is also single-core, it allows some kernel codes to be dynamically deleted and loaded when needed.
Preemptibility: The Linux kernel supports preemption. Unlike traditional UNIX, the Linux kernel has the ability to allow tasks running in the kernel to be executed first. Among various UNIX products, only Solaris and IRIX support preemption, but most traditional UNIX kernels do not support preemption.
In Linux, pragmatism is perfectly embodied. If a feature has no value or a bad idea, it will not start to be implemented. On the contrary, in the development process of Linux, a commendable pragmatic attitude has been formed: any change must be aimed at the actual problems in reality, and needs to go through a complete design and correct and concise implementation.
If Linux is a pure microkernel design, it will be easier to port to other architectures. The actual situation is that although Linux kernel porting is not very simple, it is by no means impossible.
Finally, I recommend my own Github , there are a lot of hardcore articles in it, which will definitely help you. Gan! ! ! 💪
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。