QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4654|回复: 25

Linux究竟是单内核的还是微内核的?

[复制链接]
发表于 2003-5-4 15:13:01 | 显示全部楼层 |阅读模式
而且我还没有弄明白单内核和微内核的具体概念。

看过一篇文章,说Linux是单内核的,不过另一篇则说所有的Unix都是微内核的,虽然可以构造成单内核的。
而且和微内核相比,单内核的os存在很多问题

或者说,x86的Linux是微内核的,而嵌入式的则是单内核的

不敢确信,希望知道的哥们说一说
发表于 2003-5-4 16:39:15 | 显示全部楼层
x86上真正的微内核是gnu hurd(mach 3 for x86)。linux应该还是单内核的。
微内核虽说在某些理论上有很牛b的特点,但会慢。而且虽说是micro kernel,但其实很大。
我是这样看的:linux有了可加载内核模块的机制之后,micro kernel对于linux并没有多大的意义。
回复

使用道具 举报

发表于 2003-5-4 21:07:02 | 显示全部楼层
毫无疑问linux是宏内核(Monolithic)的!

有一个著名的事件就是Andrew Tanenbaum(荷兰教授,minix作者)和Linus Torvalds的关于微内核和宏内核之间的争论
回复

使用道具 举报

发表于 2003-5-4 23:23:39 | 显示全部楼层
my opinion:
keenor and coldwind are right. linux is monolithic kernel, whether it run on x86 or m68k. whether it is used for pc, server or embedded linux.
to Axin, minux is a os used for teaching and never be used in a production environment. so embedded system do not use it. micro kernel will be slower than monolithic kernel, but vxworks is faster that embedded linux. so i am not sure if vxworks is a micro kernel os. vxworks's realtime and event-driven architecture is the reason why it is faster than linux. even realtime linux. linux is widely used in normal embedded system like mp3 player, netcam... but never be used in io controller.
回复

使用道具 举报

发表于 2003-5-4 23:40:54 | 显示全部楼层
The kernel is the fundamental part of an operating system. It is responsible for providing secure multiplexing and arbitration of a machine's hardware, which it provides in the form of a set of abstractions.

Some operating systems, such as Linux, have monolithic kernels which provide rich and powerful abstractions. Others, such as Windows XP, Mac OS X, and GNU Hurd have microkernels which provide a small set of simple abstractions. Yet others have exokernels which provide no abstractions. In the latter cases, the remaining features require small modules which can be flexibly configured.

Monolithic kernels
The monolithic approach definines a high-level virtual interface over the hardware, with a set of primitives or system calls to implement operating system services such as process management, concurrency, and memory management in several modules that run in supervisor mode.

Even if every module servicing these operations is separate from the whole, the code integration is very tight and difficult to do easily and correctly, and, as all the modules run in the same space, a bug in one of them can bring down the whole system. However, when the implementation is complete and trustworthy, the tight internal integration of components allows the low-level features of the underlying system to be effectively exploited, making a good monolithic kernel highly efficient. Proponents of the monolithic kernel approach make the case that if code is not correct, it does not belong in a kernel, and if it is, there is little advantage in the microkernel approach.

Examples of monolithic kernels:

    * Traditional UNIX kernels, including the Linux kernel

Microkernels
The microkernel approach consists in defining a very simple virtual machine over the hardware, with a set of primitives or system calls to implement minimal OS services as thread management, address spaces and interprocess communication.

The main objective is the separation of basic service implementations from the operation policy of the system. For example, the process I/O locking could be implemented by a user server running on top of the microkernel. These user servers, used to carry on the system high level parts, are very modular and simplify the structure and design of the kernel. A service server that fails doesn't bring the entire system down; this simpler module can be restarted independently of the rest.

Examples of microkernels:

    * The Mach operating system
    * The Darwin kernel for Mac OS X, a variant of Mach.
    * The L4 microkernel family
    * QNX
    * BeOS
    * AIX
    * Windows NT

Monolithic kernels vs. microkernels
A monolithic kernel is much faster than a microkernel, though a microkernel can dynamically load and unload modules as needed to reduce resource usage.

