Quiz 3 solutions

  1. This question is about memory protection using base and limit registers. For every memory access, the CPU adds the base to the address, ensures that it is less than the limit, and then uses this address to access memory. Below is a diagram of the current state of memory.

    location  value
          0    17
          1    64
          2    21
          3    38
          4    -1
          5     2
          6    99
          7    32
          8    76
    1. Suppose we want to run three processes, that each need three memory locations. Provide a valid base and limit value that will isolate each process. (The precise locations don’t matter.)

      PROCESS 1        PROCESS 2        PROCESS 3
      base = 0         base = 3         base = 6
      limit = 3        limit = 6        limit = 9

      You can put them in a different order, but to avoid overlap, some process has to start at 0, 3, and 6. The MMU (as specified above) checks that the address is strictly less than the limit, so that is why the limits are 3, 6, and 9.

    2. The physical address 4 contains the value -1. What process does it belong to, and what is its logical address?

      In our layout, physical address 4 belongs to process 2. The logical address there is 1.

    3. If process 2 tries to read from address 0, what is the result?

      Process 2 adds its base, 3, to the logical address 0, and reads from location 3, which has the value 38.

    4. If process 3 tries to read from address 3, what is the result?

      Process 3 adds its base, 6, to the logical address 3, and tries to read from location 9, but it fails because this is not less than the limit.

  2. Virtual memory means that a process’s logical address space can be larger than physical memory, by using the disk as a backing store. Briefly explain what the OS does when physical memory is full and a process needs to load a previously unused page into memory.

    When the physical memory is full and we need to load a previously unused page, we must make room by evicting some existing page. That page is swapped to the disk, which then makes room to load the new page from disk.

  3. This question is about paging. Suppose that a byte-addressable system uses 18-bit physical addresses, and that 8 of those bits are for the frame number, and the remaining 10 bits for the offset within the frame. Answer the following using whatever units are most convenient (bytes, kilobytes, etc.)

    1. What is the size of each frame?

      The size of the frame is determined by the number of bits used for the offset. In this case, that is 10 bits, so the frame is 2¹⁰ bytes = 1 kB.

    2. How many frames are available in physical memory?

      This is determined by the number of bits in the frame number. 2⁸ means 256 frames.

    3. What is the maximum amount of physical memory supported?

      The maximum amount of memory is the number of frames times the size of each frame, so 256 kB. Another way to arrive at this is the total number of bits for a physical address. 2¹⁸ bytes = 2⁸ kB = 256 kB.

comments powered by Disqus

 

©2012 Christopher League · some rights reserved · CC by-sa