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.
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]
Disk error handling and formatting
2082 ยท 5 marks
Describe about error handling and formatting in disk management. [5]
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 answerHide 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
| From | To | Distance |
|---|---|---|
| 143 | 25 | 118 |
| 25 | 17 | 8 |
| 17 | 119 | 102 |
| 119 | 197 | 78 |
| 197 | 194 | 3 |
| 194 | 15 | 179 |
| 15 | 182 | 167 |
| 182 | 115 | 67 |
| 115 | 183 | 68 |
$$\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.
| Current | Nearest pending options | Chosen | Distance |
|---|---|---|---|
| 143 | 119 (24), 115 (28), 182 (39) | 119 | 24 |
| 119 | 115 (4), 182 (63), 183 (64) | 115 | 4 |
| 115 | 182 (67), 183 (68), 25 (90) | 182 | 67 |
| 182 | 183 (1), 194 (12), 197 (15) | 183 | 1 |
| 183 | 194 (11), 197 (14) | 194 | 11 |
| 194 | 197 (3), 25 (169) | 197 | 3 |
| 197 | 25 (172), 17 (180) | 25 | 172 |
| 25 | 17 (8), 15 (10) | 17 | 8 |
| 17 | 15 (2) | 15 | 2 |
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
| Algorithm | Total Head Movement |
|---|---|
| FCFS | 790 cylinders |
| SSTF | 292 cylinders |
SSTF greatly reduces head movement versus FCFS, at the risk of starvation for distant requests.
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]
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]
Memory mapped I/O
2080 ยท 5 marks
What is memory mapped I/O? Explain about device independent I/O software. [5]
RAID definition and levels
2079 ยท 5 marks
What is RAID? Explain Level-2 and Level-3 RAID. [5]
DMA working mechanism
DMA definition and purpose
2078 ยท 5 marks
What is DMA? Explain how it works in brief with suitable diagram. [5]
Show solved answerHide 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
| Component | Role |
|---|---|
| DMA Controller (DMAC) | Manages the data transfer independently |
| Source Address Register | Holds the source memory/device address |
| Destination Address Register | Holds the destination memory address |
| Count Register | Holds the number of bytes/words to transfer |
| Control Register | Specifies 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.
Make Unit 9 stick
Practice BIT204 with flashcards & quizzes