• 沒有找到結果。

File-System Implementation

在文檔中 OPERATING SYSTEM CONCEPTS (頁 61-69)

56 Chapter 12 File-System Implementation

12.2 Consider a system where free space is kept in a free-space list.

a. Suppose that the pointer to the free-space list is lost. Can the system reconstruct the free-space list? Explain your answer.

b. Suggest a scheme to ensure that the pointer is never lost as a result of memory fail-ure.

Answer:

a. In order to reconstruct the free list, it would be necessary to perform “garbage collec-tion.” This would entail searching the entire directory structure to determine which pages are already allocated to jobs. Those remaining unallocated pages could be relinked as the free-space list.

b. The free-space list pointer could be stored on the disk, perhaps in several places.

12.3 What problems could occur if a system allowed a file system to be mounted simultane-ously at more than one location?

Answer: There would be multiple paths to the same file, which could confuse users or encourage mistakes (deleting a file with one path deletes the file in all the other paths).

12.4 Why must the bit map for file allocation be kept on mass storage, rather than in main memory?

Answer: In case of system crash (memory failure) the free-space list would not be lost as it would be if the bit map had been stored in main memory.

12.5 Consider a system that supports the strategies of contiguous, linked, and indexed allo-cation. What criteria should be used in deciding which strategy is best utilized for a particular file?

Answer:

 Contiguous– if file is usually accessed sequentially, if file is relatively small.

 Linked– if file is large and usually accessed sequentially.

 Indexed– if file is large and usually accessed randomly.

12.6 Consider a file system on a disk that has both logical and physical block sizes of 512 bytes.

Assume that the information about each file is already in memory. For each of the three allocation strategies (contiguous, linked, and indexed), answer these questions:

a. How is the logical-to-physical address mapping accomplished in this system? (For the indexed allocation, assume that a file is always less than 512 blocks long.) b. If we are currently at logical block 10 (the last block accessed was block 10) and want

to access logical block 4, how many physical blocks must be read from the disk?

Answer: Let Z be the starting file address (block number).

a. Contiguous. Divide the logical address by 512 with X and Y the resulting quotient and remainder respectively.

i. Add X to Z to obtain the physical block number. Y is the displacement into that block.

ii. 1

b. Linked. Divide the logical physical address by 511 with X and Y the resulting quo-tient and remainder respectively.

Answers to Exercises 57

i. Chase down the linked list (getting X + 1 blocks). Y + 1 is the displacement into the last physical block.

ii. 4

c. Indexed. Divide the logical address by 512 with X and Y the resulting quotient and remainder respectively.

i. Get the index block into memory. Physical block address is contained in the index block at location X. Y is the displacement into the desired physical block.

ii. 2

12.7 One problem with contiguous allocation is that the user must preallocate enough space for each file. If the file grows to be larger than the space allocated for it, special actions must be taken. One solution to this problem is to define a file structure consisting of an initial contiguous area (of a specified size). If this area is filled, the operating system automatically defines an overflow area that is linked to the initial contiguous area. If the overflow area is filled, another overflow area is allocated. Compare this implementation of a file with the standard contiguous and linked implementations.

Answer: This method requires more overhead then the standard contiguous allocation.

It requires less overhead than the standard linked allocation.

12.8 Fragmentation on a storage device could be eliminated by recompaction of the informa-tion. Typical disk devices do not have relocation or base registers (such as are used when memory is to be compacted), so how can we relocate files? Give three reasons why re-compacting and relocation of files often are avoided.

Answer: Relocation of files on secondary storage involves considerable overhead — data blocks would have to be read into main memory and written back out to their new locations. Furthermore, relocation registers apply only to sequential files, and many disk files are not sequential. For this same reason, many new files will not require contiguous disk space; even sequential files can be allocated noncontiguous blocks if links between logically sequential blocks are maintained by the disk system.

12.9 How do caches help improve performance? Why do systems not use more or larger caches if they are so useful?

Answer: Caches allow components of differing speeds to communicate more efficiently by storing data from the slower device, temporarily, in a faster device (the cache). Caches are, almost by definition, more expensive than the device they are caching for, so increas-ing the number or size of caches would increase system cost.

12.10 In what situations would using memory as aRAMdisk be more useful than using it as a disk cache?

Answer: In cases where the user (or system) knows exactly what data is going to be needed. Caches are algorithm-based, while aRAMdisk is user-directed.

12.11 Why is it advantageous for the user for an operating system to dynamically allocate its internal tables? What are the penalties to the operating system for doing so?

Answer: Dynamic tables allow more flexibility in system use growth — tables are never exceeded, avoiding artificial use limits. Unfortunately, kernel structures and code are more complicated, so there is more potential for bugs. The use of one resource can take away more system resources (by growing to accommodate the requests) than with static tables.

12.12 Explain why logging metadata updates ensures recovery of a file system after a file system crash.

58 Chapter 12 File-System Implementation

