As a model, we can map the multi-layered, two-dimensional platters that make up the hard-drive to a linear, one-dimensional array. We can imagine that both the disk head and the data of interest are tracked by two respective pointers in this one-dimensional array. "b" is the data location while "h" is our current location on disk.
By this logic, the cost of a seek is |b-h|. This approximation tends to overestimate long seeks and underestimate short seeks due to the nonlinear nature of the disk head movements; in particular, acceleration time becomes more negligible with larger distances, but maintains a more prominent role in shorter distances.
First come, first serve means we queue and service requests in order. Assuming that we are undergoing random access, and that both b and h are random, what's the average cost of an access?
Let's take a look at an example. Assume process #1 and process #2 wish to concurrently read data from the disk. Process #1 wants to read blocks 1000, 1001, 1002, 1003... (sequentially located blocks). Process #2 wants to read blocks 91631, 28193, 1572, 69317 (random, non-contiguous blocks).
The graph on the left shows process #1 and process #2's interleaved seeks using FCFS. Notice the large amount of disk head movement during every time interval. The graph on the right shows a different approach. All of process #1's requests are completed before starting process #2's. The result is that during process #1's execution, the disk can utilize sequential reading, which is much faster than the random seeking that process #2 requests.
SSTF will always schedule the request that is closest to the disk head.
The elevator algorithm is the same as SSTF, except that the head will service the closest request that can be reached when moving in a particular direction. In other words, the Boelter elevator that has just moved up from the 4th to the 5th floor will continue servicing requests all the way up to the 9th floor, while ignoring new requests from the bottom 4 floors. Once it reaches the highest requested floor, the elevator will make its descent, servicing floor requests in descending (SSTF) order.
A drawback of the elevator algorithm is that the edges (floors 1 and 9) have an average wait time of 1 cycle, while the middle floors have an average wait time of 0.5 cycles. (The middle floors get serviced twice: once on the descent, and once on the ascent).
The circular elevator algorithm connects both edges together as if the head is always moving in a particular direction. In this case, the Boelter elevator will reach the 9th floor, immediately drop to the 1st floor, and then service floor requests in ascending order. This scheduling scheme is fair to all processes but comes at a performance cost - resources are being idly wasted during the "drop" portion of the algorithm.
In the anticipatory algorithm, we want to design the file system such that it will speculate on what a process will do and delay (DALLY).
From the example, envision a scenario where we just read the first thousand blocks in a process. After finishing the read, there is only 1 (far) read request that is pending in the system. Instead of servicing that request, the algorithm would delay for a particular unit of time (0.1 milliseconds) in hopes of a request coming in that would be cheaper to service.
However, starvation is still an issue. If, for example, process 1 had a very long queue of sequential blocks, then process 2 would succumb to starvation. To reconcile this issue, the schedule typically keeps track of long-waiting requests with a timer to ensure that they too get serviced.
File systems require a data structure that lives on disk and provides an abstraction (illusion) of a set of organized files. Modern file systems span many different physical devices, including hard disks, flash-based storage, and network components (local or cloud servers). Each of these components has a performance limiting factor.
"...before he knew any better!"
This file system is similar to an array where each file starts on a sector boundary. It turns out that this file system was similar to RT-11, an existing file system.
size%512
is wasted in each file, assuming 512 byte file size)-1
: indicates a free block 0
: indicates end of file N
: indicates the number of the next block in the filelseek
requires O(N) of timestat()
to find out more on this. In addition, inodes do not contain the file name nor the directory containing it.$ ln a b
And even if we do: $ rm a
file b will still be accessible because the link count will still be greater than 0.$ dd if=/etc/passwrd of=big seek=10T
To see the block size and number of block used, one can then use
$ ls -l big
The problem with holes will be when the file is being copied such as
$ cat big
This will result in a extremely large amount of data blocks full of holes being cat
'ed.The Berkeley file system is extremely similar to the UNIX file system, but it also adds a block bit map. This allows the file system to know whether a data block is free.
BSD still succumbs to external (similar to FAT) and internal fragmentation.