In the early 1990s, monolithic kernels were considered obsolete. The design of Linux as a monolithic kernel rather than a microkernel was the topic of a famous flame war between Linus Torvalds and Andrew Tanenbaum. A summary of which can be found at http://www.dina.dk/~abraham/Linus_vs_Tanenbaum.html

However, microkernels have been found to have a number of issues which have prevented them from displacing monolithic kernels. It appears that traditional microkernels like Mach are much slower and less responsive than monolithic kernels. The best explanation for this is that optimal performance of a kernel depends on coordination between different kernel subsystems, and a microkernel architecture limits the ability to transfer information between these subsystems.

Also, the benefits of a microkernel architecture have so far been less than orginally forseen. The main claim in favor of microkernels was that by separating functions, the code would be more maintainable and understandable. However, some claim that the amount of effort in maintaining any kernel code is sufficiently high that the improvements in maintainablity generated by a microkernel architecture are marginal.

Exokernels
Exokernels are a rather radical approach to OS design. The central line of thought is, "separate protection from management".

The idea behind this is, nobody knows better how to make efficient use of available hardware but the application developer, so enable him to make the decisions. Exokernels are extremly small, since they arbitrarily limit their functionality to the protection and multiplexing of resources.

"Classic" kernel designs (both monolithic and microkernels) abstract the hardware, hiding resources under the hardware abstraction layer (HAL), or behind "trusted" servers (i.e., the servers are extensions of kernel functionality, and there is no way around them).

In these "classic" systems, if you allocate memory, you have no saying in which physical page you will be returned by the OS. If you write to a file, you have no saying on file system or physical block allocation.

It is this abstraction layer that an exokernel tries to avoid. It allows an application to request a specific piece of memory, a specific disk block etc., and merely ensures that the requested resource is free, and the application is allowed to access it.

Since an exokernel is therefore only providing a very low-level interface to the hardware, lacking any of the higher-level functionalities of other operating systems, it is augmented by a "library operating system". Such a libOS interfaces to the exokernel below, and provides application writers with the familiar functionalities of a complete OS.

This has several implications:

It is possible to have several different libOSes in the system. If, for example, you have a libOS that exports a Unix API and one exporting a Windows API, nothing keeps you from running an application linking the Windows libOS and one linking the Unix libOS, simultaneously. libOS development is done in user space - no reboots, no terminal debugging, fully memory protected. Application designers are free to replace parts, or all of the libOS with abstractions of their own, to increase performance.
回复

使用道具 举报

发表于 2003-5-5 08:11:32 | 显示全部楼层
yes, i guess vxworks is a rtos with real time as the first goal. i have a copy but never has time to use it. who know what i do everyday. what a mess.
回复

使用道具 举报

 楼主| 发表于 2003-5-6 08:57:54 | 显示全部楼层
请分析这句话:
[quote:58d1fece61="《Unix技术内幕(第五版)》(page14)"]不论是RedHat还是Solaris,用的都是微内核,尽管RedHat内核可以构建成一个单内核.[/quote]
不一定正确
回复

使用道具 举报

发表于 2003-5-6 09:09:07 | 显示全部楼层
no, i think that is wrong.
at least linus think linux is a monolithic kenrel, i agree with him.
回复

使用道具 举报

 楼主| 发表于 2003-5-6 09:16:58 | 显示全部楼层
但是这是Linus多年前的理论
或许有所改变
很多时候并不是Linus一个人说了算的
综合各种因素
微内核较为有优势,而我觉得最先进的体系结构应该是Windows NT/XP的体系:不同于经典的微内核,Windows NT将GUI和I/O系统置于核心以提高性能
市场和实际性能证明这种体系结构是成功的
回复

使用道具 举报

发表于 2003-5-6 09:37:21 | 显示全部楼层
yes, gui performance is better, but not stable, and embedded windows are still very large.
回复

使用道具 举报

 楼主| 发表于 2003-5-6 09:51:27 | 显示全部楼层
