6 Device Management

Operating Systems ยท Unit 6 ยท 6 hrs

Device Management

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

Device Management in short

This chapter covers device management: how the operating system classifies and drives the input and output hardware attached to a computer, the mechanisms (programmed I/O, interrupts, DMA) used to move data between devices and memory, and the disk-specific scheduling and formatting techniques that keep the slowest common device performing well.

Device Management: notes

Classification of IO devices

I/O devices fall into three broad classes based on how the operating system talks to them.

  • Block devices (also called machine readable devices) communicate by sending or receiving whole blocks of data, each independently addressable and readable or writable on its own; hard disks, USB drives and tape drives are examples.
  • Character devices (also called user readable devices) communicate by sending or receiving a stream of individual characters with no block structure and no seek capability; keyboards, mice, serial ports, printers and sound cards are examples.
  • Communication devices transmit an analog or digital signal over a wire or wirelessly so computers can talk to each other; a modem is the standard example.

Controllers

An I/O unit typically has a mechanical part and an electronic part; the electronic part is called the device controller (or adapter), and one controller can often drive several devices, though some devices bundle their own dedicated controller. A controller exposes one or more registers that the processor reads and writes to issue commands and check status. The controller's job includes converting the raw serial bit stream coming off the device into a block of bytes, assembling that block bit by bit inside an internal buffer, checking its checksum, and only then copying the verified, error-free block into main memory.

Memory Mapped IO

Under memory mapped I/O, each device control register is given its own address inside the normal memory address space (typically near the top of the address space), so the CPU can read and write a device register using ordinary memory instructions rather than special I/O instructions. The operating system allocates a memory buffer and tells the device to use it, after which the device operates asynchronously with the CPU and interrupts it only when the transfer is finished; this makes memory mapped I/O well suited to high-speed devices such as disks and communication interfaces.

  • Advantage: device access can be programmed in an ordinary high level language such as C, with no special protection mechanism required beyond normal memory protection.
  • Disadvantage: it adds extra complexity to both the hardware address decoding and the operating system's memory map.

DMA Operation

Direct Memory Access (DMA) transfers data between memory and an I/O device under the control of a dedicated DMA controller, without the CPU being involved in moving each individual byte; most I/O data does not need to pass through the CPU for processing, so letting a DMA controller move it directly saves CPU time and is more efficient. A PCI controller and a hard drive controller each typically have their own set of DMA channels.

The DMA transfer proceeds as follows: the CPU first programs the DMA controller's registers with the transfer direction, the memory address, and the byte count; once valid data sits in the device's own buffer, the DMA controller issues a read (or write) request over the system bus to the device controller; data moves directly between the device controller and memory; on completion of each unit of transfer the device controller acknowledges the DMA controller, which increments its memory address and decrements its remaining byte count, repeating until the count reaches zero; and finally, once the whole transfer is complete, the DMA controller interrupts the CPU to signal that the data is ready.

Interrupts

An interrupt is the hardware mechanism a device uses to get the CPU's attention, forcing it to stop its current work and switch to handling the event that just occurred. Interrupts fall into three kinds.

  • Hardware interrupts are raised by devices to signal that they need attention, for instance because they have just received data or finished a requested transfer between the device and memory.
  • Software interrupts are raised deliberately by a running program to request that the operating system perform a system call on its behalf.
  • Traps are raised by the CPU itself, to flag an error or exceptional condition (such as division by zero or an invalid memory access) that needs the operating system's intervention.

What this unit covers

  • Classification of IO devices
  • Controllers
  • Memory Mapped IO
  • DMA Operation
  • Interrupts
  • Goals of IO Software
  • Handling IO(Programmed IO, Interrupt Driven IO, IO using DMA)
  • IO Software Layers (Interrupt Handlers, Device Drivers)
  • Disk Structure
  • Disk Scheduling (FCFS, SSTF, SCAN, CSCAN, LOOK, CLOOK)
  • Disk Formatting (Cylinder Skew, Interleaving, Error handling)
  • RAID

Disk Scheduling

2081 ยท 10 marks

