# Courses/Computer Science/CPSC 457.S2016/Lecture Notes/L13

# Lecture 13 - File System Implementation, Disks and Final Review

## Concepts

- File Systems
- Virtual File Systems
- File Allocation

- Disks
- Disk Organization (RAID)
- Hard Disk Scheduling

- Final Review

## Slides

My slides are available as PDF PPTX or Handout PDF

## Notes

### RAID

I found three references that I think together do a good job of explaining the concepts, benefits and drawbacks of RAID:

- https://en.wikipedia.org/wiki/RAID - provides a general overview and a resource to find further resources.
- http://searchstorage.techtarget.com/definition/RAID - provides a better technical description and an illustration
- http://www.acnc.com/raid - provides another good set of illustrations and pros and cons, but keep in mind that it's a site that's selling RAID technology (which is to say corroborate what you learn).

### Disk Scheduling

Some quick examples to reinforce (and clarify) the topic from lecture.

Remember that we're looking at head movement across the cylinders, so we're moving the head from the outer edge of the disk to the inner edge. We're ignoring the time it takes for the disk to spin to the right location (rotational latency). We`re also not considering the actual time taken to move the head as it will be some fixed value / cylinder. So we only really need to know the number of cylinders traversed.

Assuming a disk with 200 cylinders, and the read head at cylinder 100, moving to cylinder 0.

The request queue is [98, 18, 187, 37, 14, 122]

#### First Come First Served

**Algorithm**

- Serve the requests in the order they arrived in.

**Execution**

- Read Head Travels to 98, 18, 187, 37, 14, 122 in order.

**Distance Traveled**

- Head starts at 100 and moves to 98. Distance Traveled = |100 - 98| = 2. Total = 2.
- Head starts at 98 and moves to 18. Distance Traveled = |98 - 18| = 80. Total = 82.
- Head starts at 18 and moves to 187. Distance Traveled = |18 - 187| = 169. Total = 251.
- Head starts at 187 and moves to 37. Distance Traveled = |187 - 37| = 169. Total = 401.
- Head starts at 37 and moves to 14. Distance Traveled = |37 - 14| = 169. Total = 424.
- Head starts at 14 and moves to 122. Distance Traveled = |14- 122| = 169. Total = 532.

So the head had to travel across 532 cylinders to serve all the requests.

**Comments**

- Fair algorithm - no job gets delayed or starved
- Inefficient - we traversed over a lot of cylinders and past requests we could have served.

#### Shortest Seek Time First (SSTF)

**Algorithm**

- Serve the request that's closest to the head right now.

**Execution**

- Read Head Travels to 98, 122, 187, 37, 18, 14 in order.

**Distance Traveled**

- Head starts at 100 and moves to 98. Distance Traveled = |100 - 98| = 2. Total = 2.
- Head starts at 98 and moves to 122. Distance Traveled = |98 - 122| = 24. Total = 26.
- Head starts at 122 and moves to 187. Distance Traveled = |122 - 187| = 65. Total = 91.
- Head starts at 187 and moves to 37. Distance Traveled = |187 - 37| = 169. Total = 260.
- Head starts at 37 and moves to 18. Distance Traveled = |37 - 18| = 19. Total = 279.
- Head starts at 18 and moves to 14. Distance Traveled = |18 - 14| = 4. Total = 283.

So the head had to travel across 283 cylinders to serve all the requests.

**Comments**

- Improved Efficiency - The head only travels the minimum distance necessary.
- Unfair algorithm - if jobs continue to arrive then it's possible that a job is never served if the new jobs are always closer to the read head.

#### SCAN (Elevator Algorithm)

**Algorithm**

- Sweep the head across the drive from one side back to the other, serving requests as we reach them.

**Execution**

- Read Head Travels to 98, 37, 18, 14, 122, 187 in order.

**Distance Traveled**

- Head starts at 100 and moves to 98. Distance Traveled = |100 - 98| = 2. Total = 2.
- Head starts at 98 and moves to 37. Distance Traveled = |98 - 37| = 61. Total = 63.
- Head starts at 37 and moves to 18. Distance Traveled = |37 - 18| = 18. Total = 82.
- Head starts at 18 and moves to 14. Distance Traveled = |18 - 14| = 4. Total = 86.
- Head starts at 14 and scans to the edge of the disk at 0. Distance Traveled = |14 - 0| = 14. Total = 100.
- Head starts at 0 and moves to 122. Distance Traveled = |0 - 122| = 122. Total = 222.
- Head starts at 122 and moves to 187. Distance Traveled = |122 - 187| = 65. Total = 287.

