Skip to content
CurriculumLesson 25 ยท I/O
Intermediate~12 min

Buffering & Device Drivers

Devices and the CPU run at different speeds. Buffers absorb the mismatch, and drivers hide the hardware behind a stable interface.

In plain English

A buffer is a waiting room where fast and slow workers can hand things off.

By the end you will be able to

  • Explain single, double, and circular buffering.
  • Describe the role of a device driver.
  • Distinguish blocking from non-blocking I/O.
  • Know why buffering improves throughput.
01

Buffering

A buffer is a temporary memory region between a producer and a consumer. Single buffering lets the device fill a buffer while the CPU processes the previous one only after the transfer finishes. Double buffering uses two buffers so the device can fill one while the CPU processes the other. A circular buffer is a ring of slots used for streaming data.

lesson-25.osOS
/* double buffering */
device writes buffer A
CPU processes buffer B
swap A and B
device writes buffer B
CPU processes buffer A
02

Device drivers

A device driver is kernel code that knows how to talk to a specific device. It translates a generic request such as read 4 KB into device-specific register writes, DMA setup, and interrupt handling. The rest of the kernel sees a uniform block or character device interface. Drivers are the reason the OS can support many devices without rewriting the file system for each one.

03

Blocking versus non-blocking I/O

Blocking I/O suspends the calling process until the operation completes. Non-blocking I/O returns immediately, and the process polls or waits for readiness later. Asynchronous I/O starts the operation and notifies the process on completion. The choice affects concurrency and programming complexity.

Key takeaways

  • Buffers absorb speed differences between devices and the CPU.
  • Double buffering overlaps device transfer and CPU processing.
  • Circular buffers suit streaming data.
  • Device drivers translate generic requests into device-specific operations.
  • Blocking, non-blocking, and asynchronous I/O trade simplicity for concurrency.

Common pitfalls

  • Assuming a buffer removes the need for flow control.
  • Confusing a driver with a user-space library.
  • Using blocking I/O in a single-threaded server that must serve many clients.

Kernel notes

  • Explain single versus double buffering.
  • State the driver's role in one sentence.
  • Compare blocking, non-blocking, and asynchronous I/O.

Quick check

0 / 2 answered

1. What is the main benefit of double buffering?

2. What does a device driver do?