• Home
  • Textbooks
  • Operating System Concepts Essentials
  • Virtual Memory

Operating System Concepts Essentials

Abraham Silberschatz, Peter B. Galvin, Greg Gagne

Chapter 8

Virtual Memory - all with Video Answers

Educators


Chapter Questions

Problem 1

Under what circumstances do page faults occur? Describe the actions taken by the operating system when a page fault occurs.

Check back soon!
01:40

Problem 2

Assume that you have a page-reference string for a process with $m$ frames (initially all empty). The page-reference string has length $p$; $n$ distinct page numbers occur in it. Answer these questions for any page-replacement algorithms
a. What is a lower bound on the number of page faults?
b. What is an upper bound on the number of page faults?

James Kiss
James Kiss
Numerade Educator

Problem 3

Which of the following programming techniques and structures are "good" for a demand-paged environment ? Which are "not good"? Explain your answers.
a. Stack
b. Hashed symbol table
c. Sequential search
d. Binary search
e. Pure code
f. Vector operations
g. Indirection

Check back soon!
01:40

Problem 4

Consider the following page-replacement algorithms. Rank these algorithms on a five-point scale from "bad" to "perfect" according to their page-fault rate. Separate those algorithms that suffer from Belady's anomaly from those that do not.
a. LRU replacement
b. FIFO replacement
c. Optimal replacement
d. Second-chance replacement

James Kiss
James Kiss
Numerade Educator

Problem 5

When virtual memory is implemented in a computing system, there are certain costs associated with the technique and certain benefits. List the costs and the benefits. Is it possible for the costs to exceed the benefits? If it is, what measures can be taken to ensure that this does not happen?

Check back soon!

Problem 6

An operating system supports a paged virtual memory, using a central processor with a cycle time of 1 microsecond. It costs an additional 1 microsecond to access a page other than the current one. Pages have 1,000
Chapter 8 Virtual Memory
words, and the paging device is a drum that rotates at 3,000 revolutions per minute and transfers 1 million words per second. The following statistical measurements were obtained from the system:
- One percent of all instructions executed accessed a page other than the current page.
- Of the instructions that accessed another page, 80 percent accessed a page already in memory.
- When a new page was required, the replaced page was modified 50 percent of the time.

Calculate the effective instruction time on this system, assuming that the system is running one process only and that the processor is idle during drum transfers.

Check back soon!
01:23

Problem 7

Consider the two-dimensional array A:
$$
\text { int } A[][]=\text { new int }[100][100] \text {; }
$$
where $A[0][0]$ is at location 200 in a paged memory system with pages of size 200 . A small process that manipulates the matrix resides in page 0 (locations 0 to 199). Thus, every instruction fetch will be from page 0 .
For three page frames, how many page faults are generated by the following array-initialization loops, using LRU replacement and assuming that page frame 1 contains the process and the other two are initially empty?
a. for (int $j=0 ; j<100 ; j++$ )
for (int $i=0$; $i<100 ; i++$ )
$A[i][j]=0$;
b. for (int $i=0$; $i<100 ; i++$ )
for (int $j=0 ; j<100 ; j++$ )
$A[i][j]=0$;

James Kiss
James Kiss
Numerade Educator
01:23

Problem 8

Consider the following page reference string:
$$
1,2,3,4,2,1,5,6,2,1,2,3,7,6,3,2,1,2,3,6
$$
How many page faults would occur for the following replacement algorithms, assuming one, two, three, four, five, six, and seven frames? Remember that all frames are initially empty, so your first unique pages will cost one fault each.
- LRU replacement
- FIFO replacement
- Optimal replacement

James Kiss
James Kiss
Numerade Educator

Problem 9

Suppose that you want to use a paging algorithm that requires a reference bit (such as second-chance replacement or working-set model), but the hardware does not provide one. Sketch how you could simulate a reference bit even if one were not provided by the hardware, or explain
why it is not possible to do so. If it is possible, calculate what the cost would be.

Check back soon!

Problem 10

You have devised a new page-replacement algorithm that you think may be optimal. In some contorted test cases, Belady's anomaly occurs. Is the new algorithm optimal? Explain your answer.

Check back soon!