Find the seek time using SCAN, C-SCAN, Look and C-Look disk scheduling algorithms for processing the following request queue: 35, 70, 45, 15, 65, 20, 80, 90, 75, 130. Suppose the disk has tracks numbered from 0 to 150 and assume the disk arm to be at 30 and moving outward.[10]

Show solved answer

Disk Scheduling Algorithms - Verified Solution

Given Data

  • Request Queue: 35, 70, 45, 15, 65, 20, 80, 90, 75, 130
  • Track range: 0 to 150
  • Initial head position: 30
  • Direction: Outward (toward higher tracks)

Sorted requests: 15, 20, 35, 45, 65, 70, 75, 80, 90, 130


1. SCAN

Head moves outward to 150, then reverses to service lower requests.

Order: 30 โ†’ 35 โ†’ 45 โ†’ 65 โ†’ 70 โ†’ 75 โ†’ 80 โ†’ 90 โ†’ 130 โ†’ 150 โ†’ 20 โ†’ 15

Total distance = (150 โˆ’ 30) + (150 โˆ’ 15) = 120 + 135 = 255 tracks


2. C-SCAN

Head moves outward to 150, jumps to 0, then continues servicing.

Order: 30 โ†’ 35 โ†’ ... โ†’ 130 โ†’ 150 โ†’ 0 โ†’ 15 โ†’ 20

Total = (150 โˆ’ 30) + (150 โˆ’ 0) + (20 โˆ’ 0) = 120 + 150 + 20 = 290 tracks

(Equivalently, summing the individual steps: 5+10+20+5+5+5+10+40+20+150+15+5 = 290.)


3. LOOK

Head moves outward only to the last request (130), then reverses.

Order: 30 โ†’ 35 โ†’ ... โ†’ 130 โ†’ 20 โ†’ 15

Total = (130 โˆ’ 30) + (130 โˆ’ 15) = 100 + 115 = 215 tracks


4. C-LOOK

Head moves outward to last request (130), jumps to lowest request (15), continues outward.

Order: 30 โ†’ 35 โ†’ ... โ†’ 130 โ†’ 15 โ†’ 20

MovementFromToDistance
130355
2354510
3456520
465705
570755
675805
7809010
89013040
913015115
1015205

Total = (130 โˆ’ 30) + (130 โˆ’ 15) + (20 โˆ’ 15) = 100 + 115 + 5 = 220 tracks


Summary

AlgorithmSeek Time (tracks)
SCAN255
C-SCAN290
LOOK215
C-LOOK220
Open this answer on its own page โ†’

2080 ยท 5 marks

Suppose a disk has 201 cylinders, numbered from 0 to 200. At same time the disk arm is at cylinder 10, and there is a queue of disk access requests for cylinders 30, 85, 90, 100, 105, 110, 135, and 145. Find the total seek time for the disk scheduling algorithm FCFS and SSTF. Assume the head is moving inward. [5]

  • Total cylinders: 201 (numbered 0 to 200) - Initial head position: cylinder 10 - Request queue (order of arrival): 30, 85, 90, 100, 105, 110, 135, 145 - Head moving inward (toward higher cylinder numbers) --- Requests served in arrival order: $$10 \to 30 \to 85 \to 90 \to 100 \to 105 \to 110 \to...
Open this answer on its own page โ†’

2079 ยท 10 marks

Define shell and system call. Suppose a disk has 201 cylinders, numbered from 0 to 200. At same time the disk arm is at cylinder 95, and there is a queue of disk access requests for cylinders 82,170,43,140,24,16 and 190. Calculate the seek time for the disk scheduling algorithm FCFS,SSTF,SCAN and C-SCAN.[10]

Show solved answer

Shell, System Call, and Disk Scheduling

Part 1: Definitions

Shell

A shell is a command interpreter that provides the interface between the user and the operating system kernel. It accepts user commands, interprets them, and hands them to the OS for execution. It also lets users run programs, manage files, and control processes. Examples: Bash, sh, csh, zsh.

System Call