经典的操作系统理论注重操作系统是一个资源管理者,而忽视了操作系统作为一个用户接口这个事实
Unix/Linux操作系统提供给用户的只是一个shell,而GUI只当作一个普通的用户程序,可以说,这是不尊重最终用户的一种表现
在经典的Unix系统中只提供一个shell情有可原,因为受到硬件的限制,但是如今硬件已经有了革命性的变化,而操作系统仍然只提供一个shell,这就说不过去了
Linux的设计者们喜欢字符型的shell,但是大部分用户无法接受
所以Linux只能“Just for fun”
程序的稳定性和健壮性可能通过其它方式来弥补
事实证明:Windows并不见得有多不稳定
回复

使用道具 举报

 楼主| 发表于 2003-5-6 09:54:30 | 显示全部楼层
3.4   Linux 内核的类型
解决复杂性的所有方法都基于一个基本原理:问题分解和各个击破。也就是说,都是把大
型的、难以解决的问题(或系统)分解成一定数量的复杂度较低的子问题(或子系统),
再根据需要重复这一过程直到每一部分都小到可以解决为止,而各种方法只是这种原理的
一些不同运用而已。
计算机科学中有三种经典的方法比较适合于构建大型系统(我首先必须说明的是,这些定
义都是经过我深思熟虑的讨论对象)。
1) 层次(Layer)—将解决方案分解成若干部分,在这些部分中存在一个问题域的最底层
,它为上层的抽象层次较高的工作提供基础。较高层建立在其低层基础之上。OSI和
TCP/IP协议堆栈是众所周知的层次化软件设计的成功的例子。操作系统设计的层次化解决
方案可能会包含一个可以直接和硬件通讯的层次,然后在其上提供为更高层提供抽象支持
的层次。这样更高层就可以对磁盘、网卡等硬件进行访问,而并不需要了解这些设备的具
体细节。
层次化设计的一个特征是要逐步构建符号集(vocabulary)。随着层次的升高,符号集的
功能将越来越强大。层次化设计的另外一个特征是完全可以在对其上下层透明的条件下替
换某一层次。在最理想的情况下,移植层次化的操作系统只需要重写最底层的代码。纯层
次化模型实现的执行速度可能会很慢,因为高层必须(间接的)通过调用一系列连续的低
层才能处理完自己的任务—N层调用N-1层,N-1层调用N-2层,等等,直到实际的工作在0
层被处理完成。接着,结果当然是通过同样的路径反向传递回来。因此,层次化设计通常
会包含对某些高层直接和某些低层通讯的支持;这样虽然提高了速度,但是却使得各个层
次的替换工作更加困难(因为不止一个高层会直接依赖于这个你所希望进行替换的层次)

