System call without context switching

context-switchlinux-kernelprocess

I was just reading up on how linux works in my OS-book when I came across this..

[…] 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.

That sounded quite amazing to me, surely it must store the process's context before running off into kernel mode to handle an interrupt.. But ok, I'll buy it for now. A few pages on, while describing a process's scheduling context, it said:

Both system calls and interrups that occur while the process is executing will use this stack.

"this stack" being the place where the kernel stores the process's registers and such.

Isn't this a direct contradiction to the first quote? Am I missinterpreting it somehow?

Best Answer

I think the first quote is referring to the differences between a monolithic kernel and a microkernel.

Linux being monolithic, all its kernel components (device drivers, scheduler, VM manager) run at ring 0. Therefore, no context switch is necessary when performing system calls and handling interrupts.

Contrast microkernels, where components like device drivers and IPC providers run in user space, outside of ring 0. Therefore, this architecture requires additional context switches when performing system calls (because the performing module might reside in user space) and handling interrupts (to relay the interrupts to the device drivers).

Related Topic