Problem 11

Segmentation is similar to paging but uses variable-sized "pages." Define two segment-replacement algorithms based on FIFO and LRU pagereplacement schemes. Remember that since segments are not the same size, the segment that is chosen to be replaced may not be big enough to leave enough consecutive locations for the needed segment. Consider strategies for systems where segments cannot be relocated and strategies for systems where they can.

Check back soon!
02:17

Problem 12

Consider a demand-paged computer system where the degree of multiprogramming is currently fixed at four. The system was recently measured to determine utilization of the CPU and the paging disk. The results are one of the following alternatives. For each case, what is happening? Can the degree of multiprogramming be increased to increase the CPU utilization? Is the paging helping?
a. CPU utilization 13 percent; disk utilization 97 percent
b. CPU utilization 87 percent; disk utilization 3 percent
c. CPU utilization 13 percent; disk utilization 3 percent

Adam Conner
Adam Conner
Numerade Educator
01:22

Problem 13

We have an operating system for a machine that uses base and limit registers, but we have modified the machine to provide a page table. Can the page tables be set up to simulate base and limit registers? How can they be, or why can they not be?

Adam Conner
Adam Conner
Numerade Educator

Problem 14

Assume that a program has just referenced an address in virtual memory. Describe a scenario in which each of the following can occur. (If no such scenario can occur, explain why.)
- TLB miss with no page fault
- TLB miss and page fault
- TLB hit and no page fault
- TLB hit and page fault

Check back soon!

Problem 15

A simplified view of thread states is Ready, Running, and Blocked, where a thread is either ready and waiting to be scheduled, is running on the processor, or is blocked (i.e. is waiting for $1 / 0$.) This is illustrated in Figure 8.31. Assuming a thread is in the Running state, answer the following questions: (Be sure to explain your answer.)
FIGURE CAN'T COPY
Figure 8.31 Thread state diagram for Exercise 8.15.
a. Will the thread change state if it incurs a page fault? If so, to what new state?
b. Will the thread change state if it generates a TLB miss that is resolved in the page table? If so, to what new state?
c. Will the thread change state if an address reference is resolved in the page table? If so, to what new state?

Check back soon!
01:40

Problem 16

Consider a system that uses pure demand paging.
a. When a process first starts execution, how would you characterize the page-fault rate?
b. Once the working set for a process is loaded into memory, how would you characterize the page-fault rate?
c. Assume that a process changes its locality and the size of the new working set is too large to be stored in available free memory. Identify some options system designers could choose from to handle this situation.

James Kiss
James Kiss
Numerade Educator

Problem 17

Give an example that illustrates the problem with restarting the move character instruction (MVC) on the IBM 360/370 when the source and destination regions are overlapping.

Check back soon!

Problem 18

Discuss the hardware support required to support demand paging.

Check back soon!

Problem 19

What is the copy-on-write feature, and under what circumstances is it beneficial to use this feature? What hardware support is required to implement this feature?

Check back soon!

Problem 20

A certain computer provides its users with a virtual memory space of $2^{32}$ bytes. The computer has $2^{18}$ bytes of physical memory. The virtual memory is implemented by paging, and the page size is 4,096 bytes. A user process generates the virtual address 11123456. Explain how the system establishes the corresponding physical location. Distinguish between software and hardware operations.

Check back soon!
02:15

Problem 21

Assume that we have a demand-paged memory. The page table is held in registers. It takes 8 milliseconds to service a page fault if an empty frame is available or if the replaced page is not modified and 20 milliseconds if the replaced page is modified. Memory-access time is 100 nanoseconds.
Exercises $\quad 375$
Assume that the page to be replaced is modified 70 percent of the time. What is the maximum acceptable page-fault rate for an effective access time of no more than 200 nanoseconds?

James Kiss
James Kiss
Numerade Educator
01:40

Problem 22

When a page fault occurs, the process requesting the page must block while waiting for the page to be brought from disk into physical memory. Assume that there exists a process with five user-level threads and that the mapping of user threads to kernel threads is many to one. If one user thread incurs a page fault while accessing its stack, would the other user threads belonging to the same process also be affected by the page fault - that is, would they also have to wait for the faulting page to be brought into memory? Explain.

