CMPSCI 377: Operating Systems
Exam 2: Memory Management, File and I/O Systems

  1. Contiguous Memory Allocation (20 pts)

    1. (5 pts) True or false: In a uniprogramming system, physical addresses can never be generated at compile time. Explain your answer in brief.

      Answer:
      False. In uniprogramning environment there is only one process running at any given time, so there will be no need to "look for a place in the memory" to place the process - there are no other processes running, so upon compilation the compiler knows where the loading point of the process will be and is therefore able to generate the physical addresses at compile time.

    2. (6 pts) Do you need any hardware features to support static and dynamic relocation? If so, draw a picture showing how these hardware features might be used for virtual to physical address translations. If not, explain why not?

      Answer:
      No for static - the addresses are calculated at load time.
      Yes for dynamic. For dynamic relocation you need hardware support for base and limit/relocation registers (see Figure 9.5 in the book page 266).

    3. (4 pts) True or false: The 50-percent rule states that 50% of memory is lost to external fragmentation when the first-fit policy is used.

      Answer:
      False. It states that the memory lost to fragmentation is about 50% the size of the allocated memory.

    4. (5 pts) Is it possible to eliminate internal fragmentation in the best-fit policy? If so, explain how. If not, why not?

      Answer:
      Yes, if each process is allocated exactly the memory it asked for. But the OS will (probably) have to maintain very small holes in the free list.

  2. Paging and Segmentation (20 pts)

    1. (10 pts) What is a translation look-aside buffer (TLB)? Do you need a TLB for correct execution of programs?

      Answer:
      TLB is a cache that stores [PageNo][FrameNo] pairs. You don't neet it for correct execution of programs.

    2. (10 pts) What data structures (tables) do you need to maintain to implement segmented paging? What are the three components of a virtual address in this scheme?

      Answer:
      You need a segment table and a page table. The address is represented as (seg#, poge#, offset) tripple.

  3. Demand Paging and Page Replacement (30 pts)

    1. (10 pts) In a demand paged system with a 100 nanosecond memory access time and a 10 millisecond page fault time, what must be the page fault rate to incur a 10% slowdown in the effective memory access time? (Hint: the page fault rate is the inverse of the page fault probability)

      Answer:

      ema = (1-p)*ma + p*pf
      10% Slowdown ==> ema = 110 ns
      110 = (1-p)*100 + p*10*10^6
      10 = p*(10^7-100) ==> p = 10/(10^7 - 100)

      Hence page fault rate is 10^6-10

    2. (20 pts) Give a reference stream of page accesses (use alphabets or integers to represent page accesses) for which FIFO page replacement performs better (has fewer page faults) than LRU. Next, give a reference stream for which LRU performs better than FIFO. Your reference stream can be as short as you like and you can assume as many (or as few) physical memory frames as you like (your reference stream and frame choices should demonstrate the required behavior). Make sure you state the number of frames and show that one reference stream performs better than the other.
    3. Answer:
      Assume 2 frames.
      In case of a stream A-B-A-C-A the LRU performes better - 1 fault - C forces B out and the last A is a hit and FIFO is worse - 2 page faults - C forces A out and the last A is a miss (fault).
      In case of a stream A-B-A-C-B the FIFO performes better - 1 fault - C forces A out and the last B is a hit and LRU is worse - 2 page faults - C forces B out and the last B is a miss (fault).

  4. File and I/O Systems (30 pts)

    1. (5 pts) Assuming that all files and directories are exactly one disk block in size, how many disk reads are required to locate the file named /usr/bin/netscape and read it into memory? Assume that the file descriptor for the root directory is already in memory. Explain your answer.

      Answer:
      You need six reads.
      Locate file descriptor for urs
      Read file descriptor for urs
      Read urs
      Locate file descriptor for bin
      Read file descriptor for bin
      Read bin
      Locate file descriptor for netscape
      Read file descriptor for netscape
      Read netscape

    2. (5 pts) Explain the steps that are performed when reading one byte of data from a modem. Assume that the CPU communicates with the modem using polling.
    3. Answer:
      See Lecture 21 page 4.

    4. (20 pts) Consider a file that is 1000 disk blocks in size. Assume that a disk block is appended to the end of the file, which causes the file size to grow to 1001 blocks. How many disk read and write operations are required to update the file and the file descriptor? Assume that the file is stored as a linked list with the pointer to the next file block stored at the end of each block. Also assume that both the file and the file descriptor are initially on disk and that file buffer cache is empty. How will your answer change if a multi-level index scheme is used instead of a linked file organization?

      Answer:

      Linked-list case

      Read file's descriptor.
      Traverse the linked list - 1000 reads
      Write the pointer in the 1000th block to point to the new 1001st block
      Write the 1001st block
      Write - update file's descriptor with the new file size
      ------------------------
      Total - 1001 reads and 2 writes

      Multilevel index

      Assume each indirect block has 1024 entries ==> block 1001 is in the 1st level indirect block.
      Read file's descriptor.
      Read 1st level indirect block.
      Update 1st level indirect block - add the pointer to the new 1001st block.
      Write the updated 1st level indirect block
      Write the 1001st block
      Write - update file's descriptor with the new file size
      ------------------------
      Total - 2 reads and 3 writes