Homework 6

Due 3/2/2012 [start of section]

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.
  2. Show how OPT (or MIN) based demand paging would fault pages into the four frames of physical memory.
  3. Show how clock-based demand paging would fault pages into the four frames of physical memory.

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.
 

Problem 3

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.

Problem 4

Consider the following piece of code which multiplies two matrices:
int a[1024][1024], b[1024][1024], c[1024][1024];
multiply()
{
   unsigned i, j, k;
   for(i = 0; i < 1024; i++)
       for(j = 0; j < 1024; j++)
           for(k = 0; k < 1024; k++)
               c[i][j] += a[i,k] * b[k,j];
}
Assume that the binary for executing this function fits in one page, and the stack also fits in one page. Assume further that an integer requires 4 bytes for storage. Compute the number of TLB misses if the page size is 4096 and the TLB has 8 entries with a replacement policy consisting of LRU.

Discussion Problem

Everyone should attempt this problem before the discussion section, but no one is required to turn it in.

  1. A computer system has a page size of 1,024 bytes and maintains the page table for each process in main memory. The overhead required for doing a lookup in the page table is 500 ns. To reduce this overhead, the comnputer has a TLB that caches 32 virtual pages to physical frame mappings. A TLB lookup requires 100ns. What TLB hit-rate is required to ensure an average virtual address translation time of 200ns?

  2. Discuss the issues involved in picking a page size for a virtual memory system.
    1. Name one issue that argues for small page sizes? Name two that argue for large page sizes?
    2. How do the characteristics of disks influence the selection of a page size?

Discussion Problem

Everyone should attempt this problem before the discussion section, but no one is required to turn it in.

Bryant and OHallaron CSAPP (first edition) Problem: 10.19