Memory Management Flashcards
The IBM 360 had a scheme of locking 2-KB blocks by assigning each one a 4-bit key and
having the CPU compare the key on every memory reference to the 4-bit key in the PSW.
Name two drawbacks of this scheme not mentioned in the text.
First, special hardware is needed to do the comparisons, and it must be fast, since it is used on
every memory reference. Second, with 4-bit keys, only 16 programs can be in memory at once
(one of which is the operating system).
In Fig. 3-3 (https://imgur.com/a/DbYhqga) the base and limit registers contain the same value, 16,384. Is this just an
accident, or are they always the same? It is just an accident, why are they the same in this
example?
It is an accident. The base register is 16,384 because the program happened to be loaded at
address 16,384. It could have been loaded anywhere. The limit register is 16,384 because the
program contains 16,384 bytes. It could have been any length. That the load address happens to
exactly match the program length is pure coincidence.
A swapping system eliminates holes by compaction. Assuming a random distribution of
many holes and many data segments and a time to read or write a 32-bit memory word of 4 nsec, about how long does it take to compact 4 GB? For simplicity, assume that word 0 is part
of a hole and that the highest word in memory contains valid data.
Almost the entire memory has to be copied, which requires each word to be read and then
rewritten at a different location. Reading 4 bytes takes 4 nsec, so reading 1 byte takes 1 nsec
and writing it takes another 1 nsec, for a total of 2 nsec per byte compacted. This is a rate of
500,000,000 bytes/sec. To copy 4 GB (2³² bytes, which is about 4.295 × 10⁹ bytes), the computer
needs 2³²/500,000,000 sec, which is about 8.599 msec. This number is slightly pessimistic
because if the initial hole at the bottom of memory is k bytes, those k bytes do not need to be
copied. However, if there are many holes and many data segments, the holes will be small, so k
will be small and the error in the calculation will also be small.
Consider a swapping system in which memory consists of the following hole sizes in
memory order: 10 MB, 4 MB, 20 MB, 18 MB, 7 MB, 9 MB, 12 MB, and 15 MB. Which hole is
taken for successive segment requests of (a) 12 MB, (b) 10 MB, and (c) 9 MB for first fit? Now
repeat the question for best fit, worst fit, and next fit.
● First fit takes 20 MB, 10 MB, 18 MB.
● Best fit takes 12 MB, 10 MB, and 9 MB.
● Worst fit takes 20 MB, 18 MB, and 15 MB.
● Next fit takes 20 MB, 18 MB, and 9 MB.
What is the difference between a physical address and a virtual address?
https://imgur.com/a/Ru5zoEy
For each of the following decimal virtual addresses, compute the virtual page number and
offset for a 4-KB page and for an 8 KB page: 20000, 32768, 60000.
(TUT7)
For the page size of 4 KB, page offset is 12 bits and for the page size 8 KB, page offset is 13 bits.
The page offset for 20000 is 3616 for both the pages of 4 KB and 8 KB size. The virtual page
number for 4 KB page will be 4 (that is 1000) and for 8 KB page is 2, the virtual page number will
be 1010.
The page offset for 32768 is 0 for both the pages of 4 KB and 8 KB size. The virtual page number
for 4 KB page will be 8 (that is 1000) and for 8 KB page is 4, the virtual page number will be
1050.
The page offset for 60000 is 2656 for both the pages of 4 KB and 8 KB size. The virtual page
number for 4 KB page will be 14 (that is 2025) and for 8 KB page is 7, the virtual page number
will be 1250.
For a 4-KB page size the (page, offset) pairs are (4, 3616), (8, 0), and (14, 2656). For an 8-KB page
size they are (2, 3616), (4, 0), and (7, 2656).
Using the page table of Fig. 3-9 (https://imgur.com/a/GIeyIaH), give the physical address corresponding to each of the
following virtual addresses: 20, 4100, and 8300.
a) 8212
b) 4100
c) 24684
The Intel 8086 processor did not have an MMU or support virtual memory. Nevertheless,
some companies sold systems that contained an unmodified 8086 CPU and did paging. Make
an educated guess as to how they did it. (Hint: Think about the logical location of the MMU.)
They built an MMU and inserted it between the 8086 and the bus. Thus all 8086 physical
addresses went into the MMU as virtual addresses. The MMU then mapped them onto physical
addresses, which went to the bus.
What kind of hardware support is needed for a paged virtual memory to work?
There needs to be an MMU that can remap virtual pages to physical pages. Also, when a page
not currently mapped is referenced, there needs to be a trap to the operating system so it can
fetch the page.
Copy on write is an interesting idea used on server systems. Does it make any sense on a
smartphone?
If the smartphone supports multiprogramming, which the iPhone, Android, and Windows
phones all do, then multiple processes are supported. If a process forks and pages are shared
between parent and child, copy on write definitely makes sense. A smartphone is smaller than a
server, but logically it is not so different.
Consider the following C program:
int X[N];
int step = M; /* M is some predefined constant */
for (int i = 0; i < N; i += step) X[i] = X[i] + 1;
a) If this program is run on a machine with a 4-KB page size and 64-entry TLB, what values
of M and N will cause a TLB miss for every execution of the inner loop?
b) Would your answer in part (a) be different if the loop were repeated many times?
Explain.
(TUT7)
Minimum int size is 4 bytes which gives us 1024 integers per 4-KB memory page.
a) It means that after X[0] is accessed, accessing any of the succeeding elements up to
X[1023] would not generate TLB fault. However, if we try to access X[0], X[1024], X[2048]
and so on, each time a TLB miss will occur which means that M should be at least 1024.
b) M should still be at least 1024 to cause a TLB miss for every execution of the inner loop.
Assuming that such page replacement algorithm as FIFO is used, we need to fill the
whole TLB and make one more reference to an absent page to make sure that the page 0
is not in the TLB at the beginning of each outer cycle. It means that we need to have at
least 65 pages. In this case N should be at least 64 * 1024 + 1.
The amount of disk space that must be available for page storage is related to the
maximum number of processes, n, the number of bytes in the virtual address space, v, and the
number of bytes of RAM, r. Give an expression for the worst-case disk-space requirements.
How realistic is this amount?
(TUT7)
The total virtual address space for all the processes combined is n · v, so this much storage is
needed for pages. However, an amount r can be in RAM, so the amount of disk storage required
is only n · v – r. This amount is far more than is ever needed in practice because rarely will there
be n processes actually running and even more rarely will all of them need the maximum
allowed virtual memory.
- If an instruction takes 1 nsec and a page fault takes an additional n nsec, give a formula for
the effective instruction time if page faults occur every k instructions.
Given that each instruction takes 1 nsec to execute. To execute k instructions it takes k nsec.
After k instructions a page fault occurs, to handle a page fault it requires n nsec. Therefore, to
execute k instruction with a page fault it requires (k + n) nsec. Therefore, when it takes (k + n)
nsec to execute k instructions then it requires (k + n) / k nsec for each instruction. The formula
for effective instruction time is (k + n) / k.
A machine has a 32-bit address space and an 8-KB page. The page table is entirely in
hardware, with one 32-bit word per entry. When a process starts, the page table is copied to
the hardware from memory, at one word every 100 nsec. If each process runs for 100 msec
(including the time to load the page table), what fraction of the CPU time is devoted to
loading the page tables?
(FE17) (FFE18)
The page table contains 2³²/2¹³ = 2¹⁹ entries, which is 524,288.
To copy one entry into the hardware, 100 nsec are required. Therefore, to load 2¹⁹ entries, the
time required is 2¹⁹ × 100 nsec = 52,428,800 nsec = 52 msec.
Loading the page table takes 52,43 msec. If a process gets 100 msec, this consists of 52 msec for
loading the page table and 48 msec for running. Thus 52,43% of the time is spent loading page
tables.
Suppose that a machine has 48-bit virtual addresses and 32-bit physical addresses.
a) If pages are 4 KB, how many entries are in the page table if it has only a single level?
Explain.
b) Suppose this same system has a TLB (Translation Lookaside Buffer) with 32 entries.
Furthermore, suppose that a program contains instructions that fit into one page and
it sequentially reads long integer elements from an array that spans thousands of
pages. How effective will the TLB be for this case?
(FE17)
Answer:
a) Given that the virtual address space is 48-bit and the pages are 4KB (2² × 2¹⁰ = 2¹²), the
number of entries in the page table is given by: 2⁴⁸ / 2¹² = 2³⁶ = 68,719,476,736.
b) TLB (Transaction look-aside buffer) will be very effective in this case. The instruction
addresses would achieve 100% hits in the TLB. Data pages would also achieve a hit rate
of 100% unless the program moves to the next page for data. A 4 KB page has the
capability to store 1024 long integer values. Thus single misses in the TLB will be
observed and an extra memory access will be observed for every 1024 references to
data.
You are given the following data about a virtual memory system:
a) The TLB can hold 1024 entries and can be accessed in 1 clock cycle (1 nsec).
b) A page table entry can be found in 100 clock cycles or 100 nsec.
c) The average page replacement time is 6 msec.
If page references are handled by the TLB 99% of the time, and only 0.01% lead to a page
fault, what is the effective address-translation time?
The chance of a hit is 0.99 for the TLB, 0.0099 for the page table, and 0.0001 for a page fault.
The effective address translation time in nsec is then: 0. 99 × 1 + 0.0099 × 100 + 0.0001 × 6 × 10⁶
≈ 602 nsec.
Note that the effective address translation time is quite high because it is dominated by the
page replacement time even when page faults only occur once in 10,000 references.
Suppose that a machine has 38-bit virtual addresses and 32-bit physical addresses.
a) What is the main advantage of a multilevel page table over a single-level one?
b) With a two-level page table, 16-KB pages, and 4-byte entries, how many bits should be
allocated for the top-level page table field and how many for the next level page table
field? Explain.
Consider:
a) A multilevel page table reduces the number of actual pages of the page table that need
to be in memory because of its hierarchic structure. In fact, in a program with lots of
instruction and data locality, we only need the top level page table (one page), one
instruction page, and one data page.
b) Allocate 12 bits for each of the three page fields. The offset field requires 14 bits to
address 16 KB. That leaves 24 bits for the page fields. Since each entry is 4 bytes, one
page can hold 2¹² page table entries and therefore requires 12 bits to index one page. So
allocating 12 bits for each of the page fields will address all 2³⁸ bytes.
Section 3.3.4 states that the Pentium Pro extended each entry in the page table hierarchy
to 64 bits but still could only address only 4 GB of memory. Explain how this statement can be
true when page table entries have 64 bits.
The virtual address was changed from (PT1, PT2, Offset) to (PT1, PT2, PT3, Offset). But the
virtual address still used only 32 bits. The bit configuration of a virtual address changed from
(10, 10, 12) to (2, 9, 9, 12).
A computer with a 32-bit address uses a two-level page table. Virtual addresses are split
into a 9-bit top-level page table field, an 11-bit second-level page table field, and an offset.
How large are the pages and how many are there in the address space?
Total bits = Virtual page numbers (VPN) + offset bits
Number of bytes per page = 2^offset bits
Number of pages in the address space = 2^number of virtual page numbers
Twenty bits are used for the virtual page numbers, leaving 12 over for the offset. This yields a 4-
KB page. Twenty bits for the virtual page implies 2²⁰ pages.