A system call is the programmatic interface through which a user process requests a service from the OS kernel. It transfers control from user mode to kernel mode for privileged operations. Examples: fork(), exec(), read(), write(), open().


Part 2: Disk Scheduling

Given data:

  • Cylinders: 201 (numbered 0 to 200)
  • Head start: 95
  • Queue (arrival order): 82, 170, 43, 140, 24, 16, 190

1. FCFS

Order: $95 \to 82 \to 170 \to 43 \to 140 \to 24 \to 16 \to 190$

$$|95-82|+|82-170|+|170-43|+|43-140|+|140-24|+|24-16|+|16-190|$$ $$= 13+88+127+97+116+8+174 = \boxed{623}$$


2. SSTF

StepPosClosestDist
1958213
2824339
3432419
424168
516140124
614017030
717019020

Order: $95 \to 82 \to 43 \to 24 \to 16 \to 140 \to 170 \to 190$

$$13+39+19+8+124+30+20 = \boxed{253}$$


3. SCAN (moving up toward 200)

Sorted: $16, 24, 43, 82, [95], 140, 170, 190$

Order: $95 \to 140 \to 170 \to 190 \to 200 \to 82 \to 43 \to 24 \to 16$

$$45+30+20+10+118+39+19+8 = \boxed{289}$$

Total = $(200-95) + (200-16) = 105 + 184 = 289$ โœ“


4. C-SCAN (moving up toward 200, then wrap to 0)

Order: $95 \to 140 \to 170 \to 190 \to 200 \to 0 \to 16 \to 24 \to 43 \to 82$

FromToDist
9514045
14017030
17019020
19020010
2000200
01616
16248
244319
438239

$$45+30+20+10+200+16+8+19+39 = \boxed{387}$$


Summary

AlgorithmTotal Seek (cylinders)
FCFS623
SSTF253
SCAN289
C-SCAN387
Open this answer on its own page โ†’

2076 ยท 10 marks

What is the main objective of disk scheduling algorithms? Why SSTF is not practically feasible? Assume that we have disk with 100 tracks and currently head is at track number 35. What will be the seek time for the algorithms SCAN and LOOK for processing IO requests queue: 52, 67, 21, 11, 43, 85, 18, 75, 92, 8?[10]

Show solved answer

Disk Scheduling: Objectives, SSTF Feasibility, SCAN and LOOK

1. Main Objective of Disk Scheduling Algorithms

The primary objective of disk scheduling is to minimize the total seek time (the time the disk arm spends moving between tracks), because seek time dominates disk access latency and the disk is one of the slowest components of a system.

Related objectives:

  • Maximize throughput (requests served per unit time)
  • Minimize disk arm movement by ordering requests intelligently
  • Ensure fairness so no request starves
  • Minimize average response and waiting time

2. Why SSTF Is Not Practically Feasible

SSTF (Shortest Seek Time First) always services the request nearest to the current head position.

  • Starvation: Requests far from the head may wait indefinitely if closer requests keep arriving. This is the main reason it is not practically feasible.
  • Unfairness: Requests to the innermost/outermost tracks are consistently delayed.
  • Not globally optimal: Minimizing each local step does not minimize total head movement.
  • Unpredictable response time: Hard to guarantee bounded waiting.

Because of starvation and unfairness, SSTF is attractive theoretically but unsuitable in practice.

3. Numerical Solution

Given data:

  • Total tracks: 100 (tracks $0$ to $99$)
  • Current head position: 35
  • Request queue: 52, 67, 21, 11, 43, 85, 18, 75, 92, 8
  • Assumed initial direction: toward higher track numbers (standard assumption)

Sorted requests: 8, 11, 18, 21, 43, 52, 67, 75, 85, 92


SCAN (Elevator)

Head moves up, servicing all requests, reaches end track 99, then reverses to service lower requests.

Order: $35 \to 43 \to 52 \to 67 \to 75 \to 85 \to 92 \to 99 \to 21 \to 18 \to 11 \to 8$

FromToDistance
35438
43529
526715
67758
758510
85927
92997
992178
21183
18117
1183

