9 Input Output And Disk Management

Operating Systems ยท Unit 9

Input Output and Disk Management

Exam-focused notes for Input Output and Disk Management (Operating Systems, BIT204): what the TU syllabus asks and how it has actually been tested, with 10 solved past questions from this unit.

Input Output and Disk Management in short

The OS must control many different input and output devices. This chapter covers device controllers, ways of doing I/O, disk scheduling and RAID.

Input Output and Disk Management: notes

Device controller definition

An I/O device has a mechanical part and an electronic part. The electronic part is the device controller (or adapter). It is a small circuit board that controls the device and talks to the CPU through the system bus.

A controller has:

  • Registers: command, status and data registers that the CPU reads and writes.
  • A buffer: a small memory that holds data while it moves between device and memory.

Example: a disk controller reads a block from the disk, checks it for errors, and puts it in its buffer. The OS then uses a device driver, which is software that knows how to talk to one kind of controller.

DMA definition and purpose

Direct Memory Access (DMA) is a method where a special controller moves data between a device and memory. The CPU is not used for every byte.

Purpose:

  • Free the CPU from copying large amounts of data.
  • Make transfer of blocks (disk, network) fast.
  • Let the CPU do other work during the transfer.

Without DMA, the CPU would take an interrupt for every byte or word. That wastes much time on fast devices.

DMA working mechanism

The CPU starts the transfer, and the DMA controller does the rest.

  1. The CPU programs the DMA controller with the memory address, the byte count and the direction (read or write).
  2. The CPU tells the device controller to start.
  3. The DMA controller moves data between the device and memory.
  4. It steals cycles from the CPU. This means it uses the bus when the CPU is not using it, or takes a short turn on the bus.
  5. It decreases the byte count after each transfer, and increases the memory address.
  6. When the count reaches zero, the DMA controller sends one interrupt to the CPU.

The CPU is interrupted only once for the whole block instead of once per byte.

Memory mapped I/O

In memory mapped I/O, the registers and buffers of a device are given addresses in the normal memory address space. The CPU uses ordinary load and store instructions to talk to a device.

Advantages:

  • No special I/O instructions are needed.
  • Device code can be written in C, without assembly.
  • The same protection method as memory can protect devices.

Disadvantages:

  • Part of the address space is used by devices.
  • Caching of device registers must be turned off.

In port mapped I/O (isolated I/O), devices have a separate address space and special instructions such as IN and OUT.

What this unit covers

  • Device controller definition
  • DMA definition and purpose
  • DMA working mechanism
  • Memory mapped I/O
  • Interrupt based I/O
  • DMA based I/O comparison
  • Device independent I/O software
  • Disk scheduling algorithms
  • RAID definition and levels
  • Disk error handling and formatting

Device controller definition

2082 ยท 10 marks

Discuss about controller and memory mapped I/O.Differentiate between interrupt based I/O and DMA based I/O.[5+5]

Note: No specific curriculum notes were found for this topic. The answer below is based on standard, correct Computer Organization and Architecture concepts as taught in BSc CSIT programs. --- (a) Controller and Memory Mapped I/O An I/O Controller (also called a device controller) is a hardware i...

Open this answer on its own page โ†’

Disk error handling and formatting

2082 ยท 5 marks

Describe about error handling and formatting in disk management. [5]

Note: The reference notes did not contain specific content on this topic. The following answer is based on standard Operating Systems concepts as taught in BSc CSIT curriculum. --- Disk formatting is the process of preparing a disk for use by the operating system. It is done in two stages: - Divi...

Open this answer on its own page โ†’

Disk scheduling algorithms

2080 ยท 5 marks

Suppose that a disk drive has the cylinder numbered, 0 to 199 is currently serving a request at cylinder 143. The request queue is kept in the FIFO order 25, 17, 119, 197, 194, 15, 182, 115, and 183. What is the total head movement needed to satisfy these request for the following disk scheduling algorithm. a) FCFS b) SSTF [5]

Show solved answer

Disk Scheduling: FCFS and SSTF

Given Data

  • Cylinder range: 0 to 199
  • Current head position: 143
  • Request queue (FIFO): 25, 17, 119, 197, 194, 15, 182, 115, 183

