Operating-Systems-Notes

I/O Management

Operating system

I/O Device Features

Device drivers

Types of devices

OS representation of a device : special device file

UNIX like systems:

Linux supports a number of pseudo “virtual” devices that provide special functionality to a system.

CPU device interactions

iointeractions.png

access device registers : memory load/store

  1. Memory mapped I/0
    • part of ‘host’ physical memory dedicated for device interactions
    • Base Address Registers (BAR)
  2. I/O Port
    • dedicated in low instructions for device access
    • target device (I/0 port) and value in register

Path from Device to CPU

  1. Interrupt
    • Overhead: Interrupt handling steps
    • +: Can be generated as soon as possible
  2. Polling
    • Overhead: Delay or CPU overhead
    • when convenient for OS

Device access : Programmed I/O (PIO)

E.g. 1500B packet; 8 byte registers or bus => 1(for bus command) + 188(for data) = 189 CPU store instructions

Direct Memory Access (DMA)

E.g. 1500B packet; 8 byte registers or bus => 1(for bus command) + 1(for DMA configuration) = total 2 CPU store instructions. Less steps, but DMA configuration is more complex.

For DMAs

Typical Device Access

typicaldeviceaccess.png

OS bypass

osbypass.png

What happens to a calling thread?

access.png

Block Device Stack

Block device typical storage for files:

blockdevicestack.png

Virtual File System

vfs.png

Virtual File System Abstractions

VFS on disk

Inodes

Index of all disk blocks corresponding to a file

+: Easy to perform sequential or random access
-: Limit on file size

Inodes with indirect pointers

+: Small inode => large file size
-: File access slowdown

Disk access optimizations

Reducing file access overheads

  1. Caching/buffering : reducenumber of disk accesses
    • buffer cache in main menu
    • read/write from cache
    • periodically flush to disk - fsync()
  2. I/O scheduling : reduce disk head movement
    • maximize sequential vs random access
  3. Prefetching : increases cache hits
    • leverages locality
  4. Journaling/logging: reduce random access (ext3, ext4)
    • “describe” write in log : block, offset, value..
    • periodically apply updates to proper disk locations