* 模块(Module)—模块将具体的一部分功能块隐藏在抽象的接口背后。模块的最大特点
是将接口和其实现分离开来,这样就能够保证一个模块可以在不影响其他模块的情况下进
行改变。这样也将模块之间的依赖关系仅仅限定于接口。模块的范围是试图反映求解域内
一些方面的自然的概念性界限。纯模块化的操作系统因而就可能有一个磁盘子系统模块,
一个内存管理子系统模块,等等。纯模块化和纯层次化的操作系统之间的主要区别是,一
个可以由其他模块自由调用,模块间没有上层和下层的概念(从这个意义上来说,模块是
广义的层次。按照纯粹的观点,层次是最多可供一个其它模块调用的模块,这个模块也就
是它的直接上层模块)。
* 对象(Object)—对象和模块不同,因为对于初学者来说它们具有不同的问题考虑方式
,实现的方法也可能各自独立。但是,就我们当前的目的来说,对象不过是结构化使用模
块的方法。组件(component)作为对象思想的进一步改进,目前还没有在操作系统设计
中广泛使用。即便如此(按照我们的观点),我们也没有足够的理由将其和模块划分在不
同的范畴中。
图3-1强调了内核的层次化的视图,而且是体系结构无关层次位于体系结构相关层次之上
(更为精确的视图是在顶层增加一个附加的体系结构相关的层次。这是因为系统调用接口
位于应用程序和内核之间,而且是体系结构相关的)。图3-2着重强调了更加模块化的内
核视图。
从合理的表述层次上看,这两种观点都是正确的。但也可以说这两种观点都是错误的。我
可以用大量的图片向你证明内核是遵从所有你所能够指出的设计原则集合的,因为它就是
从众多思想中抽取出来的。简单说来,事实是Linux内核既不是严格层次化的,也不是严
格模块化的,也不是严格意义上的任何类型,而是以实用为主要依据的(实际上,如果要
用一个词来概括Linux从设计到实现的所有特点,那么实用就是最确切的)。也许最保守
的观点是内核的实现是模块化的,虽然这些模块有时会为了追求速度而有意跨越模块的界
限。
这样,Linux的设计同时兼顾了理论和实际。Linux并没有忽视设计方法;相反,在Linux
的开发基本思想中,设计方法的作用就像是编译器:它是完成工作的有力工具。选择一个
基本的设计原则(例如对象)并完全使用这种原则,不允许有任何例外,这对于测试该原
则的限制,或者构建以说明这些方法为目的的教学系统来说都是一个不错的方法。但是如
果要用它来达到Linux的设计目标则会引起许多问题。而且Linux的设计目标中也并不包括
要使内核成为一个完全纯化的系统。Linux开发者为了达到设计目标宁愿违背妨碍目标实
现的原则。
实际上,如果对于Linux来说是正确的,那么它们对于所有最成功的设计来说都是正确的
。最成功、应用最广泛的实际系统必然是实用的系统。有些开发人员试图寻找功能强大的
可以解决所有问题的特殊方法。他们一旦找到了这种方法,所有的问题就都迎刃而解了。
像Linux内核一样的成功设计通常需要为系统的不同部分和描述上的不同层次使用不同的
方法。这样做的结果可能不是很清晰,也不是很纯粹,但是这种混合产物比同等功能的纯
粹系统要强大而且优秀得多。
Linux大部分都是单内核的
操作系统内核可能是微内核,也可能是单内核(后者有时称之为宏内核Macrokernel)。
按照类似封装的形式,这些术语定义如下:
* 微内核(microkernel)—在微内核中,大部分内核都作为独立的进程在特权状态下运
行,它们通过消息传递进行通讯。在典型情况下,每个概念模块都有一个进程。因此,如
果在设计中有一个系统调用模块,那么就必然有一个相应的进程来接收系统调用,并和能
够执行系统调用的其他进程(或模块)通讯以完成所需任务。
在这些设计中,微内核部分经常只不过是一个消息转发站:当系统调用模块要给文件系统
模块发送消息时,消息直接通过内核转发。这种方式有助于实现模块间的隔离(某些时候
,模块也可以直接给其他模块传递消息)。在一些微内核的设计中,更多的功能,如I/O
等,也都被封装在内核中了。但是最根本的思想还是要保持微内核尽量小,这样只需要把
微内核本身进行移植就可以完成将整个内核移植到新的平台上。其他模块都只依赖于微内
核或其他模块,并不直接直接依赖硬件。
微内核设计的一个优点是在不影响系统其他部分的情况下,用更高效的实现代替现有文件
系统模块将会更加容易。我们甚至可以在系统运行时将开发出的新系统模块或者需要替换
现有模块的模块直接而迅速地加入系统。另外一个优点是不需要的模块将不会被加载到内
存中,因此,微内核就可以更有效地利用内存。
* 单内核(monolithic kernel)—单内核是一个很大的进程。它的内部又可以被分为若
干模块(或者是层次或其他)。但是在运行的时候,它是一个独立的二进制大映象。其模
块间的通讯是通过直接调用其他模块中的函数实现的,而不是消息传递。
单内核的支持者声称微内核的消息传递开销引起了效率的损失。微内核的支持者则认为因
此而增加的内核设计的灵活性和可维护性可以弥补任何损失。
我并不想讨论这些问题,但必须说明非常有趣的一点是,这种争论经常会令人想到前几年
CPU领域中RISC和CISC的斗争。现代成功的CPU设计中包含了所有这两种技术,就像Linux
内核是微内核和单内核的混合产物一样。Linux内核基本上是单一的,但是它并不是一个
纯粹的集成内核。前面一章所介绍的内核模块系统将微内核的许多优点引入到Linux的单
内核设计中。(顺便提一下,我考虑过一种有趣的情况,就是Linux的内核模块系统可以
将系统内核转化成为简单的不传递消息的微内核设计。虽然我并不赞成,但是它仍然是一
个有趣的想法。)
为什么Linux必然是单内核的呢?一个方面是历史的原因:在Linus的观点看来,通过把内
核以单一的方式进行组织并在最初始的空间中运行是相当容易的事情。这种决策避免了有
关消息传递体系结构、计算模块装载方式等相关工作。(内核模块系统在随后的几年中又
进行了不断地改进。)
另外一个原因是充足的开发时间的结果。Linux既没有开发时间的限制,也没有来自于市
场压力的发行进度。 所有的限制只有并不过分的对内核的修改与扩充。内核的单一设计
在内部实现了充分的模块化,在这种条件下的修改或增加都并不怎么困难。而且问题还在
于没有必要为了追求尚未证实的可维护性的微小增长而重写Linux的内核(Linus曾多次特
别强调了如下的观点:为了这点利益而损耗速度是不值得的)。后面章节中将详细讨论充
足开发时间的效果。
如果Linux是纯微内核设计,那么向其他体系结构上的移植将会比较容易。实际上,有一
些微内核,如Mach微内核,就已经成功地证明了这种可移植性的优点。实际的情况是,
Linux内核的移植虽然不是很简单,但也绝不是不可能的:大约的数字是,向一个全新的
体系结构上的典型的移植工作需要30 000到60 000行代码,再加上不到20 000行的驱动程
序代码(并不是所有的移植都需要新的驱动程序代码)。粗略计算一下,一个典型的移植
大约平均需要50 000行代码。这对于一个程序员或者最多一个程序小组来说是力所能及的
,可以在一年之内完成。虽然这比微内核的移植需要更多的代码,但是Linux的支持者将
会提出,这样的Linux内核移植版本比微内核更能够有效地利用底层硬件,因而移植过程
中的额外工作是能够从系统性能的提高上得到补偿的。
这种特殊设计的权衡也不是很轻松就可以达到的,单内核的实现策略公然违背了传统的看
法,后者认为微内核是未来发展的趋势。但是由于单一模式(大部分情况下)在Linux中
运行状态良好,而且内核移植相对来说比较困难,但没有明显地阻碍程序员团体的工作,
他们已经成功地把内核移植到了现存的大部分实际系统中,更不用说类似掌上型电脑了。
只要Linux的众多特点仍然值得移植,新的移植版本就会不断涌现。