a) FCFS (First Come First Served)

Service order: 143 โ†’ 25 โ†’ 17 โ†’ 119 โ†’ 197 โ†’ 194 โ†’ 15 โ†’ 182 โ†’ 115 โ†’ 183

FromToDistance
14325118
25178
17119102
11919778
1971943
19415179
15182167
18211567
11518368

$$\text{Total} = 118+8+102+78+3+179+167+67+68 = 790$$

FCFS total head movement = 790 cylinders


b) SSTF (Shortest Seek Time First)

Always move to the nearest pending request.

At every step the head jumps to whichever pending cylinder is closest, so the distances to all remaining requests are compared before each move.

CurrentNearest pending optionsChosenDistance
143119 (24), 115 (28), 182 (39)11924
119115 (4), 182 (63), 183 (64)1154
115182 (67), 183 (68), 25 (90)18267
182183 (1), 194 (12), 197 (15)1831
183194 (11), 197 (14)19411
194197 (3), 25 (169)1973
19725 (172), 17 (180)25172
2517 (8), 15 (10)178
1715 (2)152

Service order: 143 โ†’ 119 โ†’ 115 โ†’ 182 โ†’ 183 โ†’ 194 โ†’ 197 โ†’ 25 โ†’ 17 โ†’ 15

$$\text{Total} = 24+4+67+1+11+3+172+8+2 = 292$$

SSTF total head movement = 292 cylinders

Note that 119 has to be taken before 115, since $|143-119| = 24$ is smaller than $|143-115| = 28$. Servicing 115 first would violate the shortest-seek rule even though the two requests sit close together.


Summary

AlgorithmTotal Head Movement
FCFS790 cylinders
SSTF292 cylinders

SSTF greatly reduces head movement versus FCFS, at the risk of starvation for distant requests.

Open this answer on its own page โ†’

2078 ยท 10 marks

Suppose that a disk has 100 cylinders, numbered 0 to 99. The drive is currently serving a request at cylinder 45. The queue of pending request, in FIFO order is: 88, 72, 13, 74, 48, 9, 22, 50, 35 and 30. What is the total distance (in cylinders) that the disk arm moves to satisfy all pending request for each of the following disk scheduling algorithms? a) FCFS b) SCAN c) SSTF[10]

  • Total cylinders: 0 to 99 (100 cylinders) - Current head position: 45 - FIFO request queue: 88, 72, 13, 74, 48, 9, 22, 50, 35, 30 --- Serve in FIFO order: $45 \to 88 \to 72 \to 13 \to 74 \to 48 \to 9 \to 22 \to 50 \to 35 \to 30$ Move Distance ---------------- 45โ†’88 43 88โ†’72 16 72โ†’13 59 13โ†’74 61 ...
Open this answer on its own page โ†’

0 ยท 10 marks

When does interrupt concur? Suppose that a disk drive has the cylinder numbered from 0 to 199. The head is currently at cylinder number 53. The queue for services of cylinders is as 99, 183, 37, 122, 14, 124, 65 and 67. What is the total head movement in each of following disk algorithm to satisfy the requests? (a) FCFS (b) SSTF (c) SCAN[10]

An interrupt is a signal to the CPU from hardware or software indicating that an event needs immediate attention. When an interrupt occurs, the CPU suspends the currently executing process, saves its state, and transfers control to an Interrupt Service Routine (ISR). Interrupts occur in the follo...

Open this answer on its own page โ†’

Memory mapped I/O

2080 ยท 5 marks

What is memory mapped I/O? Explain about device independent I/O software. [5]

