微内核
微内核
微内核设计带来了良好的兼容性、扩充性、灵
活性、移植性、可靠性和网络支持。
但是,微内核设计有一个重要缺点:由于微内
核操作系统使用进程来隔离系统组件,这些组
件之间的通信使用了消息传递方式来实现一个
组件对另一个组件的调用 - 这实际上是进行
了一次RPC(例如在NT上是LPC)调用。但这
种类似RPC的方式是通过进程间通信(IPC)机制
实现的,其性能一般低于传统操作系统的系统
调用的性能。
微内核的缺陷
由于微内核操作系统的类似RPC调用是通过消息传送机
制实现的,而传统操作系统的系统调用一般是通过类
似trap的方法实现。相比于trap方法,通过消息传送机
制需要创建消息、发送消息、进程切换等更多的步骤
。这些步骤使得微内核操作系统的消息传送部分成为
一个瓶颈,其性能大大低于传统操作系统的系统调用
部分。
微内核设计导致的过多用户态和核心态之间的切换以
及过多的不同地址空间之间的切换有关。不同地址空
间之间的切换导致较高的Cache未命中率(cache-miss
rate)也是导致性能下降的重要原因。
微内核缺陷解决方法
1. 改进微内核体系结构:第二代微内核(
例如 L4 )
2. 设计其它内核结构(例如外核)
3. 把核外功能重新放回内核(例如Spin)
L4作者关于微内核的论述
THE microkernel story is full of good
ideas and blind alleys. The story began
with enthusiasm about the promised
dramatic increase in flexibility, safety,
and modularity. But over the years,
enthusiasm changed to disappointment,
because the first-generation micro-
kernels were inefficient and inflexible.
L4作者关于微内核的论述
Today, we observe radically new
approaches to the microkernel idea that
seek to avoid the old mistakes while
overcoming the old constraints on
flexibility and performance. The second-
generation micro-kernels may be a
basis for all types of operating systems,
including timesharing, multimedia, and
soft and hard real time.
第二代微内核
解决微内核设计性能问题的一个方法是扩大微
内核并把一些关键的服务程序和驱动程序重新
加入到内核中去,从而减少系统在用户态和核
心态之间的切换以及系统在不同地址空间之间
的切换。
但是,扩大内核的方法大大削弱了微内核思想
带来的优点 – 扩大的内核降低了系统的扩充性
、灵活性和可靠性。
与扩大内核的思路相反,解决微内核性能问题
的另一条思路是进一步减少内核的大小,并对
RPC调用进行直接优化。这种思路导致了被称
为第二代微内核的一些新的内核设计的出现。
L4 operating system
http://os.inf.tu-dresden.de/L4/
Originally, L4 is the name of a second-
generation µ-kernel (microkernel)
designed and implemented by Jochen
Liedtke, running on i486 and Pentium
CPUs.
However, there are now numerous
implementations of the L4 API
(application programming interface) on
several hardware architectures.
L4微内核
L4微内核的核心功能是支持一个基于消
息传送的IPC原语,以便在此基础上实现
高性能的RPC机制。在L4上实现一个RPC
调用的开销比Mach要快很多,甚至比传
统操作系统的IPC还要快。
L4微内核
L4微内核还提供了地址空间管理原语和
线程管理原语。L4的地址空间管理原语
负责内存地址空间的映射,支持三个操
作:Grant、Map和Flush。
基于这些操作,L4可以支持由不同的用
户进程以不同的策略来映射页面。
L4微内核
L4的线程管理原语使得线程调度能够由
用户进程以不同的策略来实现,从而支
持用户态的线程调度器。由于L4微内核
仅仅以7个系统调用接口就实现了以上功
能,所以只占用了12K内存。相比之下,
一个典型的第一代微内核占用300K内存
以支持140个系统调用接口。
L4微内核中断处理方式
微内核把硬件当作是一些能够发送IPC消息给
相关处理代码的线程,而把中断服务程序当作
是一些正在接收这些IPC消息的线程。当一个
硬件中断发生时,微内核会为这个中断产生一
条消息并把此消息发送到和此中断相关联的用
户进程中,然后由用户进程中的负责接收这条
IPC消息的线程来处理这个硬件中断。这样,
内核只负责产生中断消息,而不用涉及到具体
的中断处理,从而使得中断处理的具体策略和
内核隔离开来。
Operating system on L4
L4 Linux
Operating system on L4
L4 Linux
L4Linux is a port of Linux to the L4 µ-kernel. L4Linux
runs as an L4 server in user-mode, side-by-side with
other L4 applications (e.g. real-time components). It
is currently running on x86 and ARM and it is binary
compatible with the native Linux kernels.
L4-Linux puts the device drivers in one or more
virtual machines separated from the main virtual
machine that runs the rest of the operating system
and the application programs.
If a device driver crashes, only its virtual machine
goes down. The virtual machine can be rebooted and
the drivers returned to their initial state.
Operating system on L4
Mungi Single-Address-Space OS
A single address space operating system
(SASOS) on top of L4.
The goal of the project is to show that a
SASOS can work on standard hardware, can
be made as secure as traditional systems, is
not inherently less efficient that traditional
systems, and that for some classes of
important applications it delivers performance
advantages over traditional systems.
Exokernel
Exokernel微内核的核心观点是:只要内核还提
供对系统资源的抽象,就不能实现性能的最大
优化 -- 内核应该支持一个最小的、高度优化的
原语集,而不是提供对系统资源的抽象。从这
个观点上来说,IPC也是一个太高级的抽象因
而不能达到最高的性能。
Exokernel微内核的核心是支持一个高度优化的
原语名叫保护控制转移(protected control
transfer, PCT)。PCT是一个不带参数的跨地址
空间的过程调用,其功能类似于一个硬件中断
。在PCT的基础上,可以实现高级的IPC抽象如
RPC。
Exokernel philosophy
An operating system is interposed between
applications and the physical hardware.
Therefore, its structure has a dramatic impact
on the performance and the scope of
applications that can be built on it. Since its
inception, the field of operating systems has
been attempting to identify an appropriate
structure: previous attempts include the
familiar monolithic and micro-kernel operating
systems as well as more exotic language-
based and virtual machine operating systems.
Exokernel philosophy
Exokernels dramatically depart from this
previous work. An exokernel eliminates the
notion that an operating system should
provide abstractions on which applications are
built. Instead, it concentrates solely on
securely multiplexing the raw hardware: from
basic hardware primitives, application-level
libraries and servers can directly implement
traditional operating system abstractions,
specialized for appropriateness and speed.
Exokernel architecture