Sie sind auf Seite 1von 19

Operating Systems 6 File Systems

Lab notes
Course lectured by Prof. Gabriel Kuper Lab assist. Ilya Zaihrayeu http://www.dit.unitn.it/~ilya/os.htm

File allocation strategies


Q: Consider a file currently consisting of 100 blocks. Assume that the file control block (and the index block, in the case of indexed allocation) is already in memory. Calculate how many disk I/O operations are required for contiguous, linked, and indexed (singlelevel) allocation strategies, if, for one block, the following conditions hold. In the contiguous-allocation case, assume that there is no room to grow in the beginning, but there is room to grow in the end. For the linked allocation assume that the file control block stores the disk addresses of the first and the last block in the file. Assume that the block information to be added is stored in memory. a) The block is added at the beginning. b) The block is added in the middle. c) The block is added at the end. d) The block is removed from the beginning. e) The block is removed from the middle. f) The block is removed from the end.
Ilya Zaihrayeu Operating Systems Course

Recall: file allocation strategies

contiguous

linked indexed
Ilya Zaihrayeu Operating Systems Course

File allocation strategies, contd A:


Operations: read blocks + write blocks + write the file control block
Contiguous a) b) c) d) e) f) 100r + 102w=202 50r + 52w = 102 0r + 2w = 2 99r + 100w =199 49r + 50w = 99 50r + 51w = 101 0r + 1w = 1 Linked 0r + 2w = 2 50r + 2w = 52 1r + 3w = 4 1r + 1w = 2 50r + 1w = 51 51r + 1w = 52 99r + 2w = 101 Indexed 0r + 2w = 2 0r + 2w = 2 0r + 2w = 2 0r + 1w = 1 0r + 1w = 1 0r + 1w = 1

Ilya Zaihrayeu

Operating Systems Course

File allocation strategies-2


Q: One way to use contiguous allocation of the disk and not suffer from holes is to compact the disk every time a file is removed. Since all files are contiguous, copying a file requires a seek and rotational delay to read the file, followed by the transfer at full speed. Writing the file back requires the same work. a) Assuming a seek time of 5 msec, a rotational delay of 4 msec, a transfer rate of 8 MB/sec, and an average file size of 8 KB, how long does it take to read a file into main memory then write it back to the disk at a new location? b) Using these numbers, how long would it take to compact half of a 16-GB disk?
Ilya Zaihrayeu Operating Systems Course

File allocation strategies-2, contd A: a) Time to read a file = seek time + latency time + read time = 5 msec + 4 msec + 8 KB / (8 * 1024 KB / 1 * 1000 msec) 0.98 msec Therefore read + write = 2 * 0.98 msec = 1.96 msec b) Half of a 16-GB disk is 8 GB = 8 388 608 KB That is approximately 1 048 576 files. Each file takes 1.96 msec, thus the whole process will take about 2055 sec, i.e. about 34 min
Ilya Zaihrayeu Operating Systems Course

Free disk space management Q: Free disk space can be kept track of using a free list or a bit map. Disk addresses require D bits. For a disk with B blocks, F of which are free, state the condition under which the free list uses less space than the bit map. For D having the value 16 bits, express your answer as a percentage of the disk space that must be free.
Ilya Zaihrayeu Operating Systems Course

Free disk space management, contd A: The bit map requires B blocks, whereas the free list requires F*D bits. Thus the state when the free list uses less space than the bit map is F*D < B. The percentage of disk space free is given by the fraction F/B. F*D less than B becomes F/B less than 1/D. If D is 16, then this fraction is 1/16 or 6.25 percent
Ilya Zaihrayeu Operating Systems Course

File system consistency


Q: A file system checker has built up its counters as shown bellow Are there any errors? If so, are they serious? Why? How to fix them?

In use free

0 1 0

1 1 0

2 0 0

3 1 0

4 0 2

5 1 0

6 2 0

7 1 0

8 1 0

9 10 11 12 13 14 15 0 0 1 1 1 0 0 1 1 0 1 0 1 1

Ilya Zaihrayeu

Operating Systems Course

Recall: file system consistency