So the head had to travel across 287 cylinders to serve all the requests.

**Comments**

- Improved Fairness - Jobs won't wait forever and we make more efficient use of the disk.
- Inefficient? - as request arrive, assuming they're uniformly spread across the disk, when the head turns it will not serve many requests since it mostly cleared the area of the disk out.

#### C-SCAN (Circular Scan)

**Algorithm**

- Sweep the head across the drive from one side to the other at the end reset to the first edge of the disk, serving requests as we reach them.

**Execution**

- Read Head Travels to 98, 37, 18, 14, 187, 122 in order.

**Distance Traveled**

- Head starts at 100 and moves to 98. Distance Traveled = |100 - 98| = 2. Total = 2.
- Head starts at 98 and moves to 37. Distance Traveled = |98 - 37| = 61. Total = 63.
- Head starts at 37 and moves to 18. Distance Traveled = |37 - 18| = 18. Total = 82.
- Head starts at 18 and moves to 14. Distance Traveled = |18 - 14| = 4. Total = 86.
- Head starts at 14 and scans to the edge of the disk at 0. Distance Traveled = |14 - 0| = 14. Total = 100.
- Head starts at 0 and returns to the other edge of the disk at 200. Distance Traveled = |0 - 200| = 200. Total = 300.
- Head starts at 200 and moves to 187. Distance Traveled = |200 - 187| = 13. Total = 313.
- Head starts at 187 and moves to 122. Distance Traveled = |187 - 122| = 65. Total = 387.

So the head had to travel across 387 cylinders to serve all the requests.

**Comments**

- Still fair, but as jobs continue to come in, we should now be serving a more consistent number of jobs.

#### LOOK

**Algorithm**

- Sweep the head across the drive from one side back to the other, serving requests as we reach them. Stopping at the last request in a direction.

**Execution**

- Read Head Travels to 98, 37, 18, 14, 122, 187 in order.

**Distance Traveled**

- Head starts at 100 and moves to 98. Distance Traveled = |100 - 98| = 2. Total = 2.
- Head starts at 98 and moves to 37. Distance Traveled = |98 - 37| = 61. Total = 63.
- Head starts at 37 and moves to 18. Distance Traveled = |37 - 18| = 18. Total = 82.
- Head starts at 18 and moves to 14. Distance Traveled = |18 - 14| = 4. Total = 86.
- Head starts at 14 and moves to 122. Distance Traveled = |14 - 122| = 108. Total = 194.
- Head starts at 122 and moves to 187. Distance Traveled = |122 - 187| = 65. Total = 259.

So the head had to travel across 259 cylinders to serve all the requests.

**Comments**

- Slightly more efficient, so long as we don`t mind the extra overhead of checking where our jobs are (we can skip actually checking the job locations in SCAN).

#### C-LOOK (Circular Look)

**Algorithm**

- Sweep the head across the drive and reset to the first request on the other edge after the last request on this edge of the disk, serving requests as we reach them.

**Execution**

- Read Head Travels to 98, 37, 18, 14, 187, 122 in order.

**Distance Traveled**

- Head starts at 100 and moves to 98. Distance Traveled = |100 - 98| = 2. Total = 2.
- Head starts at 98 and moves to 37. Distance Traveled = |98 - 37| = 61. Total = 63.
- Head starts at 37 and moves to 18. Distance Traveled = |37 - 18| = 18. Total = 82.
- Head starts at 18 and moves to 14. Distance Traveled = |18 - 14| = 4. Total = 86.
- Head starts at 14 and moves to 187. Distance Traveled = |14 - 187| = 13. Total = 259.
- Head starts at 187 and moves to 122. Distance Traveled = |187 - 122| = 65. Total = 324.

So the head had to travel across 324 cylinders to serve all the requests.

**Comments**

- As with LOOK, more efficient than C-SCAN, so long as we don`t mind the overhead of actually looking at the request queue.