Operating systems, software and translators · A level · OCR H446 1.2.1, AQA 7517 4.6.1.4, Eduqas A500QS 2.6 · about 40 min
Logical and physical addresses, page tables, segments, page faults and disk thrashing.
[1 mark]With a page size of 1000 bytes, what is the physical address of logical address 2345, if page 2 is stored in frame 7?
[1 mark]How does segmentation differ from paging?
[1 mark]What happens when a process uses an address in a page that is currently on disk?
[1 mark]What is the term for the state where a computer spends more time swapping pages between memory and disk than running processes?
[1 mark]What does this program print?
PAGE = 256
table = {0: 4, 1: 9}
for address in [10, 300]:
page, offset = address // PAGE, address % PAGE
print(address, page, offset, table[page] * PAGE + offset)[1 mark]Which problem does virtual memory solve?
Write translate(address) for a paging system. The inputs are:
- PAGE_SIZE, the size of a page and a frame in bytes (256);
- page_table, a dictionary from page number to frame number, where None means the page is on disk;
- free_frames, a list of frame numbers that are free, used from the front;
- addresses, the logical addresses to translate, each a whole number from 0 to 1023.
For each address, work out the page number and offset. If the page's entry is None, handle the page fault: take the first frame out of free_frames, store it in the page table, and print page fault: page <page> loaded into frame <frame>. Then print <address> -> page <page> offset <offset> -> <physical address>, and return the physical address. Call translate for every address in addresses, in order. A page that was loaded by an earlier fault is in memory now, so it does not fault again. The robot stays still.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
PAGE_SIZE = 256
page_table = {0: 5, 1: 2, 2: None, 3: 7}
free_frames = [1, 4]
addresses = [300, 12, 600, 1000, 700]
def translate(address):
passPlan your program here, then type it in and press Run.
free_frames is empty, a page must be swapped out. Choose the page that was loaded first, set its entry back to None, and reuse its frame. Add enough addresses to cause it.