Problem 3.
Consider two possible page-replacement strategies: LRU (the least
recently used page is replaced) and FIFO (the page that has been in
the memory longest is replaced). The merit of a page-replacement
strategy is judged by its hit ratio.
Assume that, after space has been reserved for the page table, the
interrupt service routines, and the operating-system kernel, there is
only sufficient room left in the main memory for
four
user-program pages. Assume also that initially virtual pages 1, 2, 3,
and 4 of the user program are brought into physical memory in that
order.
-
For each of the two strategies, what pages will be in the memory
at the end of the following sequence of virtual page accesses? Read
the sequence from left to right: (6, 3, 2, 8, 4).
LRU:
start: 4 3 2 1
access 6: replace 1 => 6 4 3 2
access 3: reorder list => 3 6 4 2
access 2: reorder list => 2 3 6 4
access 8: replace 4 => 8 2 3 6
access 4: replace 6 => 4 8 2 3
FIFO:
start: 4 3 2 1
access 6: replace 1 => 6 4 3 2
access 3: no change => 6 4 3 2
access 2: no change => 6 4 3 2
access 8: replace 2 => 8 6 4 3
access 4: no change => 8 6 4 3
-
Which (if either) replacement strategy will work best when the
machine accesses pages in the following (stack) order: (3, 4, 5, 6,
7, 6, 5, 4, 3, 4, 5, 6, 7, 6, ...)?
LRU misses on pages 3 & 7 => 2/8 miss rate.
FIFO doesn't work well on stack accesses => 5/8 miss rate.
-
Which (if either) replacement strategy will work best when the
machine accesses pages in the following (repeated sequence) order: (3,
4, 5, 6, 7, 3, 4, 5, 6, 7, ...).
Both strategies have a 100% miss rate in the steady state.
-
Which (if either) replacement strategy will work best when the
machine accesses pages in a randomly selected order, such as (3, 4,
2, 8, 7, 2, 5, 6, 3, 4, 8, ...).
Neither FIFO nor LRU is guaranteed to be the better strategy
in dealing with random accesses since there is no locality to
the reference stream.
Problem 4.
A paged memory with a one-level page table has the following
parameters: The pages are 2
P bytes long; virtual addresses
are V bits long, organized as follows:
| virtual page number | offset in page |
The page-table starts at physical address PTBL; and each page-table
entry is a 4-byte longword, so that, given a virtual address, the
relevant page-table entry can be found at PTBL + (page number)*4.
Answer the following in terms of the parameters P and V:
-
How many bits long is the "offset in page" field?
It takes log2(2P) = P address bits to select a single byte
from a page with 2P bytes.
-
How many bits long is the "virtual page number" field?
Since there a P bits in the offset field, the remaining V-P bits are
part of the virtual page number.
-
How many entries does the page table have, and what is the
highest address occupied by a page-table entry?
Since the virtual page number field has V-P bits, there are 2V-P
virtual pages and each has its own entry in the page table. Each entry
is 4 bytes longs, so the highest address occupied by a page table entry
is PTBL + 4*(2(V-P)-1).
-
How many pages long is the page table?
There are 2P/4 page table entries per page and 2V-P
pages, so the page table is 2V-P/2P-2 = 2V-2P+2
pages long.
-
What is the smallest value of P such that the
page table fits into one page?
Using the formula from the previous question, to make the page table fit in
one page, we want V-2P+2 = 0. Solving for P we get
P = V/2 + 1.
-
What relationships, if any, must hold between P, V, and the
size of physical memory?
Suppose physical memory contained 2M bytes. Then
- The physical page number must fit in 30 bits since we reserve 2 bits of the
32-bits page table entry for the dirty and resident control bits. So
30 >= M - P.
- It useful to have room in memory for at least one page other than those
occupied by the page map. So M > V-P+2.
Problem 5.
-
If virtual addresses are V bits long, physical addresses are
A bits long, the page size is 2P bytes, and a one-level page
table is used, give an expression for the size of the page table.
There are 2V-P pages and the page table entry for each page
contains a physical page number (A-P bits), a dirty bit (1 bit) and a
resident bit (1 bit). So the page table occupies 2V-P(A-P+2) bits.
Problem 6.
Adverbs Unlimited has recently added a new product, the VIRTUALLY
to the product line introduced in an earlier tutorial problem. The
VIRTUALLY has a fully-associative cache with 256 entries and a block size
of 1,
2
20 bytes of physical memory, 16-bit virtual addresses, and
a 2
6-entry page map. The VIRTUALLY will be used to support
multiuser time-sharing. The page map holds the address translation for
a single (current) process and must be reloaded (by the kernel) at
each process switch. The cache is located between the page map and
main memory.
-
What is the page size?
page size in bytes = size of virtual address divided by number of
entries in the page map = 216/26 = 210
bytes per page.
-
Which virtual address lines are used to form the index to the
page map?
The virtual page number is used as the index to the page map. The
virtual page number includes all virtual address bits that aren't part
of the page offset. Since there 210 bytes per page, the
page offset requires 10 bits, i.e., address bits 0 through 9. The
remaining six bits (bits 10 through 15) form the virtual page number.
-
Can the operation of the cache and page-map be overlapped?
Explain in a single sentence.
No since we can't search the cache until we have the physical page
number from the page map.
-
Under what circumstances, if any, must the cache be invalidated
(that is, its entries marked as invalid)?
Since the cache is located after the page map, it caches physical
addresses. So it must be invalidated when there is a page replacement
due to a page fault, since this operation changes the contents of physical
memory.
Problem 7.
-
Program A consists of 1000 consecutive ADD instructions, while
program B consists of a loop that executes a single ADD instruction
1000 times. You run both programs on a certain machine and find that
program B consistently executes faster. Give two plausible
explanations.
Explanation #1: one would expect the loop to achieve a higher hit
rate in the cache since it involves many fewer instruction words.
Explanation #2: the loop, occupying many fewer instruction words,
should all fit onto a single page. The 1000 instructions might
span several pages and hence their execution may involve some
page faults.