当我遇到这个时,我刚刚在我的操作系统书籍中阅读了 Linux 如何工作的内容..
[...] the kernel is created as a single, monolitic binary. The main reason is to improve performance. Because all kernel code and data structures are kept in a single address space, no context switches are necessary when a process calls an operating-system function or when a hardware interrup is delivered.
这对我来说听起来相当惊人,当然它必须在运行到内核模式来处理中断之前存储进程的上下文。但是好吧,我现在就买它。有几页在描述进程的调度上下文时说:
Both system calls and interrups that occur while the process is executing will use this stack.
“这个堆栈”是内核存储进程寄存器等的地方。
这不是与第一句话直接矛盾吗?我是否误解了它?
最佳答案
我认为第一句话是指单片内核和 microkernel 之间的差异.
Linux 是整体的,其所有内核组件(设备驱动程序、调度程序、VM 管理器)都运行在 ring 0 。因此,在执行系统调用和处理中断时不需要上下文切换。
对比微内核,其中设备驱动程序和 IPC 提供程序等组件在 user space 中运行,在环 0 之外。因此,该架构在执行系统调用(因为执行模块可能驻留在用户空间)和处理中断(将中断中继到设备驱动程序)时需要额外的上下文切换。
关于process - 没有上下文切换的系统调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8878557/