Pages moving between RAM and virtual memory

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Pages moving between RAM and virtual memory

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. In paging, how is data divided up?
A Into variable-size files chosen by the user
B Into fixed-size blocks called pages
2. Which pages are moved out of RAM into virtual memory?
A Pages that are not currently needed (idle)
B Pages the CPU is using right now
3. The CPU needs a page that is stored in virtual memory. What happens?
A The page is swapped back into RAM
B The CPU runs the page directly from the hard drive
4. RAM is full and a new page is needed. What does the computer do first?
A Deletes the oldest page permanently
B Moves an idle page out to virtual memory to make room
5. Where is virtual memory located?
A On secondary storage, such as a hard drive or SSD
B Inside the CPU

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1page Apaging
2swap out BThe page must be swapped back into RAM before the CPU can use it
3A page the CPU needs is in virtual memory, so it is copied back into RAM CMove an idle page from RAM to virtual memory to free up space
4Data is split into equal-sized blocks so it can be moved easily DA fixed-size block of data that can be moved between RAM and virtual memory
5Pages are different sizes so they fit any gap in RAM EPages are all the same fixed size, not different sizes
6The CPU runs a page straight from virtual memory Fswap in

Definitions

paging

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
SWAP idlePage FROM RAM TO _____________
2.
SWAP page2 FROM virtualMemory TO ___
3.
IF page3Needed = TRUE ____ SWAP page3 FROM virtualMemory TO RAM ENDIF
4.
numPages ← dataSize ___ pageSize
5.
_____ ramFull = TRUE DO SWAP idlePage FROM RAM TO virtualMemory ENDWHILE

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A RAM ← [P1, P2, P3]
B idle ← P4
C MOVE idle FROM RAM TO VM
Question 2
A pageSize ← RANDOM(1, 9)
B pages ← CEIL(size / pageSize)
C OUTPUT pages
Question 3
A IF CPU needs page P5 THEN
B IF P5 is in VM THEN
C SWAP P5 OUT OF RAM
D ENDIF
E ENDIF
Question 4
A FOR each page in RAM
B IF page is in use THEN
C MOVE page TO VM
D ENDIF
E ENDFOR
Question 5
A RAM_FULL ← TRUE
B IF RAM_FULL = FALSE THEN
C MOVE idle page TO VM
D ENDIF

Answer Key

Pages moving between RAM and virtual memory
Section A: Quick Questions
Q1
B — Into fixed-size blocks called pages
Q2
A — Pages that are not currently needed (idle)
Q3
A — The page is swapped back into RAM
Q4
B — Moves an idle page out to virtual memory to make room
Q5
A — On secondary storage, such as a hard drive or SSD
Section B: Match the Pairs
Q1
page → A fixed-size block of data that can be moved between RAM and virtual memory
Q2
swap out → Move an idle page from RAM to virtual memory to free up space
Q3
A page the CPU needs is in virtual memory, so it is copied back into RAM → swap in
Q4
Data is split into equal-sized blocks so it can be moved easily → paging
Q5
Pages are different sizes so they fit any gap in RAM → Pages are all the same fixed size, not different sizes
Q6
The CPU runs a page straight from virtual memory → The page must be swapped back into RAM before the CPU can use it
Section C: Definitions
Q1
paging — Data is split into fixed-size pages. Idle pages are moved out of RAM into virtual memory, then swapped back into RAM when the CPU needs them.
Section D: Fill in the Blanks
Q1
SWAP idlePage FROM RAM TO virtualMemory
Q2
SWAP page2 FROM virtualMemory TO RAM
Q3
IF page3Needed = TRUE THEN SWAP page3 FROM virtualMemory TO RAM ENDIF
Q4
numPages ← dataSize DIV pageSize
Q5
WHILE ramFull = TRUE DO SWAP idlePage FROM RAM TO virtualMemory ENDWHILE
Section E: Spot the Error
Q1
B — The idle page must be one that is currently in RAM so it can be swapped out. P4 is not in RAM (RAM holds P1, P2 and P3). It should be a RAM page such as idle ← P2.
Q2
A — Pages are fixed-size blocks of data, so the page size must be a constant value such as 4096, not a random number.
Q3
C — The CPU needs P5 and it is in virtual memory, so it must be swapped INTO RAM. Swapping it out of RAM is the wrong direction.
Q4
B — Only idle pages (not currently needed) should be moved out to virtual memory. Moving pages that are in use would slow the program. It should be IF page is idle THEN.
Q5
B — Idle pages are moved to virtual memory to free space when RAM is full. The condition should be IF RAM_FULL THEN, not when RAM is not full.