Você está na página 1de 5

Example Problems

Thursday, 3 April 2003 1) Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in order), how would each of the First-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? Answer: First-fit: 212K is put in 500K partition 417K is put in 600K partition 112K is put in 288K partition (new partition 288K = 500K - 212K) 426K must wait Best-fit: 212K is put in 300K partition 417K is put in 500K partition 112K is put in 200K partition 426K is put in 600K partition Worst-fit: 212K is put in 600K partition 417K is put in 500K partition 112K is put in 388K partition (600K 212K) 426K must wait In this example, Best-fit turns out to be the best. 2) We learned in class that by running multiple jobs at once (multi-programming) they can finish faster then when they are run sequentially. Suppose two jobs, each of which needs 10 minutes of CPU time, start simultaneously. Assume 50% I/O wait time. a) How long will it take for both to complete if they run sequentially? b) How long if they run in parallel? Answer: If they run sequentially then the total time to complete (T) is: T = 20 min + 20 min = 40min Let P = probability that a process is waiting for I/O, P = .5. Then the likelihood that at least one process is ready to run (not waiting on I/O) is given by (1 Pn) = .75. So the time to complete is T * (1 P2) = T * = 20 or T = (4 * 20) / 3 = 26.7min 3) Consider a logical address space of eight pages of 1024 addressable words each, mapped onto a physical memory of 32 frames. a) How many bits are there in the logical address? b) How many bits are there in the physical address? Answer: a. Logical address: 13 bits (213 = 8K), b. Physical address: 15 (215 = 32K)

4) Consider a paging system with the page table (1 level) stored in memory. a. If a memory reference takes 200 nanoseconds, how long does a paged memory reference take? b. If we add associative registers, and 75 percent of all page-table references are found in the associative 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.) Answer: a. access time 400 nanoseconds; 200 nsecs to access the page table and 200 nsec to access the word in memory. b. Effective access time 250 nsec; 0.75 (200 nsec) + 0.25 (400 nanoseconds) = 250 nsec. 5) The memory management unit is responsible for performing virtual address translation. The figure below illustrates the relationship between the different components and tables used for this translation.
MMU CPU
Virtual address

Physical cache
physical address

TLB
page table directory offset

Page tables

Based on this figure, answer the following questions: a) What is the TLB used for (keep it short 2 or 3 words)? b) What are the three exception types raised by the MMU when a valid mapping does not exist for a virtual page number (exact or paraphrased)? c) Explain what happens when the MMU raises an exception for a non-resident page (i.e. a page fault)? Keep it short, just hit on the key operations performed by the MMU and OS. Answer: a) Cache for virtual page number to frame number (physical page frame) translations b) Bounds error - outside address range, Validation error - non-resident page, Protection error - not permitted access c) Page fault occurs when a virtual page that is not resident in physical memory. When the MMU looks up the virtual page number in the page table the PTE indicates the page is not resident. The MMU asserts a validation exception causing the Operating System to run. The operating system verifies the memory access, aborting the program if it is invalid. If it is valid, a free frame is located 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 is updated and the instruction is restarted.

