operating systems Disk Management 1 operating systems Goals

  • Slides: 54
Download presentation
operating systems Disk Management 1

operating systems Disk Management 1

operating systems Goals of I/O Software Provide a common, abstract view of all devices

operating systems Goals of I/O Software Provide a common, abstract view of all devices to the application programmer (open, read, write) Provide as much overlap as possible between the operation of I/O devices and the CPU. 2

operating systems I/O – Processor Overlap Application programmers expect serial execution semantics read (device,

operating systems I/O – Processor Overlap Application programmers expect serial execution semantics read (device, “%d”, x); y = f(x); We expect that this statement will complete before the assignment is executed. To accomplish this, the OS blocks the process until the I/O operation completes. 3

read(device, %D”, x); y = f(x); … operating systems User Process READ Device Independent

read(device, %D”, x); y = f(x); … operating systems User Process READ Device Independent Layer Without Blocking! The read completes is has issued. not and Completed the value … but of xthe is updated. process continues to execute. CPU Device Dependent Layer Interrupt Handler data status command Device Controller 12 x 5 4

operating systems In a multi-programming environment, another application could use the cpu while the

operating systems In a multi-programming environment, another application could use the cpu while the first application waits for the I/O to complete. Request I/O operation I/O Complete app 2 done app 1 app 2 I/O controller 5

operating systems Performance Thread execution time can be broken into: • Time compute The

operating systems Performance Thread execution time can be broken into: • Time compute The time thread spends doing computations • Time device The time spent on I/O operations • Time overhead The time spent determining if I/O is complete So, Time total = Time compute + Time device + Time overhead 6

operating systems Performance When the device driver polls Time overhead total = Time compute

operating systems Performance When the device driver polls Time overhead total = Time compute + Time device + Time overhead = The period of time between the point where the device completes the operation and the point where the polling loop determines that the operation is complete. This is generally just a few instruction times. Note that when the device driver polls, no other process can use the cpu. Polling consumes the cpu. 7

Are you done yet? 8

Are you done yet? 8

Performance operating systems When the device driver uses interrupts Time total = Time compute

Performance operating systems When the device driver uses interrupts Time total = Time compute + Time device + Time overhead When the device driver uses interrupts Time overhead = Time handler + Time ready Time handler is the time spent in the interrupt handler Time ready is the time the process waits for the cpu after it has completed its I/O, while another process uses the CPU. 9

operating systems For simplicity’s sake assume processes of the following form: Each process computes

operating systems For simplicity’s sake assume processes of the following form: Each process computes for a long while and then writes its results to a file. We will ignore the time taken to do a context switch. process Time compute Request an I/O operation I/O controller Time compute device 10

Polling Case Time operating systems Time device Time compute compute Proc 1 polls Time

Polling Case Time operating systems Time device Time compute compute Proc 1 polls Time Proc 2 device overhead Proc 2 polls Proc 1 Time overhead In the polling case, the process starts the I/O operation, and then continually loops, asking the device if it is done. 11

Interrupt Case Time operating systems Time Proc 1 Proc 2 Time overhead interrupt handler

Interrupt Case Time operating systems Time Proc 1 Proc 2 Time overhead interrupt handler Time compute device compute Time In the interrupt case, the process starts the I/O operation, and then blocks. When the I/O is done, the os will get an interrupt. compute Time device 12

Which gives better system throughput? * Polling * Interrupts Which gives better application performance?

Which gives better system throughput? * Polling * Interrupts Which gives better application performance? * Polling * Interrupts If you were developing an operating system, would you choose interrupts or polling? 13

Buffering Issues operating systems User space Kernel Read from the disk Into user memory

Buffering Issues operating systems User space Kernel Read from the disk Into user memory Assume that you are using interrupts… What problems Exist in this situation? 14

Buffering Issues operating systems User space Kernel Read from the disk Into user memory

Buffering Issues operating systems User space Kernel Read from the disk Into user memory Assume that you are using interrupts… What problems Exist in this situation? The process cannot be completely swapped out of memory. At least the page containing the addresses into which the data is being written must remain in real memory. 15

Buffering Issues operating systems User space Kernel Read from the disk into kernel buffer.

Buffering Issues operating systems User space Kernel Read from the disk into kernel buffer. When the buffer is full, transfer to memory in user space. 16

Buffering Issues operating systems User space Kernel We can now swap the user processor

Buffering Issues operating systems User space Kernel We can now swap the user processor out While the I/O completes. What problems Exist in this situation? 1. The O/S has to carefully keep track of the assignment of system buffers to user processes. 2. There is a performance issue when the user process is not in memory and the O/S is ready to transfer its data to the user process. Also, the device must wait while data is being transferred. 3. The swapping logic is complicated when the swapping operation uses the same disk drive for paging that the data is being read from. 17

operating systems Buffering Issues User space Kernel Some of the performance issues can be

operating systems Buffering Issues User space Kernel Some of the performance issues can be addressed by double buffering. While one buffer is being transferred to the user process, the device is reading data into a second buffer. 18

operating systems Networking may involve many copies 19

operating systems Networking may involve many copies 19

operating systems Disk Scheduling Because Disk I/O is so important, it is worth our

operating systems Disk Scheduling Because Disk I/O is so important, it is worth our time to investigate some of the issues involved in disk I/O. One of the biggest issues is disk performance. 20

seek time is the time required for the read head to move to the

seek time is the time required for the read head to move to the track containing the data to be read. 21

rotational delay or latency, is the time required for the sector to move under

rotational delay or latency, is the time required for the sector to move under the read head. 22

operating systems Performance Parameters seek Wait for device Wait for Channel rotational delay (latency)

operating systems Performance Parameters seek Wait for device Wait for Channel rotational delay (latency) data transfer Device busy Seek time is the time required to move the disk arm to the specified track Transfer Time Rotational delay is the time required for the data on that track to come ~ underneath the read heads. For T = #/ tracks * disk constant + startup time) ( rotation_speed * bytes_on_track s a hard T drive rotating at 3600 rpm, the average rotational t = bytes delay will be 8. 3 ms. 23

operating systems Data Organization vs. Performance Consider a file where the data is stored

operating systems Data Organization vs. Performance Consider a file where the data is stored as compactly as possible, in this case the file occupies all of the sectors on 8 adjacent tracks (32 sectors x 8 tracks = 256 sectors total). The time to read the first track will be average seek time rotational delay read 32 sectors 20 ms 8. 3 ms 16. 7 ms 45 ms Assuming that there is essentially no seek time on the remaining tracks, each successive track can be read in 8. 3 + 16. 7 ms = 25 ms. Total read time = 45 ms + 7 * 25 ms = 220 ms = 0. 22 seconds 24

operating systems If the data is randomly distributed across the disk: For each sector

operating systems If the data is randomly distributed across the disk: For each sector we have average seek time rotational delay read 1 sector 20 ms 8. 3 ms 0. 5 ms 28. 8 ms Total time = 256 sectors * 28. 8 ms/sector = 7. 73 seconds Random placement of data can be a problem when multiple processes are accessing the same disk. 25

operating systems In the previous example, the biggest factor on performance is ? Seek

operating systems In the previous example, the biggest factor on performance is ? Seek time! To improve performance, we need to reduce the average seek time. 26

Queue operating systems Request If requests are scheduled in random order, then we would

Queue operating systems Request If requests are scheduled in random order, then we would expect the disk tracks to be visited in a random order. … 27

Queue operating systems Request … First-come, First-served Scheduling If there are few processes competing

Queue operating systems Request … First-come, First-served Scheduling If there are few processes competing for the drive, we can hope for good performance. • If there a large number of processes competing for the drive, then performance approaches the random scheduling case. 28

While at track 15, assume some random set of read requests -- tracks 4,

While at track 15, assume some random set of read requests -- tracks 4, 40, 11, 35, 7 and 14 operating systems Track 40 30 Head Path Tracks Traveled 15 to 4 4 to 40 40 to 11 11 to 35 35 to 7 7 to 14 11 steps 36 steps 29 steps 24 steps 28 steps 7 steps 135 steps 20 10 50 100 Steps 29

Queue operating systems Shortest Seek Time First Request … Always select the request that

Queue operating systems Shortest Seek Time First Request … Always select the request that requires the shortest seek time from the current position. 30

operating systems While at track 15, assume some random set of read requests --

operating systems While at track 15, assume some random set of read requests -- tracks 4, 40, 11, 35, 7 and 14 Shortest Seek Time First Track Head Path Tracks Traveled 40 30 20 10 50 Problem? 100 Steps In a heavily loaded system, incoming requests with a shorter seek time will constantly push requests with long seek times to the end of the queue. This results in what is called “Starvation”. 31

Queue operating systems Request The elevator algorithm (scan-look) Request … Search for shortest seek

Queue operating systems Request The elevator algorithm (scan-look) Request … Search for shortest seek time from the current position only in one direction. Continue in this direction until all requests have been satisfied, then go the opposite direction. In the scan algorithm, the head moves all the way to the first (or last) track with a request before it changes direction. 32

operating systems While at track 15, assume some random set of read requests Track

operating systems While at track 15, assume some random set of read requests Track 4, 40, 11, 35, 7 and 14. Head is moving towards higher numbered tracks. Scan-Look Track Head Path Tracks Traveled 40 30 20 10 50 100 Steps 33

Which algorithm would you choose if you were implementing an operating system? Issues to

Which algorithm would you choose if you were implementing an operating system? Issues to consider when selecting a disk scheduling algorithm: Performance is based on the number and types of requests. What scheme is used to allocate unused disk blocks? How and where are directories and i-nodes stored? How does paging impact disk performance? How does disk caching impact performance? 34

operating systems Disk Cache The disk cache holds a number of disk sectors in

operating systems Disk Cache The disk cache holds a number of disk sectors in memory. When an I/O request is made for a particular sector, the disk cache is checked. If the sector is in the cache, it is read. Otherwise, the sector is read into the cache. 35

operating systems Replacement Strategies Least Recently Used replace the sector that has been in

operating systems Replacement Strategies Least Recently Used replace the sector that has been in the cache the longest, without being referenced. Least Frequently Used replace the sector that has been used the least 36

RAID Redundant Array of Independent Disks • Push Performance • Add reliability 37

RAID Redundant Array of Independent Disks • Push Performance • Add reliability 37

operating systems strip 0 RAID Level 0: Striping strip 1 Physical Drive 1 strip

operating systems strip 0 RAID Level 0: Striping strip 1 Physical Drive 1 strip 2 strip 3 strip 4 strip 5 strip 6 strip 7 strip 8 Physical Drive 2 strip 0 strip 1 strip 2 strip 3 strip 4 strip 5 strip 6 strip 7 ooo A Stripe strip 9 strip 10 strip 11 Disk Management Software ooo Logical Disk 38

RAID Level 1: Mirroring High Reliability operating systems strip 0 strip 1 strip 2

RAID Level 1: Mirroring High Reliability operating systems strip 0 strip 1 strip 2 Physical Drive 1 strip 3 strip 0 strip 1 strip 4 strip 2 strip 3 strip 5 strip 4 strip 5 strip 6 strip 7 ooo ooo Physical Drive 2 Physical Drive 3 Physical Drive 4 strip 8 strip 9 strip 10 strip 11 Disk Management Software ooo Logical Disk 39

RAID Level 3: Parity High Throughput operating systems strip 0 strip 1 strip 2

RAID Level 3: Parity High Throughput operating systems strip 0 strip 1 strip 2 Physical Drive 1 strip 3 strip 0 strip 1 strip 2 0 strip para 1 strip 4 strip 3 2 strip 4 3 strip 5 2 strip parb 3 strip 5 strip 6 4 strip 7 5 strip 8 4 strip parc 5 strip 6 strip 9 6 strip 10 7 strip 11 6 strip pard 7 strip 7 ooo ooo strip 8 Physical Drive 2 Physical Drive 3 Physical Drive 4 parity strip 9 strip 10 strip 11 Disk Management Software ooo Logical Disk 40

Thinking About What You Have Learned 41

Thinking About What You Have Learned 41

operating systems Suppose that 3 processes, p 1, p 2, and p 3 are

operating systems Suppose that 3 processes, p 1, p 2, and p 3 are attempting to concurrently use a machine with interrupt driven I/O. Assuming that no two processes can be using the cpu or the physical device at the same time, what is the minimum amount of time required to execute three processes, given the following (ignore context switches): Process 1 2 3 Time compute 10 30 15 Time 50 10 35 device 42

Process 1 2 3 Time compute 10 30 15 Time 50 10 35 device

Process 1 2 3 Time compute 10 30 15 Time 50 10 35 device p 3 p 2 P 1 0 10 20 30 40 50 60 70 80 90 100 110 120 130 105 43

Consider the case where the device controller is double buffering I/O. That is, while

Consider the case where the device controller is double buffering I/O. That is, while the process is reading a character from one buffer, the device is writing to the second. What is the effect on the running time of the process is I/O bound and requests characters faster than the device can provide them? Process A B Device Controller The process reads from buffer A. It tries to read from buffer B, but the device is still reading. The process blocks until the data has been stored in buffer B. The process wakes up and reads the data, then tries to read Buffer A. Double buffering has not helped performance. 44

Consider the case where the device controller is double buffering I/O. That is, while

Consider the case where the device controller is double buffering I/O. That is, while the process is reading a character from one buffer, the device is writing to the second. What is the effect on the running time of the process is Compute bound and requests characters much slower than the device can provide them? Process A B Device Controller The process reads from buffer A. It then computes for a long time. Meanwhile, buffer B is filled. When The process asks for the data it is already there. The process does not have to wait and performance improves. 45

Suppose that the read/write head is at track 97, moving toward the highest numbered

Suppose that the read/write head is at track 97, moving toward the highest numbered track on the disk, track 199. The disk request queue contains read/write requests for blocks on tracks 84, 155, 103, 96, and 197, respectively. How many tracks must the head step across using a FCFS strategy? 46

Suppose that the read/write head is at track 97, moving toward the highest numbered

Suppose that the read/write head is at track 97, moving toward the highest numbered track on the disk, track 199. The disk request queue contains read/write requests for blocks on tracks 84, 155, 103, 96, and 197, respectively. How many tracks must the head step across using a FCFS strategy? Track 97 to 84 84 to 155 to 103 to 96 96 to 197 199 150 13 steps 71 steps 52 steps 7 steps 101 steps 244 steps 100 50 100 200 Steps 47

Suppose that the read/write head is at track 97, moving toward the highest numbered

Suppose that the read/write head is at track 97, moving toward the highest numbered track on the disk, track 199. The disk request queue contains read/write requests for blocks on tracks 84, 155, 103, 96, and 197, respectively. How many tracks must the head step across using an elevator strategy? 48

Suppose that the read/write head is at track 97, moving toward the highest numbered

Suppose that the read/write head is at track 97, moving toward the highest numbered track on the disk, track 199. The disk request queue contains read/write requests for blocks on tracks 84, 155, 103, 96, and 197, respectively. How many tracks must the head step across using an elevator strategy? Track 97 to 103 to 155 to 197 to 199 to 96 96 to 84 199 150 6 steps 52 steps 42 steps 103 steps 12 steps 217 steps 100 50 100 200 Steps 49

In our class discussion on directories it was suggested that directory entries are stored

In our class discussion on directories it was suggested that directory entries are stored as a linear list. What is the big disadvantage of storing directory entries this way, and how could you address this problems? Consider what happens when look up a file … The directory must be searched in a linear way. 50

Which file allocation scheme discussed in class gives the best performance? What are some

Which file allocation scheme discussed in class gives the best performance? What are some of the concerns with this approach? Contiguous allocation schemes gives the best performance. Two big problems are: * Finding space for a new file (it must all fit in contiguous blocks) * Allocating space when we don’t know how big the file will be, or handling files that grow over time. 51

What is the difference between internal and external fragmentation? Internal fragmentation occurs when only

What is the difference between internal and external fragmentation? Internal fragmentation occurs when only a portion of a File block is used by a file. External fragmentation occurs when the free space on a disk does not contain enough space to hold a file. 52

Linked allocation of disk blocks solves many of the problems of contiguous allocation, but

Linked allocation of disk blocks solves many of the problems of contiguous allocation, but it does not work very well for random access files. Why not? To access a random block on disk, you must walk Through the entire list up to the block you need. 53

Linked allocation of disk blocks has a reliability problem. What is it? If a

Linked allocation of disk blocks has a reliability problem. What is it? If a link breaks for any reason, the disk blocks after The broken link are inaccessible. 54