Alternatively, total movement = (up: $99-35=64$) + (down: $99-8=91$) = $155$.

$$\text{Total Seek (SCAN)} = 8+9+15+8+10+7+7+78+3+7+3 = \mathbf{155 \text{ tracks}}$$


LOOK

Same as SCAN but the head only goes as far as the last request (92) in the upward direction, not to track 99.

Order: $35 \to 43 \to 52 \to 67 \to 75 \to 85 \to 92 \to 21 \to 18 \to 11 \to 8$

FromToDistance
35438
43529
526715
67758
758510
85927
922171
21183
18117
1183

Alternatively, total movement = (up: $92-35=57$) + (down: $92-8=84$) = $141$.

$$\text{Total Seek (LOOK)} = 8+9+15+8+10+7+71+3+7+3 = \mathbf{141 \text{ tracks}}$$


Summary

AlgorithmTotal Seek Time
SCAN155 tracks
LOOK141 tracks

(If seek time per track is $t$ ms, multiply by $t$: SCAN $=155t$, LOOK $=141t$.)

Open this answer on its own page โ†’

Memory Mapped IO

2081 ยท 5 marks

Explain memory-mapped I/O. [5]

Memory-mapped I/O is a method of performing input/output operations in which each I/O device's control register is assigned a unique memory address, to which no actual RAM is assigned. In most systems, these assigned addresses are located at the top of the address space or near the top of the add...

Open this answer on its own page โ†’

Interrupts

2080 ยท 5 marks

What are the advantages of using interrupt? Describe. [5]

"The hardware mechanism that enables a device to notify the CPU is called an interrupt. Interrupt forces CPU to stop what it is doing and start doing something else. Interrupts are signals sent to the CPU by external devices, normally I/O devices." --- In Programmed I/O, the CPU continuously poll...

Open this answer on its own page โ†’

DMA Operation

2079 ยท 5 marks

Describe the working mechanism of DMA. [5]

DMA (Direct Memory Access) is a hardware mechanism that allows I/O devices to transfer data directly to or from main memory without involving the CPU for each byte of the transfer. This frees the CPU to perform other tasks during data transfer. --- - DMA Controller: A dedicated hardware unit that...

Open this answer on its own page โ†’

2080.1 ยท 10 marks

How DMA operation is performed? Consider a disk with 200 tracks and the queue has random requests from different processes in the order: 45, 48, 29, 17, 80, 150, 28 and 188. Find the seek time using FIFO, SSTF and SCAN. Assume the initial position of head as 100.[10]

  • Total tracks: 200 (numbered 0 to 199) - Request queue (in order): 45, 48, 29, 17, 80, 150, 28, 188 - Initial head position: 100 --- Direct Memory Access (DMA) is an I/O technique in which a dedicated hardware controller transfers data directly between an I/O device and main memory, freeing the ...
Open this answer on its own page โ†’

Controllers

2079 ยท 5 marks

What is the task of disk controller? List some drawback of segmentation. [5]

--- A disk controller is a hardware component that acts as an interface between the CPU/memory and the physical disk drive. Its main tasks are: 1. Receiving Commands from CPU: The disk controller accepts read/write commands from the CPU or DMA controller and translates them into low-level operati...

Open this answer on its own page โ†’

Disk Formatting

2078 ยท 5 marks

Why the concept of disk interleaving is important? Explain with suitable example. [5]

--- Disk interleaving (also called sector interleaving) is a technique used to improve disk read/write performance by arranging the logical order of sectors on a disk track differently from their physical order. Instead of numbering sectors consecutively (0, 1, 2, 3...), sectors are numbered with...

Open this answer on its own page โ†’

Handling IO

2076 ยท 5 marks

When programmed IO is suitable than other IO handling techniques? Explain the process of IO handling using DMA. [5]

--- Programmed I/O is the simplest form of I/O where the CPU does all the work. It directly controls the I/O operation including sensing device status, sending read/write commands, and transferring data. Programmed I/O is suitable in the following situations: Condition Reason ------ Few I/O devic...

Open this answer on its own page โ†’