6) For a demand-paged memory subsystem with the page table held in registers, memory access times are as follows: 8 msecs to service a page fault if an empty page is available or the replaced page is not modified, 20 msecs if the replaced page is modified 100 nsecs memory access time 70% of the time the page to be replaced is modified What is the maximum acceptable page fault rate (P) for an effective access time of no more than 200 nsecs? Answer: P = page fault rate, percentage of references that are not in cache M = percentage of time page is modified = 70% T = effective access time = 200 nsec (time is un usec) T = (1 P) * (Memory Access Time) + (1-M) * P * (Time to service page fault) + M * P * (Time to write dirty page and service fault); 0.2 = {(1 - P) * 0.1 + 0.3 * P * 8,000 + 0.7 * P * 20,000} usec = 0.1(1 P) + 2,400 P + 14,000 P = 0.1 + P * (14,000 + 2,400 0.1) 0.1 = -0.1P + 16,400 * P = 16,399.9 P P = 0.1 / 16,399.9 = 6.0976 * 10-6 So, P is approximately 6(10-6) or roughly 1 in every 1.6 million references. 7) Assume you have a fast-wide SCSI-II disk with characteristics: 10000 RPM spindle speed, 512 Bytes per sector, 300 Sectors per track, 24 tracks per cylinder (12 platters), 9801 cylinders (tracks per platter side), 6ms average seek time, 0.6 ms track-to-track seek time. Suppose you want to read a 4,608MB file under the following two sets of assumptions: a) Assume the file is allocated consecutive sectors and tracks on one surface of one of the platters. How long does it take to read the files data and what is the average throughput? a) If the individual blocks are randomly scattered over the disk how long will it now take to transfer this file and what is the average transfer rate? Answer: Rotational delay = 60 (s/m)/10,000 (rev/m) = 6ms per revolution Total number of Bytes in a track = Bt = 300 (sectors/track) * 512 (Bytes/sector) = 153,600 B/track Time to transfer X Bytes from a track is given by: Tt(X) = 6ms * X (B) / 153,600 (B/track) Blocks in file = 4,608,000 B / 512 (B/sector) = 9,000 Blocks in file (exactly 30 tracks) So to transfer the first track (T1): T1 = average seek time + average rotational delay + transfer time = 6 ms + 3 ms + 6 ms = 15ms

The time to transfer all other tracks is 6 ms plus .6 ms average tract-to-track seek time, this assumes no rotational delay. T2-30 = .6 ms + 6 ms = 6.6 ms T = 15ms + 29 * 6.6ms = 206.4 ms Average throughput = 4,608,000 / .2064 = 22.3 MBps The answer for part a is 206.4 ms and 22.3 MBps assuming sector skew (see below) For part b, assume that all blocks are randomly located on the disk. Then it takes the same time to read all disk blocks (all 9,000): T1-30 = 6 ms + 3 ms + 6 ms (s/rev) / 300 (blocks / rev) = 6 ms + 3 ms + 20 us = 9.02 ms T = 9,000 (Blocks) * 9.02 ms (time per block) = 81.18 s Average Throughput = 4,608,000 / 81.18 s = 56.76 KBps The answer for part b is 81.18 seconds and 56.76KBps Note, if a track has 300 sectors then the heads pass over a sector in 6ms / 300 = 20 usec. If it takes .6 ms to change tracks then we go over 30 tracks. So we need a 30 sector cylinder skew to ensure we can start reading the next block without additional delay. If we assume that the sectors are not skewed then after each track change we need to add in 3 msec for an average rotational delay: T2-30 = 3 ms + .6 ms + 6 ms = 9.6ms T = 15ms + 29*9.6 ms = 293.4 ms Throughput = 4,608,000 / 293.4ms = 15.7 MBps 8) Consider the two-dimensional array A: short int A[][] = new int[100][100]; // short int is 2 Bytes where A[0][0] 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 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: a. for (int j = 0; j < 100; j++) for (int i = 0; i < 100; i++) A[i][j] = 0; b. for (int i = 0; i < 100; i++) for (int j = 0; j < 100; j++) A[i][j] = 0; Answer: Assume an integer is 2 bytes and each page has length 200 bytes. Then one row fits in a page. a) 100, b) 100 * 100 = 10,000 9) Explain the purpose of the open and close operations. Answer: The open operation informs the system that the named file is about to become active. The close operation informs the system that the named file is no longer in active use by the user who issued the close operation.

10) 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. 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. Answer: Always write updated control block or index block to disk. a. b. c. d. e. f. Contiguous: a) read 100, write 101, write FCB with new length and pointer b) read last 50, write 51, write FCB with new length c) write 1, write FCB with new length d) write FCB with new length and starting block e) read last 50, write last 49, write FCB with new length f) write FCB with new length Linked: a) write new block, write FCB with new first block pointer b) read 50 blocks, write 50th with new next pointer, write new block, write FCB with new length c) read 100 blocks, write old last with new next pointer, write new last, write FCB with new length d) write FCB with new first pointer and new length e) read 51, update 50th next, write FCB with new length f) read 99, write 99th with updated next, write FCB with new length Indexed a-c) write new block, write FCB, d-f) write FCB Contiguous 202 102 2 1 100 1 Linked 2 52 103 2 53 101 Indexed 2 2 2 1 1 1

Você também pode gostar