4.2.2 · D4Operating Systems

Exercises — OS structure — monolithic, microkernel, hybrid

2,663 words12 min readBack to topic

Level 1 — Recognition

Exercise 1.1 (L1)

Classify each kernel as Monolithic, Microkernel, or Hybrid: (a) Linux (b) MINIX 3 (c) Windows NT (d) QNX (e) macOS / XNU (f) classic UNIX.

Recall Solution 1.1

(a) Linux → Monolithic — services share kernel space, communicate by function calls. (b) MINIX 3 → Microkernel — FS/drivers are user-mode servers. (c) Windows NT → Hybrid — microkernel design but hot-path services pulled into kernel space. (d) QNX → Microkernel. (e) macOS / XNU → Hybrid — Mach microkernel core + BSD monolithic chunk. (f) classic UNIX → Monolithic. See Linux kernel modules, Windows NT architecture, XNU macOS kernel for how (a),(c),(e) are actually built.

Exercise 1.2 (L1)

In which mode does each run in a monolithic kernel: (a) the CPU scheduler, (b) a network device driver, (c) a text editor?

Recall Solution 1.2

(a) Kernel mode. (b) Kernel mode — this is the whole reason a driver bug can crash a monolithic system. (c) User mode — ordinary application.


Level 2 — Application

Exercise 2.1 (L2)

One boundary crossing costs . A read() on a monolithic kernel takes crossings; on a microkernel it takes . Compute the communication overhead for each, and the ratio microkernel/monolithic.

Recall Solution 2.1

Apply .

  • Monolithic: .
  • Microkernel: .
  • Ratio — the microkernel spends the boundary overhead here. That single number is the classic speed criticism made concrete.

Exercise 2.2 (L2)

A microkernel read() chains through two user-mode servers: app → FS server → disk-driver server, and the answer flows back the same path. Using the convention "one boundary arrow = one crossing", enumerate every crossing (forward sweep and reply sweep) and total them.

Recall Solution 2.2

We walk the request literally, arrow by arrow. Each arrow that crosses the user/kernel wall is one crossing. Look at the chain diagram (figure below) as you count.

Forward sweep (request travelling outward):

  1. app → kernel — the app traps in. (crossing 1)
  2. kernel → FS server — kernel delivers the message out to FS. (crossing 2)
  3. FS → kernel — FS forwards the request toward the driver, trapping back in. (crossing 3)
  4. kernel → disk-driver server — kernel delivers it out to the driver. (crossing 4)

At this point the driver has the data. Now the answer comes home. Crucially the reply is forwarded straight back — the driver hands the data to the kernel, and the kernel returns it to the waiting app in a single reply sweep (we do NOT re-visit the FS server, because in this model the FS is blocked waiting and the kernel routes the completed reply to the original caller):

Reply sweep (answer travelling home): 5. driver → kernel — driver returns the data, trapping in. (crossing 5) 6. kernel → app — kernel delivers the finished data out to the app. (crossing 6)

Total . This is the concrete case of the general formula derived in Exercise 4.1, and it matches Exercise 2.1's .

Reconciling with "round-trip = 4 crossings": that 4-crossing figure is for a single leaf server you bounce off (2 out + 2 back). Here the two servers are chained, not bounced independently — the forward arrows are shared by the whole chain and the reply is one sweep, so a 2-server chain is 6, not .


Level 3 — Analysis

Exercise 3.1 (L3)

Designer A claims: "Halving (faster traps) closes the gap between microkernel and monolithic." Using with monolithic , microkernel , show what halving does to the ratio and refute or support the claim.

Recall Solution 3.1

Ratio The cancels. Halving makes both faster but leaves the ratio at . So faster traps help absolute latency but do not close the structural gap — that gap is set purely by the crossing count , which is a property of the structure, not of hardware speed. Claim refuted as stated.

Exercise 3.2 (L3)

A hybrid pulls the FS server back into kernel space. In the chained microkernel of Exercise 2.2 the FS server sat at crossings 2 and 3 (kernel→FS, then FS→kernel). Co-locating FS means those two hand-offs vanish (FS is now just a kernel function call). Starting from , find the hybrid's , its at , and its speedup over the microkernel.

Recall Solution 3.2

