CS372: Solutions for Homework 12

Problem 1

Suppose a program references pages in the following sequence:
ACBDBAEFBFAGEFA
Suppose the computer on which this program is running has 4 pages of physical memory.
  1. Show how LRU-based demand paging would fault pages into the four frames of physical memory.
    Solution:
      ACBDBA EFBFA GEFA
    1 A     +     +   +
    2 C      E     G   
    3  B +    +     E  
    4   D    F  +   +  

  2. Show how OPT (or MIN) based demand paging would fault pages into the four frames of physical memory.
    Solution:
      ACBDBA EFBFA GEFA
    1 A     +     +   +
    2  C      E      +   
    3   B +    +   G    
    4   D    F  +   +  

  3. Show how clock-based demand paging would fault pages into the four frames of physical memory.
    Solution:
      ACBDBA EFBFA GEFA
    1 A11 11 1+1 E11111 0+111
    2  C11111 0 F11+1100 +11
    3    B11+110 0 +1 1 0G1111
    4     D1110000 A111 1+1

    "+" (plus sign) means cache hit
    1/0 means the state of the "used" bit at the end of the specified step
    bold italics is the position of the clock hand at the end of the specified step (this is what will be looked at first the next time the clock hand moves)

Problem 2

Assume that you have a page reference string for a process. Let the page reference string have length p with n distinct page numbers occurring in it. Let m be the number of page frames that are allocated to the process (all the page frames are initially empty). Let n > m.
  1. What is the lower bound on the number of page faults?
  2. What is the upper bound on the number of page faults?
Hint: Your answer is independent of the page replacement scheme that you use.

Solution:
Need solution.

Problem 3

Suppose you have a file system with multi-level indexing (with 14 direct pointers, 1 indirect inode, 1 doubly indirect pointer, and 1 triple indirect pointer in the inode), directories, inodes statically allocated in an array 0..MAX_INUM to a known location on disk. Also assume there is an on-disk bitmap of free inodes and free sectors. Assume that the file containing the root directory is stored in a well-known inode with inumber ROOT_INUM.

Assume each file fits in one sector. Assume each inode consumes exactly one sector.

Consider creating a new file "/foo/bar" in the existing directory "foo" and writing one sector of data to that file.

Assume no in-memory cache.

  1. List the reads and writes that must be executed to accomplish this task (and explain how each disk address is determined.)

  2. Suppose we want to ensure that these actions occur reliably (e.g., if a crash occurs, the file ends up either created and full with the bitmaps and directories updated accordingly or not created with none of these updates having occurred). Using ordered synchronous metadata writes and FSCK (File System ChecK program --e.g., file system recovery on reboot), explain how to meet this guarantee. In particular,
    1. Write down the writes in order they should occur.
    2. List the actions that the fsck program must take to ensure the disk is brought to a correct state on recovery and show that these actions guarantee file systems consistency.

  3. Suppose we want to ensure reliable updates using logging (e.g., as per a journaling file system). List the series of writes (to the disk and log) in the order they should occur. Also describe what actions (if any) must be taken on recovery after a crash.

Solution:
Need solution.

Problem 4

Belady's anomaly: Intuitively, it seems that the more frames the memory has, the fewer page faults a program will get. Surprisingly enough, this is not always true. Belady (1969) discovered an example in which FIFO page replacement causes more faults with four page frames than with three. This strange situation has become known as Belady's anomaly. To illustrate, a program with five virtual pages numbered from 0 to 4 references its pages in the order:
0 1 2 3 0 1 4 0 1 2 3 4
  1. Using FIFO replacement, compute the number of page faults with 3 frames. Repeat for 4 frames.
  2. Compute the number of page faults under LRU, NRU, the clock algorithm, and the optimal algorithm.
Solution:
  1. The number of page faults is 9 with 3 frames, 10 with 4.
  2. The point of the exercise is to see that the performance of LRU, NRU, clock algorithm and optimal all offer better performance with larger number of frames.

Problem 5

You are implementing a file server that contains 25 16GB disks and uses the UNIX file system to implement the network file server (NFS). A engineer in the lab gives you a 1GB disk that she no longer needs. What would you do with this disk?

Solution:
If the UNIX file system uses a log-based (journalled) file system, then the 1GB disk would be ideal for storing the log, since there will be no competition for the head from ordinary access.