1、Chapter 9n 9.3 Describe the following allocation algorithms:n a. First fitn b. Best fitn c. Worst fitn First fit:搜索可用内存列表,分配第一块足够大的n Best fit:搜索整个可用内存块,分配最小足够大的n Worst fit:搜索整个可用内存块,分配最大足够大的9-cont.n 9.5 Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in order), how would each of the Fir
2、st-fit, Best-fit, and Worst-fit algorithms place processes of 212K, 417K, 112K, and 426K (in order)? Which algorithm makes the most efficient use of memory?n First fitn 212 -500(288)n 417 -600(183)n 112 -288n 426 -nonen Best fitn 212 -300n 417 -500n 112 -200 n 426 -600n Worst fitn 212 -600(388)n 417
3、 -500n 112 -388 n 426 -none9-cont.n 9.10 Consider a paging system with the page table stored in memory.n a. If a memory reference takes 200 nanoseconds, how long does a paged memory reference take?n b. If we add associative registers, and 75 percent of all page-table references are found in the asso
4、ciative registers, what is the effective memory reference time? (Assume that finding a page-table entry in the associative registers takes zero time, if the entry is there.)n a. 400, 200(page table)+200(access word)n b. 250, 75%*200+25%*(200+200)9-cont.n 9.16 Consider the following segment table:n W
5、hat are the physical addresses for the following logical addresses?n a. 0,430n b. 1,10n c. 2,500n d. 3,400n e. 4,112n a. 430100, illegaln d. 40096, illegal9-cont.n 9.18 In the IBM/370, memory protection is provided through the use of keys. A key is a 4-bit quantity. Each 2K block of memory has a key
6、 (the storage key) associated with it. The CPU also has a key (the protection key) associated with it. A store operation is allowed only if both keys are equal, or if either is zero. Which of the following memory-management schemes could be used successfully with this hardware?n a. Bare machinen b.
7、Single-user systemn c. Multiprogramming with a fixed number of processesn d. Multiprogramming with a variable number of processesn e. Pagingn f. Segmentationn a. Protection not necessary, set system key to 0.n b. Set system key to 0 when in supervisor mode.n c. Region sizes must be fixed in incremen
8、ts of 2k bytes, allocate key with memoryn blocks.n d. Same as above.n e. Frame sizes must be in increments of 2k bytes, allocate key with pages.n f. Segment sizes must be in increments of 2k bytes, allocate key with segments.Chapter 10n 10.1 Under what circumstances do page faults occur? Describe th
9、e actions taken by the operating system when a page fault occurs.n A page fault occurs when an access to a page that has not been brought into main memory takes place. n The operating system verifies the memory access, n aborting the program if it is invalid. n If it is valid, a free frame is locate
10、d and I/O is requested to read the needed page into the free frame. Upon completion of I/O, the process table and page table are updated and the instruction is restarted.10-cont.n 10.6 Consider the following page-replacement algorithms. Rank these algorithms on a five point scale from “bad” to “perf
11、ect” according to their page-fault rate. Separate those algorithms that suffer from Beladys anomaly from those that do not.n a. LRU replacementn b. FIFO replacementn c. Optimal replacementn d. Second-chance replacementn Rank Algorithm Suffer from Beladys anomalyn 1 Optimal non 2 LRU non 3 Second-cha
12、nce yesn 4 FIFO yes10-cont.n 10.9 Consider a demand-paging system with the following time-measured utilizations:CPU utilization 20%Paging disk 97.7%Other I/O devices 5%Which (if any) of the following will (probably) improve CPU utilization? Explain your answer.n a. Install a faster CPU.n b. Install
13、a bigger paging disk.n c. Increase the degree of multiprogramming.n d. Decrease the degree of multiprogramming.n e. Install more main memory.n f. Install a faster hard disk or multiple controllers with multiple hard disks.n g. Add prepaging to the page fetch algorithms.n h. Increase the page size.10
14、-cont.n 10.10 Consider the two-dimensional array A:int A = new int100100;where A00 is at location 200, in a paged system with pages of size 200. A small process is in page 0 (locations 0 to 199) for manipulating the matrix; thus, every instruction fetch will be from page 0.For three page frames, how
15、 many page faults are generated by the following array-initialization loops, using LRU replacement, and assuming page frame 1 has the process in it, and the other two are initially empty:n a. for (int j = 0; j 100; j+)for (int i = 0; i 100; i+)Aij = 0;n b. for (int i = 0; i 100; i+)for (int j = 0; j
16、 100; j+)Aij = 0;a. 100x50b. 5010-cont.n 10.11 Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.How many page faults would occur for the following replacement algorithms, assuming one, two, three, four, five, six, or seven frames? Remember all
17、frames are initially empty, so your first unique pages will all cost one fault each.n LRU replacementn FIFO replacementn Optimal replacementn Number of frames LRU FIFO Optimaln 1 20 20 20n 2 18 18 15n 3 15 16 11n 4 10 14 8n 5 8 10 7n 6 7 10 7n 7 7 7 7Chapter 11n 11.3 Why do some systems keep track o
18、f the type of a file, while others leave it to the user or simply do not implement multiple file types? Which system is “better?”n Some systems allow different file operations based on the type of the file (for instance, an ascii file can be read as a stream while a database file can be read via an
19、index to a block). Other systems leave such interpretation of a files data to the process and provide no help in accessing the data. The method which is “better” depends on the needs of the processes on the system, and the demands the users place on the operating system. If a system runs mostly data
20、base applications, it may be more efficient for the operating system to implement a database-type file and provide operations, rather than making each program implement the same thing (possibly in different ways). For general purpose systems it may be better to only implement basic file types to kee
21、p the operating system size smaller and allow maximum freedom to the processes on the system.11-cont.n 11.6 Could you simulate a multilevel directory structure with a single-level directory structure in which arbitrarily long names can be used? If your answer is yes, explain how you can do so, and c
22、ontrast this scheme with the multilevel directory scheme. If your answer is no, explain what prevents your simulations success. How would your answer change if file names were limited to seven characters?n If arbitrarily long names can be used then it is possible to simulate a multilevel directory s
23、tructure. This can be done, for example, by using the character “.” to indicate the end of a subdirectory. Thus, for example, the name jim.pascal.F1 specifies that F1 is a file in subdirectory pascal which in turn is in the root irectory jim. If file names were limited to seven characters, then the
24、above scheme could not be utilized and thus, in general, the answer is no. The next best approach in this situation would be to use a specific file as a symbol table (directory) to map arbitrarily long names (such as jim.pascal.F1) into shorter arbitrary names (such as XX00743), which are then used
25、for actual file access.11-cont.n 11.9 Give an example of an application in which data in a file should be accessed in the following order:n a. Sequentiallyn b. Randomlyn a. Print the content of the file.n b. Print the content of record i. This record can be found using hashing or index techniques.n
26、11.12 Consider a system that supports 5000 users. Suppose that you want to allow 4990 of these users to be able to access one file.n a. How would you specify this protection scheme in UNIX?n b. Could you suggest another protection scheme that can be used more effectively for this purpose than the sc
27、heme provided by UNIX?n a. There are two methods for achieving this:n i. Create an access control list with the names of all 4990 users.n ii. Put these 4990 users in one group and set the group access accordingly. This scheme cannot always be implemented since user groups are restricted by the syste
28、m.n b. The universe access information applies to all users unless their name appears in the access-control list with different access permission. With this scheme you simply put the names of the remaining ten users in the access control list but with no access privileges allowed.Chapter 12n 12.1 Co
29、nsider 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 (single-level) allocation strategies, if, for on
30、e 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. Assume that the block information to be added is stored in memory.n a. The block is added at the beginning.n b. The block is added i
31、n the middle.n c. The block is added at the end.n d. The block is removed from the beginning.n e. The block is removed from the middle.n f. The block is removed from the end.n Contiguous Linked Indexedn 201(100读写 +1新写 ) 1( 1新写) 1( 1新写)n 101(50读写 +1新写 ) 52( 50读 +第 50块写 +1新写) 1( 1新写)n 1( 1新写) 3(第 100块
32、读写 +1新写) 1( 1新写)n 198( 99读写) 1(读第 1块) 0n 98(后 49块读写) 52( 51读 +第 50块写) 0n 0 100( 99读 +1写) 012-cont.n 12.2 Consider a system where free space is kept in a free-space list.n a. Suppose that the pointer to the free-space list is lost. Can the system reconstruct the free-space list? Explain your answer.n
33、 b. Suggest a scheme to ensure that the pointer is never lost as a result of memory failure.n a. In order to reconstruct the free list, it would be necessary to perform “garbage collection.” This would entail searching the entire directory structure to determine which pages are already allocated to
34、jobs. Those remaining unallocated pages could be relinked as the free-space list.n b. The free-space list pointer could be stored on the disk, perhaps in several places.12-cont.n 12.3 What problems could occur if a system allowed a file system to be mounted simultaneously at more than one location?n
35、 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).n 12.4 Why must the bit map for file allocation be kept on mass storage, rather than in main memory?n In case of system crash (memo
36、ry failure) the free-space list would not be lost as it would be if the bit map had been stored in main memory.12-cont.n 12.5 Consider a system that supports the strategies of contiguous, linked, and indexed allocation. What criteria should be used in deciding which strategy is best utilized for a p
37、articular file?n Contiguous if file is usually accessed sequentially, if file is relatively small.n Linked if file is large and usually accessed sequentially.n Indexed if file is large and usually accessed randomly.n 12.6 Consider a file system on a disk that has both logical and physical block size
38、s 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:n a. How is the logical-to-physical address mapping accomplished in this system? (For the indexed allocation, assume
39、 that a file is always less than 512 blocks long.)n 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?n a. Contiguous. Divide the logical address by 512 with X and Y the resulting
40、quotient and remainder respectively.n i. Add X to Z to obtain the physical block number. Y is the displacement into that block.n ii. 1n b. Linked. Divide the logical physical address by 511 with X and Y the resulting quotient and remainder respectively.n i. Chase down the linked list (getting X + 1b
41、locks). Y + 1 is the displacement into the last physical block.n ii. 4n c. Indexed. Divide the logical address by 512 with X and Y the resulting quotient and remainder respectively.n i. Get the index block into memory. Physical block address is contained in the index block at location X. Y is the di
42、splacement into the desired physical block.n ii. 2Chapter 13n 13.1 State three advantages of placing functionality in a device controller, rather than in the kernel. State three disadvantages.n Three advantages: Bugs are less likely to cause an operating system crash Performance can be improved by u
43、tilizing dedicated hardware and hard-coded algorithms The kernel is simplified by moving algorithms out of itn Three disadvantages: Bugs are harder to fix - a new firmware version or new hardware is needed Improving algorithms likewise require a hardware update rather than just kernel or device driv
44、er update Embedded algorithms could conflict with applications use of the device, causing decreased performance.13-cont.n 13.2 Consider the following I/O scenarios on a single-user PC.n a. A mouse used with a graphical user interfacen b. A tape drive on a multitasking operating system (assume no dev
45、ice preallocation is available)n c. A disk drive containing user filesn d. A graphics card with direct bus connection, accessible through memory-mapped I/OFor each of these I/O scenarios, would you design the operating system to use buffering, spooling, caching, or a combination? Would you use polle
46、d I/O, or interrupt-driven I/O? Give reasons for your choices.n a. Buffering may be needed to record mouse movement during times when higherpriority operations are taking place. Spooling and caching are inappropriate. Interrupt driven I/O is most appropriate.n b. Buffering may be needed to manage th
47、roughput difference between the tape drive and the source or destination of the I/O, Caching can be used to hold copies of data that resides on the tape, for faster access. Spooling could be used to stage data to the device when multiple users desire to read from or write to it. Interrupt driven I/O
48、 is likely to allow the best performance.n c. Buffering can be used to hold data while in transit from user space to the disk, and visa versa. Caching can be used to hold disk-resident data for improved performance. Spooling is not necessary because disks are shared-access devices. Interrupt driven I/O is best for devices such as disks that transfer data at slow rates.n d. Buffering may be needed to control multiple access and for performance (double buffering can be used to hold the next screen im