Which crossings disappear: in the Exercise 2.2 enumeration, crossing 2 (kernel→FS) and crossing 3 (FS→kernel) exist only because FS is a separate user process. Pull FS into the kernel and those two arrows become an in-kernel function call — 0 crossings. The remaining path is app→kernel→driver→kernel→app. Remove exactly those 2 crossings: . . Speedup over microkernel . The hybrid "cheats" by co-locating the hot-path service, buying here while keeping the driver isolated. Note it is still slower than monolithic ( vs ) — hybrids sit between, exactly as the reliability/speed ordering predicts.

(This is consistent with the convention: we removed the two boundary arrows that flanked the co-located server, not a whole 4-crossing leaf round-trip, because FS was a chained middle server contributing 2 arrows.)


Level 4 — Synthesis

Exercise 4.1 (L4)

Build the crossing count from scratch for a request that touches separate user-mode servers chained app → server → server → … → server, with the answer forwarded back in a single reply sweep. Each boundary arrow is one crossing. Derive , then evaluate for .

Recall Solution 4.1

WHAT we count: every arrow that crosses the user/kernel wall, once. Trace the chain diagram (figure below).

Forward sweep — count the boundary arrows going out:

  • app → kernel → server: that is 2 crossings (trap in, deliver out).
  • For each additional server the request is forwarded server → kernel → server: that is 2 crossings per extra server. There are such forwarding steps ⇒ crossings.
  • So the forward sweep alone = crossings.

WHY the reply is only ONE sweep (not one per server): once server has the answer, it does not walk the chain backwards visiting every intermediate server again. The intermediate servers are blocked waiting on their forwarded call; the completed answer is returned up the call stack, and the microkernel routes the final finished result to the original app. Concretely, the reply is: server → kernel → app = 2 crossings, independent of . (Each intermediate server's "return" is an in-process resume, not a boundary arrow — it simply unblocks; the only boundary arrows on the reply are the last hand-off in and the final delivery out.)

Total: Check: ; (matches the FS+driver chain of Exercise 2.2!); . The formula is linear in — every extra isolated server on the forward path adds a fixed , while the reply cost stays constant. That linear growth is the microkernel's structural tax, and it's why designers minimise the number of servers on any hot path.

Exercise 4.2 (L4)

Given and monolithic constant , at what does the microkernel become the monolithic overhead?

Recall Solution 4.2

Ratio . Set . So touching 3 servers yields a 4× overhead ratio. This gives a designer a hard rule: keep hot-path server chains to if you want to stay within 2× of monolithic.


Level 5 — Mastery

Exercise 5.1 (L5)

You are designing an OS for a medical ventilator (must never crash) that also streams high-rate sensor data (needs low latency). Using and , argue for a hybrid design: which one service do you pull into kernel space and what is the quantified benefit? Assume the reliability-critical part is the FS and the latency-critical part is the sensor-driver, and pure microkernel touches both (, ).

Recall Solution 5.1

Reliability constraint says: keep as much as possible isolated (microkernel-like), so a driver bug can't kill the ventilator — the whole point of a medical device. Latency constraint says: the sensor-driver is on the hot path; pulling it into kernel space removes its round-trip. Pull only the sensor-driver into kernel space → drops from 2 to 1 → . Quantified benefit: at , goes , a speedup on the sensor path, while the FS stays isolated for safety. This is textbook hybrid reasoning: isolate the risky, co-locate the hot. Windows NT and XNU made exactly this class of choice.

Exercise 5.2 (L5)

Prove the speed ordering Monolithic Hybrid Microkernel for any request, using , , with (hybrid co-locates some servers, so it touches fewer isolated servers ).

Recall Solution 5.2

Since and is common, compare the 's.

  • , i.e. (nothing isolated).
  • Because and is increasing in : Multiplying by preserves order: Lower = faster, so Monolithic Hybrid Microkernel in speed — matching the mnemonic MONO > HYBRID > MICRO, now proved rather than memorised. Reliability is the reverse because isolated servers () contain crashes.

The picture behind the counting

The figure below is the chain we enumerated in Exercises 2.2 and 4.1. Read it left-to-right for the forward sweep (orange arrows: app traps in, kernel forwards to each server) and right-to-left for the single reply sweep (plum arrows: the finished answer returns straight to the app). Count the arrows crossing the dashed user/kernel wall and you get exactly — here gives crossings. This is the visual that makes Exercise 2.2's "6, not 8" and Exercise 3.2's "remove the 2 FS arrows" obvious at a glance.

Figure — OS structure — monolithic, microkernel, hybrid

Recall One-line self-test

Why can't faster CPUs make a microkernel beat a monolithic kernel? ::: Because the speed ratio equals and cancels — the gap is structural (crossing count), not hardware-bound.