hw5 solutions (1)

Upload: jeffrey-barrett

Post on 03-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 HW5 Solutions (1)

    1/3

    CS 4375: HOMEWORK #5

    1. Consider a swapping system in which memory consists of the following hole sizes in memory inthis order: 10KB, 4KB, 20KB, 18KB, 7KB, 9KB, 12KB. Which hole is taken for successive segment

    request of 12KB, 10KB, 9KB for

    a. First fit?b. Best fit?c. Worst fit?d. Next fit?Solution:

    a. 20KB (for 12KB segment), 10KB (for 10KB segment), 18KB (for 9KB segment).b. 12KB, 10KB, 9KBc. 20KB, 18KB, 12KBd. 20KB, 18KB, 9KB

    2. Suppose that the virtual page reference stream contains repetitions of long sequences of pagereferences followed occasionally by a random page reference. For example, the sequence:

    0,1,...,511,431,0,1,,511,332,0,1, consists of repetition of the sequence 0,1,,511 followed by

    a random reference to pages 431 and 332.

    a. Why wont the standard replacement algorithms (LRU, FIFO, Clock) be effective in handlingthis workload for a page allocation that is less than the sequence length?

    Solution: Almost every page reference will be a miss. The page to be taken out will almost

    always be the one with the smallest ID, and the page coming in will be the one with either

    much higher ID or much smaller ID. The only time a hit might occur in LRU and Clock is when

    the random reference occurs. Hit will never happen in FIFO.b. If this program were allocated 500 page frames, describe a page replacement approach that

    would perform much better than the LRU, FIFO, or Clock algorithms.

    Solution: Multiple options exist. One method (not really sophisticated though) is random

    page replacement. It will probably not result in less hits than LRU, FIFO, and Clockm and is

    the easiest to implement. More sophisticated method would always replace the page with

    the highest ID. This way, every time a page above ID 499 is referenced, there will be a miss,

    but in other cases, there will be a hit.

    3. If FIFO page replacement algorithm is used with four page frames and eight pages, how manypage faults will occur with the reference string 0172327103 if the four frames are initiallyempty? Now repeat the problem for LRU.

    Solution:

    Reference Currently in memory (FIFO) miss/hit Currently in memory (LRU) miss/hit

    0 miss miss

    1 0 miss 0 miss

    7 01 miss 01 miss

  • 7/28/2019 HW5 Solutions (1)

    2/3

    2 017 miss 017 miss

    3 0172 (replace 0) miss 0172 (replace 0) miss

    2 1723 hit 3172 hit

    7 1723 hit 3172 hit

    1 1723 hit 3172 hit

    0 1723 (replace 1) miss 3172 (replace 3) miss

    3 0723 hit 0172 (replace 2) miss

    4. A computer has four page frames. The time of loading, time of last access, and the referenced(R) and modified (M) bits for each page are as shown below (the times are in clock ticks):

    Page Loaded Last ref. R M

    0 126 280 1 0

    1 230 265 0 1

    2 140 270 0 0

    3 110 285 1 1

    Which page will be replaced using

    a. NRU?b. FIFO?c. LRU?d. Second chance?Solution:

    a. Page 2 (R=0, M=0).b. Page 3 (the earliest time of loading).c. Page 1 (the longest time since it has been referenced).d. Page 2 (the earliest page with R=0).

    5. Can you think of any situation where supporting virtual memory would be a bad idea, and whatwould be gained by not having to support virtual memory? Explain.

    Solution: Multiple situations exist. A trivial example is when only one program is running and

    this program is small enough to fit in the memory. A more complex example is that there are

    multiple programs that fit into memory and their sizes do not change. In either case, not having

    virtual memory would save a level of mapping.

    6. Clearly explain the difference between segmented and paged memory:Solution: Paged memory is designed to map multiple aligned blocks of same size, whilesegmented memory is designed to map multiple aligned blocks of different sizes.

    7. Does a TLB miss always indicate that a page is not resident in memory? Explain.Solution: No, it just indicated that the page is not cached in TLB.

  • 7/28/2019 HW5 Solutions (1)

    3/3

    8. Compare base and bound, segmentation, and paging methods. Describe their advantages anddisadvantages.

    Solution: Base and bound is simple but arithmetically expensive. Segmentation is efficient in

    terms of space allocation but hard to manage. Paging is simple in terms of allocation, but some

    space might be wasted.

    9. In a bitmap, discuss advantages and disadvantages of having a small bit.Solution: With a small bitmap, memory will not be wasted in terms of having last bit half-empty,

    which could happen if a large bit is used. On the other hand, a large bitmap is needed in this

    case, which takes up some extra memory.

    10.Explain how a TLB speeds up a page lookup.Solution: The TLB serves as a cache to a page table. The information of the most commonly

    requested pages is held in a TLB. Moreover, all entries in TLB are searched in parallel. Thus, the

    pages in TLB are accessed really quickly.

    11.Consider the following CPU-referenced memory address (in hexadecimal notation): F80AC4B4.Assume a page size (both virtual and physical) of 4Kbytes. Give the number of the referenced

    virtual page (in hexadecimal).

    Solution: F80AC because the page size is 4Kbytes = 2^12, so the offset is 2^12 bits, which is the

    last 3 hexadecimal numbers. Thus, the page number is the remaining 5 hexadecimal numbers.