Answer: No answer.

12.13 Explain how theVFSlayer allows an operating system easily to support multiple types of file systems.

Answer: No answer.

12.14 Consider the following backup scheme:

 Day 1. Copy to a backup medium all files from the disk.

 Day 2. Copy to another medium all files changed since day 1.

 Day 3. Copy to another medium all files changed since day 1.

This contrasts to the schedule given in Section 11.6.2 by having all subsequent backups copy all files modified since the first full backup. What are the benefits of this system over the one in Section 11.6.2? What are the drawbacks? Are restore operations made easier or more difficult? Explain your answer.

Answer: Restores are easier because you can go to the last backup tape, rather than the full tape. No intermediate tapes need be read. More tape is used as more files change.

Review Questions 59

Review Questions

12.1 List three ways of allocating storage, and give advantages of each.

Answer:

a. Contiguous allocation. Fastest, if no changes are to be made. Also easiest for random-access files.

b. Linked allocation. No external fragmentation. File can grow without complications.

c. Indexed allocation. Supports direct access without external fragmentation.

12.2 What is contiguous allocation?

Answer: Allocation of a group of consecutive sectors for a single file.

12.3 What main difficulty occurs with contiguous allocation?

Answer: Finding space for a new file.

12.4 What is a “hole” in contiguous allocation method?

Answer: An unallocated segment of blocks.

12.5 Explain first-fit, best-fit, and worst-fit methods of allocating space for contiguous files.

Answer:

 First-fit: Scan available blocks of disk for successive free sectors; use the first area found that has sufficient space; do not scan beyond that point.

 Best-fit: Search for smallest area large enough to place the file.

 Worst-fit: Search for largest area in which to place the file.

12.6 What is external fragmentation in a system with contiguous files?

Answer: The disk has files scattered all over; fragmentation occurs when there is enough empty space collectively for the next file, but there is no single gap large enough for the entire file to fit in.

12.7 How can we overcome fragmentation?

Answer: We can use an allocation technique that does not result in fragmentation; or we can move the files around on disk, putting them closer together, to leave us larger blocks of available sectors.

12.8 What is preallocation? Why do it?

Answer: Allocating space for a file before creating the file to allow for expansion. This reserves space for a particular file so that other files can’t grab it. The new file may initially use only a small portion of this space.

12.9 What is linked allocation, as detailed in text?

Answer: Directory contains pointers to first and last blocks of file. Each block of file (except last) has pointer to the next block.

12.10 Can linked allocation have external fragmentation? Internal fragmentation?

Answer: External — no. Internal — Yes.

12.11 Can linked allocation be used for direct-access files?

Answer: Not in the form suggested in the book. RSTSon thePDP-11 stores the sector numbers in the directory, with each group of seven addresses linked to the next group of seven. Direct access using this modified linked allocation is possible. (This approach is really a hybrid of linked and indexed allocations.)

60 Chapter 12 File-System Implementation

12.12 What is indexed allocation?

Answer: Each file has its own block of pointers to the sectors of the file.

12.13 Rank the allocation methods on speed.

Answer: Contiguous is fastest. Linked is slower, because the disk head may have to move between accesses of file. Indexed is slowest, unless the entire index can be kept in memory at all times. If not, then extra time must be used to access next block of file indexes.

12.14 List four ways a system could use to determine which sectors are free. Give advantages of each way.

Answer:

a. Free-space list. Each section indicates a sector that is available. Not encumbered by a used-sector list.

b. Bit vector is a compact version. Has no links that can be broken.

c. Link all free sectors together in an available list. Takes no usable space. But links could break.

d. List giving start of each block of free sectors, and a count of number of sectors in this block. This is fast for use in contiguous storage search.

12.15 List kinds of information we’d likely want to keep in a directory, and estimate number of bytes needed to store each compactly.

Answer: File name (5 - 15), file type (3), location (4), size (2), protection (2), usage count (2), time (2), date (2), process ID (3), time-date-process ID for creation, last modification, last use (3-4 bytes for each time/date), owner (2).

12.16 What data structures can be used for directory information?

Answer:

a. Linear list b. Linked list c. Sorted list

d. Linked binary tree e. Hash table

12.17 What problems might arise with above data structures?

Answer:

a. Linear list is slow to access particular file. Also must decide how to take care of deletions (mark, copy last entry to it, ...).

b. Linked list requires storage overhead for pointers; also, if link goes bad, rest of files are lost.

c. Sorted list requires list always to be sorted, which means extra work on creating and deleting files.

d. Binary tree suffers like linked list.

e. Hash tables are set up for a maximum number of files; also there is a problem with collisions.

Review Questions 61

12.18 Give advantages of each directory structure above.

Answer:

Linear list Simple to program search.

Linked list Easier to process deletes.

Sorted list Fast access.

Linked binary tree Faster access.

Hash table Fastest access.

在文檔中 OPERATING SYSTEM CONCEPTS (頁 61-69)