为什么 Linux 被称为单片内核? [英] Why is Linux called a monolithic kernel?

查看:28
本文介绍了为什么 Linux 被称为单片内核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到 Linux 是一个单体内核.单片内核是否意味着将完整的内核代码编译并链接成可执行文件?

I read that Linux is a monolithic kernel. Does monolithic kernel mean compiling and linking the complete kernel code into an executable?

如果Linux能够支持模块,为什么不将所有子系统分解成模块并在必要时加载它们?在这种情况下,内核不必一开始就加载所有模块,而是可以维护模块中函数的索引,并在必要时加载它们.

If Linux is able to support modules, why not break all the subsystems into modules and load them when necessary? In that case, the kernel doesn't have to load all modules initially and could maintain an index of the functions in the module and load them when necessary.

推荐答案

单体内核是这样一种内核,其中所有服务(文件系统、VFS、设备驱动程序等)以及核心功能(调度、内存分配等)都在内核中.) 是一个紧密结合的群体,共享相同的空间.这直接反对微内核.

A monolithic kernel is a kernel where all services (file system, VFS, device drivers, etc) as well as core functionality (scheduling, memory allocation, etc.) are a tight knit group sharing the same space. This directly opposes a microkernel.

微内核更喜欢将核心功能与系统服务和设备驱动程序(基本上只是系统服务)隔离的方法.例如,VFS(虚拟文件系统)和块设备文件系统(即 minixfs)是在内核空间之外运行的独立进程,它们使用 IPC 与内核、其他服务和用户进程进行通信.简而言之,如果它是Linux中的模块,那么它就是微内核中的服务,表示一个孤立的进程.

A microkernel prefers an approach where core functionality is isolated from system services and device drivers (which are basically just system services). For instance, VFS (virtual file system) and block device file systems (i.e. minixfs) are separate processes that run outside of the kernel's space, using IPC to communicate with the kernel, other services and user processes. In short, if it's a module in Linux, it's a service in a microkernel, indicating an isolated process.

不要将术语模块化内核混淆为单片内核.一些单体内核可以编译为模块化(例如 Linux),重要的是模块插入并运行在处理核心功能的同一空间(内核空间).

Do not confuse the term modular kernel to be anything but monolithic. Some monolithic kernels can be compiled to be modular (e.g Linux), what matters is that the module is inserted to and runs from the same space that handles core functionality (kernel space).

微内核的优点是任何失败的服务都可以轻松重新启动,例如,如果根文件系统抛出中止,则内核不会停止.不过,这也可以看作是一个缺点,因为它可以隐藏非常严重的错误(或者使它们看起来不那么严重,因为问题似乎会不断自我修复).在部署后您根本无法方便地修复某些内容的情况下,它被视为一个很大的优势.

The advantage to a microkernel is that any failed service can be easily restarted, for instance, there is no kernel halt if the root file system throws an abort. This can also be seen as a disadvantage, though, because it can hide pretty critical bugs (or make them seem not-so-critical, because the problem seems to continuously fix itself). It's seen as a big advantage in scenarios where you simply can't conveniently fix something once it has been deployed.

微内核的缺点是异步 IPC 消息传递会变得非常难以调试,尤其是在 fibrils 实施.此外,仅仅追踪 FS/写问题意味着检查用户空间进程、块设备服务、VFS 服务、文件系统服务和(可能)PCI 服务.如果您对此一无所知,那么是时候查看 IPC 服务了.这在单片内核中通常更容易.GNU Hurd 遭受这些调试问题(参考).在处理复杂的消息队列时,我什至不打算进入检查点.微内核不适合胆小的人.

The disadvantage to a microkernel is that asynchronous IPC messaging can become very difficult to debug, especially if fibrils are implemented. Additionally, just tracking down a FS/write issue means examining the user space process, the block device service, VFS service, file system service and (possibly) the PCI service. If you get a blank on that, its time to look at the IPC service. This is often easier in a monolithic kernel. GNU Hurd suffers from these debugging problems (reference). I'm not even going to go into checkpointing when dealing with complex message queues. Microkernels are not for the faint of heart.

获得稳定运行的内核的最短路径是单体方法.这两种方法都可以提供 POSIX 接口,对于那些只想编写代码以在任何给定设计上运行的人来说,内核的设计几乎没有兴趣.

The shortest path to a working, stable kernel is the monolithic approach. Either approach can offer a POSIX interface, where the design of the kernel becomes of little interest to someone simply wanting to write code to run on any given design.

我在生产中使用 Linux(单体).然而,我对内核开发的大部分学习、黑客攻击或修补都进入了微内核,特别是 HelenOS.

I use Linux (monolithic) in production. However, most of my learning, hacking or tinkering with kernel development goes into a microkernel, specifically HelenOS.

编辑

如果您通过我冗长的回答获得了这么多,那么您可能会在阅读关于内核设计的 Torvalds-Tanenbaum 大辩论'.在它发生 20 多年之后,在 2013 年读起来更有趣.最有趣的部分是 Linus 在最后一条消息中的签名:

If you got this far through my very long-winded answer, you will probably have some fun reading the 'Great Torvalds-Tanenbaum debate on kernel design'. It's even funnier to read in 2013, more than 20 years after it transpired. The funniest part was Linus' signature in one of the last messages:

Linus "my first, and hopefully last flamefest" Torvalds

显然,这与 Tanenbaum 预测的 x86 很快就会过时一样没有实现.

Obviously, that did not come true any more than Tanenbaum's prediction that x86 would soon be obsolete.

注意:

当我说Minix"时,并不是指 Minix 3.此外,当我提到 The HURD 时,我指的是(主要是)Mach 微内核.我无意贬低他人最近的工作.

When I say "Minix", I do not imply Minix 3. Additionally, when I mention The HURD, I am referencing (mostly) the Mach microkernel. It is not my intent to disparage the recent work of others.

这篇关于为什么 Linux 被称为单片内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