Memory Mapped I/O is a method of performing input/output operations between the CPU and peripheral devices in which the I/O devices are mapped into the same address space as the main memory. - In this scheme, a portion of the memory address space is reserved for I/O device registers (control, sta...

Open this answer on its own page โ†’

RAID definition and levels

2079 ยท 5 marks

What is RAID? Explain Level-2 and Level-3 RAID. [5]

RAID (Redundant Array of Independent Disks) is a data storage technology that combines multiple physical disk drives into a single logical unit to achieve one or more of the following goals: - Improved performance (through parallelism/striping) - Fault tolerance / reliability (through redundancy)...

Open this answer on its own page โ†’

DMA working mechanism

2079 ยท 5 marks

Explain the working mechanism of DMA. [5]

DMA (Direct Memory Access) is a technique that allows I/O devices to transfer data directly to/from main memory without involving the CPU for each byte/word of the transfer. A dedicated hardware unit called the DMA Controller manages this transfer. --- Component Role ------ DMA Controller Manages...

Open this answer on its own page โ†’

DMA definition and purpose

2078 ยท 5 marks

What is DMA? Explain how it works in brief with suitable diagram. [5]

Show solved answer

Direct Memory Access (DMA)

Definition

DMA (Direct Memory Access) is a feature of computer systems that allows certain hardware subsystems (such as disk controllers, network cards, or sound cards) to access main memory (RAM) independently of the CPU. It enables data transfer between I/O devices and memory without continuous CPU involvement, freeing the CPU to perform other tasks during the transfer.


Why DMA is Needed

Without DMA, the CPU must supervise every byte transferred between an I/O device and memory (programmed I/O), which wastes CPU cycles. DMA offloads this work to a dedicated DMA Controller (DMAC).


Key Components

ComponentRole
DMA Controller (DMAC)Manages the data transfer independently
Source Address RegisterHolds the source memory/device address
Destination Address RegisterHolds the destination memory address
Count RegisterHolds the number of bytes/words to transfer
Control RegisterSpecifies direction and mode of transfer

How DMA Works (Step-by-Step)

Step 1: CPU Initialization

  • The CPU programs the DMA controller by providing:
    • Source address
    • Destination address
    • Number of bytes to transfer
    • Direction of transfer (read/write)
  • The CPU then continues its own tasks.

Step 2: DMA Request

  • The I/O device signals the DMAC that it is ready to transfer data (via DMA Request line - DREQ).

Step 3: Bus Request

  • The DMAC requests control of the system bus from the CPU by asserting the Bus Request (BR) signal.

Step 4: Bus Grant

  • The CPU completes its current bus cycle and grants the bus to the DMAC by asserting Bus Grant (BG). The CPU is now temporarily disconnected from the bus (CPU is in a "hold" state).

Step 5: Data Transfer

  • The DMAC takes control of the address bus, data bus, and control bus.
  • Data is transferred directly between the I/O device and memory, one block at a time, without CPU involvement.
  • The address and count registers are updated after each transfer.

Step 6: Transfer Complete

  • When the count reaches zero (all data transferred), the DMAC sends an interrupt to the CPU to notify it that the transfer is complete.
  • The CPU resumes control of the bus.

Diagram

        +------------------+
        |       CPU        |
        +--------+---------+
                 |  BR / BG (Bus Request / Bus Grant)
                 |
        +--------+---------+
        |  DMA Controller  |<-------- DREQ (from I/O Device)
        | (Source Addr Reg)|
        | (Dest  Addr Reg) |
        | (Count Reg)      |
        +---+----------+---+
            |          |
     Address/Data/Control Bus
            |          |
    +-------+--+    +--+--------+
    |  Main    |    | I/O Device|
    |  Memory  |    | (Disk,NIC)|
    +----------+    +-----------+

Data Flow:

I/O Device  ----[DMA Controller]---->  Main Memory
                  (No CPU needed
                   during transfer)

Advantages of DMA

  • CPU is free to execute other instructions during data transfer.
  • Faster data transfer compared to programmed I/O or interrupt-driven I/O.
  • Suitable for high-speed, bulk data transfers (e.g., disk to memory).

Summary

DMA allows I/O devices to transfer data directly to/from memory by temporarily taking control of the system bus, with the CPU only involved at the start (initialization) and end (interrupt) of the transfer.

Open this answer on its own page โ†’

0 ยท 5 marks

How does DMA help in I/O management? Explain. [5]

Direct Memory Access (DMA) is a technique that allows I/O devices to transfer data directly to or from main memory without the continuous involvement of the CPU. A special hardware unit called the DMA controller manages these transfers. --- Without DMA, the CPU must handle every byte/word of data...

Open this answer on its own page โ†’