James Kiss
James Kiss
Numerade Educator

Problem 23

Consider the page table for a system with 12-bit virtual and physical addresses with 256-byte pages. The list of free page frames is $D, E, F$ (that is, $D$ is at the head of the list, $E$ is second, and $F$ is last).
$$
\begin{array}{|c|c|}
\hline \text { Page } & \text { Page Frame } \\
\hline \hline 0 & - \\
\hline 1 & 2 \\
\hline 2 & \text { C } \\
\hline 3 & \text { A } \\
\hline 4 & - \\
\hline 5 & 4 \\
\hline 6 & 3 \\
\hline 7 & - \\
\hline 8 & \text { B } \\
\hline 9 & 0 \\
\hline
\end{array}
$$
Convert the following virtual addresses to their equivalent physical addresses in hexadecimal. All numbers are given in hexadecimal. (A dash for a page frame indicates that the page is not in memory.)
- 9EF
- 111
- 700
- $0 \mathrm{FF}$

Check back soon!
02:17

Problem 24

Assume that you are monitoring the rate at which the pointer in the clock algorithm (which indicates the candidate page for replacement) moves. What can you say about the system if you notice the following behavior:
a. Pointer is moving fast.
b. Pointer is moving slow.
Chapter 8 Virtual Memory

James Kiss
James Kiss
Numerade Educator

Problem 25

Discuss situations in which the LFU page-replacement algorithm generates fewer page faults than the LRU page-replacement algorithm. Also discuss under what circumstances the opposite holds.

Check back soon!

Problem 26

Discuss situations in which the MFU page-replacement algorithm generates fewer page faults than the LRU page-replacement algorithm. Also discuss under what circumstances the opposite holds.

Check back soon!
01:23

Problem 27

The VAX/VMS system uses a FIFO replacement algorithm for resident pages and a free-frame pool of recently used pages. Assume that the free-frame pool is managed using the LRU replacement policy. Answer the following questions:
a. If a page fault occurs and if the page does not exist in the free-frame pool, how is free space generated for the newly requested page?
b. If a page fault occurs and if the page exists in the free-frame pool, how is the resident page set and the free-frame pool managed to make space for the requested page?
c. What does the system degenerate to if the number of resident pages is set to one?
d. What does the system degenerate to if the number of pages in the free-frame pool is zero?

James Kiss
James Kiss
Numerade Educator
01:45

Problem 28

Consider a demand-paging system with the following time-measured utilizations:
$\begin{array}{lr}\text { CPU utilization } & 20 \% \\ \text { Paging disk } & 97.7 \% \\ \text { Other 1/O devices } & 5 \%\end{array}$
For each of the following, say whether it will (or is likely to) improve CPU utilization. Explain your answers.
a. Install a faster CPU.
b. Install a bigger paging disk.
c. Increase the degree of multiprogramming.
d. Decrease the degree of multiprogramming.
e. Install more main memory.
f. Install a faster hard disk or multiple controllers with multiple hard disks.
g. Add prepaging to the page-fetch algorithms.
h. Increase the page size.

James Kiss
James Kiss
Numerade Educator
02:33

Problem 29

Suppose that a machine provides instructions that can access memory locations using the one-level indirect addressing scheme. What sequence of page faults is incurred when all of the pages of a program are currently nonresident and the first instruction of the program is an indirect memory-load operation? What happens when the operating

Shelby Mohamed
Shelby Mohamed
Numerade Educator
01:40

Problem 30

Suppose that your replacement policy (in a paged system) is to examine each page regularly and to discard that page if it has not been used since the last examination. What would you gain and what would you lose by using this policy rather than LRU or second-chance replacement?

James Kiss
James Kiss
Numerade Educator

Problem 31

