UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department | ||
CS 537
Spring 2001 | A. Arpaci-Dusseau | |
Quiz #8: April 25th -- File Systems |
Name: Solutions | Student ID #: Solutions |
This question/answer is straight from the lecture notes:
1. To adjust to different transfer rates between a producer (e.g., a disk) and a consumer (e.g., an application running on the CPU). By having multiple buffers, work can be overlapped: the producer can be filling one buffer while the consumer uses the contents of a previous buffer.
2. To adjust to different transfer sizes. For example, files may be read from disk in only block-size units; if an application reads a smaller amount than this, the full block-size must still be read (and buffered).
3. Copy semantics. If the application uses a non-blocking interface to I/O (e.g., a write() call that returns immediately, before the buffer has actually been written to disk), the OS must copy the buffer to another location so that the application can modify the contents of the buffer after the write() call returns.
The i-nodes are already cached in memory (in the file buffer), so they do not need to be read from disk. Only the actual data blocks need to be read from disk. To lookup file /a/b/c we search through each directory until we find the i-node number for the next directory or file. The following disk reads of data-blocks are needed:
1. We know that the root directory in Unix has i-node number 2. This i-node is in memory so this doesn't yet involve a disk read. The i-node contains the pointers to the data-blocks for the a directory (remember, the directory is stored as simply a file.) Given the asummption that each directory file is only one block long, we only have to read one data-block to read the contents of the root directory. This is our first disk read. In this data, we search for directory "a" and get its i-node number, x.
2. We look at i-node number x (in memory) and get the block number (i.e., the pointer) for the data. We read this data (the second read), search this directory for the directory "b" and get its i-node number, y.
3. We look at i-node number y (in memory) and get the block number for the data. We read this data (the third read) and search this directory for the file "c"; we see its i-node number and are done.
Thus, a total of three disk reads are required.
_H_ When B is created, the reference count in the i-node of A is incremented. _B_ When the contents of A are changed, the contents of B change as well. _B_ When the contents of B are changed, the contents of A change as well. _H_ When A is removed (e.g., with "rm A"), B still exists. _B_ When B is removed (e.g., with "rm B"), A still exists. _S_ A and B can be directories. _S_ Can be used to create cycles in the directory hierarchy.
_c_ Linked a. Single pointer to file-data and its size _d_ Indexed b. Array containing multiple pointers and their sizes _a_ Contiguous c. Pointer to first block of file _b_ Extent-based d. Array containing pointers to every block of file
A)What is the largest possible file that can be supported with this design? Show your work (as an expression) to make sure you get credit; if your expression is correct, you will get full credit (i.e., you shouldn't calculate the final numeric answer!).
Each direct pointer points to 4KB of data, for a total of 10*4KB.
The indirect pointer points to an indirect block that contains pointers to data. The indirect block is a 4KB block filled with 4-byte pointers, for a total of 1024 pointers. Thus, the indirect pointer can refer to 1024*4KB of data.
Similarly, the double-indirect pointer points a double-indirect block containing 1024 pointers to indirect blocks, each of which points to 4KB*1024 for a total of 1024*1024*4KB of data.
Finally, the triple-indirect pointer refers to 1024*1024*1024*4KB.
The total data is thus 10*4KB + 1024*4KB + 1024*1024*4KB + 1024*1024*1024*4KB.
B) Assume that the operating system has already read the i-node for your file into main memory (i.e., the file buffer cache). How many disk reads are required to read data block number 800 into memory? To assure full credit, describe each disk read.
Data-block number 800 will fall in the set of blocks accessible from the indirect block (blocks 10 - 1033). One disk read is required to read the indirect block and one disk read is required to read the actual data, for a total of two disk reads.