Sub topic 2
SCAN, C-SCAN, LOOK and C-LOOK
This chapter assumes you know what a cylinder is, how seek time works, and how FCFS and SSTF order disk requests. Head movement is counted in cylinders crossed.
SCAN, C-SCAN, LOOK and C-LOOK
SCAN
SCAN (the "elevator" algorithm) sweeps the head in one direction, serves requests as it passes them, and reverses only at the disk edge. For the queue 98, 183, 37, 122, 14, 124, 65, 67 with the head at 53 moving toward cylinder 0, SCAN travels to 0 and then up to 183, a total of 236 cylinders.
C-SCAN
C-SCAN serves requests in one direction only. At the end of a sweep, the head returns to the start edge without serving requests, which gives more uniform waiting times.
LOOK and C-LOOK
LOOK works like SCAN but reverses at the last pending request instead of the disk edge. For the same queue, with the head moving down first, LOOK turns at 14 and goes up to 183: 39 + 169 = 208 cylinders.
C-LOOK is the one-directional version of LOOK. After serving 14, the head jumps to 65, the lowest pending request above it, and sweeps up to 183: 39 + 51 + 118 = 208 cylinders. The jump counts as head movement.
def look_down_first(head, requests):
low = [r for r in requests if r <= head]
high = [r for r in requests if r > head]
total = 0
pos = head
if low:
total += head - min(low)
pos = min(low)
if high:
total += max(high) - pos
return total
def clook_down_first(head, requests):
low = [r for r in requests if r <= head]
high = [r for r in requests if r > head]
total = 0
pos = head
if low:
total += head - min(low)
pos = min(low)
if high:
total += abs(min(high) - pos) # jump back to lowest upward request
total += max(high) - min(high) # sweep up to the highest request
return total
queue = [98, 183, 37, 122, 14, 124, 65, 67]
print(look_down_first(53, queue)) # 208
print(clook_down_first(53, queue)) # 208Choosing a scheduling algorithm
SSTF has a low average seek, but requests far from the head can starve. SCAN and C-SCAN bound the wait for every request. LOOK and C-LOOK usually beat them because they skip travel to the disk edge. Choose C-LOOK when uniform waiting matters.
RAID in brief
RAID combines several disks for speed or redundancy. RAID 0 stripes data with no redundancy. RAID 1 mirrors data. RAID 5 stripes data with distributed parity and survives one disk failure. Each level trades capacity, redundancy and write speed.
SSDs and seek-based scheduling
An SSD has no moving head, so seek time is near zero and reads cost about the same from any address. Seek-based scheduling therefore matters less on SSDs.
Files: attributes and operations
A file has a name, type, location, size, protection and timestamps. The core operations are create, open, read, write, seek, close and delete.
File access methods
Sequential access reads records in order. Direct access reads any block by its number. Indexed access looks up a key in an index and then reads the matching record.
Directory structures
A single-level directory puts all files in one directory. A two-level directory gives each user a directory. A tree allows nested directories. An acyclic graph lets files be shared through links, but it must avoid cycles.
File system layout and in-memory tables
On disk, a volume holds a boot control block, a volume control block, a directory structure and per-file control blocks (inodes). In memory, the OS keeps a system-wide open-file table and a per-process table that stores each open file's pointer.
Exercise
Exercise
The queue is 98, 183, 37, 122, 14, 124, 65, 67, the head is at 53, and the head moves down first. What is the LOOK total head movement?
Show answer
208 cylinders. The head moves 53 to 14 (39), then 14 to 183 (169).