A page-replacement algorithm should minimize the number of page faults. We can achieve this minimization by distributing heavily used pages evenly over all of memory, rather than having them compete for a small number of page frames. We can associate with each page frame a counter of the number of pages associated with that frame. Then, to replace a page, we can search for the page frame with the smallest counter.
a. Define a page-replacement algorithm using this basic idea. Specifically address these problems:
i. What is the initial value of the counters?
ii. When are counters increased?
iii. When are counters decreased?
iv. How is the page to be replaced selected?
b. How many page faults occur for your algorithm for the following reference string with four page frames?
$$
1,2,3,4,5,3,4,1,6,7,8,7,8,9,7,8,9,5,4,5,4,2 .
$$
c. What is the minimum number of page faults for an optimal pagereplacement strategy for the reference string in part $b$ with four page frames?

Check back soon!
01:47

Problem 32

Consider a demand-paging system with a paging disk that has an average access and transfer time of 20 milliseconds. Addresses are translated through a page table in main memory, with an access time of 1 microsecond per memory access. Thus, each memory reference through the page table takes two accesses. To improve this time, we have added an associative memory that reduces access time to one memory reference if the page-table entry is in the associative memory.
Assume that 80 percent of the accesses are in the associative memory and that, of those remaining, 10 percent (or 2 percent of the total) cause page faults. What is the effective memory access time?

James Kiss
James Kiss
Numerade Educator
01:38

Problem 33

What is the cause of thrashing? How does the system detect thrashing? Once it detects thrashing, what can the system do to eliminate this problem?

Adam Conner
Adam Conner
Numerade Educator
00:20

Problem 34

Is it possible for a process to have two working sets, one representing data and another representing code? Explain.

Amy Jiang
Amy Jiang
Numerade Educator
01:26

Problem 35

Consider the parameter $\Delta$ used to define the working-set window in the working-set model. What is the effect of setting $\Delta$ to a small value on the page-fault frequency and the number of active (nonsuspended) processes currently executing in the system? What is the effect when
is set to a very high value?

Jake Rempel
Jake Rempel
Numerade Educator
01:39

Problem 36

Assume there is a 1,024-KB segment where memory is allocated using the buddy system. Using Figure 8.27 as a guide, draw a tree illustrating how the following memory requests are allocated:
- Request 240 bytes
- Request 120 bytes
- Request 60 bytes
- Request 130 bytes
Next, modify the tree for the following releases of memory. Perform coalescing whenever possible:
- Release 240 bytes
- Release 60 bytes
- Release 120 bytes

James Kiss
James Kiss
Numerade Educator
00:59

Problem 37

Consider a system that provides support for user-level and kernellevel threads. The mapping in this system is one to one (there is a corresponding kernel thread for each user thread). Does a multithreaded process consist of (a) a working set for the entire process or (b) a working set for each thread? Explain

James Kiss
James Kiss
Numerade Educator

Problem 38

The slab-allocation algorithm uses a separate cache for each different object type. Assuming there is one cache per object type, explain why this scheme doesn't scale well with multiple CPUs. What could be done to address this scalability issue?

Check back soon!

Problem 39

Consider a system that allocates pages of different sizes to its processes. What are the advantages of such a paging scheme? What modifications to the virtual memory system provide this functionality?
Programming Problems

Check back soon!

Problem 40

Write a program that implements the FIFO and LRU page-replacement algorithms presented in this chapter. First, generate a random pagereference string where page numbers range from 0 to 9. Apply the random page-reference string to each algorithm, and record the number of page faults incurred by each algorithm. Implement the replacement algorithms so that the number of page frames can vary from 1 to 7 . Assume that demand paging is used.

Check back soon!
01:07

Problem 41

The Catalan numbers are an integer sequence $C_n$ that appear in treeenumeration problems. The first Catalan numbers for $n=1,2,3, \ldots$ are $1,2,5,14,42,132, \ldots$. A formula generating $C_n$ is
$$
C_n=\frac{1}{(n+1)}\left(\frac{2 n}{n}\right)=\frac{(2 n) !}{(n+1) ! n !}
$$
Design two programs that communicate with shared memory using the Win32 API as outlined in Section 8.7.2. The producer process will generate the Catalan sequence and write it to a shared memory object. The consumer process will then read and output the sequence from shared memory.
In this instance, the producer process will be passed an integer parameter on the command line specifying how many Catalan numbers to produce (for example, providing 5 on the command line means the producer process will generate the first five Catalan numbers).

Mohamed Mohamed
Mohamed Mohamed
Numerade Educator