--
回复

使用道具 举报

 楼主| 发表于 2003-5-6 09:57:00 | 显示全部楼层
可见:Linux是一个具有某些微内核特征的单内核

怀疑《Unix技术内幕》存在翻译上的错误

因为单内核也被叫作Macrokernel
回复

使用道具 举报

发表于 2003-5-6 10:03:39 | 显示全部楼层
[quote:980e37044e="吴文官"]经典的操作系统理论注重操作系统是一个资源管理者,而忽视了操作系统作为一个用户接口这个事实
Unix/Linux操作系统提供给用户的只是一个shell,而GUI只当作一个普通的用户程序,可以说,这是不尊重最终用户的一种表现
在经典的Unix系统中只提供一个shell情有可原,因为受到硬件的限制,但是如今硬件已经有了革命性的变化,而操作系统仍然只提供一个shell,这就说不过去了
Linux的设计者们喜欢字符型的shell,但是大部分用户无法接受
所以Linux只能“Just for fun”
程序的稳定性和健壮性可能通过其它方式来弥补
事实证明:Windows并不见得有多不稳定[/quote]

but windows can only have one window manager, while linux can have many. i still think graphic is unneed to put into kernel.
回复

使用道具 举报

 楼主| 发表于 2003-5-6 10:16:55 | 显示全部楼层
单一的窗口管理的好处是:用户不需要再学习新的东西,而且更容易形成一种事实上的标准
多种不同窗口管理的好处是:用户可以选择不同的东西

事实证明MS是成功的,而RedHat也在模仿MS的作法:从RH8开始,RedHat在缩小KDE和Gnome之间的差别

对于一个应用于服务器的os来说,GUI确实是个累赘;但是对于一个就用于桌面的os来说,很有必要将GUI置入核心
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-9-19 18:52 , Processed in 0.068809 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表