Initially: Checking i-nodes: if a block is referenced, its number In use is incremented Checking free lists or bit maps: if a block is referenced, its number free is incremented If the system is consistent, each block will have 1 either in In use or in free (in this example the system is inconsistent)
Ilya Zaihrayeu

In use free

0 0 0 0 0 0

1 0 0 1 2 0

2 0 0 2 0 0

3 0 0 3 1 0

4 0 0 4 0 0

5 0 0 5 0 0

6 0 0 6 0 0

In use free

In use free

0 0 1

1 2 0

2 0 1

3 1 0

4 0 1

5 0 1

6 0 1

In use free

0 0 1

1 2 0

2 0 1

3 1 0

4 0 1

5 0 1

6 0 1

Operating Systems Course

10

File system consistency, contd


A:

Block 2 is not reported in either table (missing block). Not serious, but wastes space. Add it to the free list Block 4 is twice in a free list. Not serious at the moment. Just fix the free list Block 6 is present in 2 files at the same time. If a file is removed then the block will appear in the both lists. The solution is to allocate a free block, copy the contents of 6 there, and insert the copy onto one of the files Block 12 is present in the both lists. Remove it from the free list
In use free
Ilya Zaihrayeu

0 1 0

1 1 0

2 0 0

3 1 0

4 0 2

5 1 0

6 2 0

7 1 0

8 1 0

9 10 11 12 13 14 15 0 0 1 1 1 0 0 1 1 0 1 0 1 1
11

Operating Systems Course

Free memory space management


Q: The beginning of a free space bitmap looks like this after the disk partition is first formatted: 1000 0000 0000 0000 (the first block is used by the root directory). The system always searches for free blocks starting at the lowest numbered block, so after writing file A, which uses 6 blocks, the bitmap looks like this: 1111 1110 0000 0000. Show the bitmap after each of the following additional actions: a) File B us written, using 5 blocks. b) File A is deleted. c) File C is written, using 8 blocks. d) File B is deleted
Ilya Zaihrayeu Operating Systems Course

12

Free memory space management, contd

A: a) 1111 1111 1111 0000


A B

b) 1000 0001 1111 0000


B

c) 1111 1111 1111 1100


C B C

d) 1111 1110 0000 1100


C C
Ilya Zaihrayeu Operating Systems Course

13

Free memory space management-2 Q: A certain file system uses 2 KB disk blocks. The median file size is 1 KB. What fraction of the disk space is wasted for 1 KB files? How might you justify wasting the disk space?

Ilya Zaihrayeu

Operating Systems Course

14

Free memory space management-2, contd


A: The 1 KB median file size consumes only half of the 2 KB disk block, and thus leads to 50% wasted disk space Because disks generally read large disk blocks more efficiently, and realistic file systems include large files, disk performance can justify the wasted disk space

2K

Ilya Zaihrayeu

Operating Systems Course

15

Directories and files Q: How many disk operations are needed to fetch the i-node for the file /usr/ast/courses/os/handout.t? Assume that the i-node for the root directory is in memory, but nothing else along the path is in memory. Also assume that all directories fit in one disk block.

Ilya Zaihrayeu

Operating Systems Course

16

Recall: i-nodes

I-node stores the attributes and disk addresses of a files blocks The first few addresses are stored in the i-node itself Additional addresses are available via single, double and triple indirect blocks reference In UNIX directories are implemented as i-nodes

Ilya Zaihrayeu

Operating Systems Course

17

Directories and files, contd


A: Since all directories fit in one disk block then all required data on a directory is stored in the i-node itself To open /usr/ast/courses/os/handout.t, assuming the root i-node is already in memory, we do the following reads: 1: directory / 2: i-node for /usr 3: directory /usr 4: i-node for /usr/ast 5: directory /usr/ast 6: i-node for /usr/ast/courses 7: directory /usr/ast/courses 8: i-node for /usr/ast/courses/os/ 9: directory /usr/ast/courses/os/ 10: i-node for /usr/ast/courses/os/handout.t
Ilya Zaihrayeu Operating Systems Course

18

References Andrew S. Tanenbaum, Modern Operating Systems Silberschatz Galvin, Operating System Concepts

Ilya Zaihrayeu

Operating Systems Course

19

Das könnte Ihnen auch gefallen