Description
CS 370 Assignment 4: Pagiminator! Fall 2026 focuses on implementing a paged virtual memory simulator using ANSI C. Students explore virtual address translation, page tables, translation lookaside buffers (TLB), demand paging, page faults, and FIFO page replacement. The assignment also covers dirty page write-backs, process isolation, context switching, and memory access statistics.
Assignment Description
In Shellminator (Assignment 1), you created simulated processes. In Schedulminator (Assignment 2), you
selected which process runs. In Memminator (Assignment 3), you translated virtual addresses using a base
and limit and allocated heap memory inside contiguous regions. This assignment extends the same simulated
machine to paged virtual memory. Processes still use virtual byte addresses, but their pages may occupy
nonadjacent physical frames or may not currently be in RAM. Your simulator must model a page table, a
translation lookaside buffer (TLB), page faults, and a simple page-replacement policy.
This is a simulation, not an implementation of the host operating system’s virtual memory. Do not call
real paging APIs, fork processes, map files, or use threads. Write portable ANSI C (C90).
Why Paging?
With the base/limit model, a process occupied one contiguous physical interval. That is simple to protect,
but it makes placement and growth difficult. Paging divides a process’s virtual address space into fixed-size
pages and RAM into equally sized frames. Each process has its own page table. Two processes may use
virtual address 20 while referring to entirely different physical bytes. Some virtual pages may be absent from
RAM; accessing one produces a page fault that the simulated OS must handle.
The Simulated Machine
Use these constants, which are deliberately small so you can trace the system by hand:
Page/frame size 16 bytes
RAM 128 bytes (8 physical frames)
Maximum processes 4
Virtual space per process 128 bytes (8 virtual pages)
TLB 4 entries, shared by the simulated CPU
Replacement policy FIFO (first loaded resident page evicted first)
Backing store One 128-byte array per process, provided in memory
The backing store is an ordinary C array, not a host file. The simulator starts with all page-table entries
marked nonresident, all frames free, and all TLB entries invalid. Every process has a unique PID. Each
frame has at most one owner, identified by (PID, virtual page number). All addresses and lengths are in
bytes.
Virtual Address Translation
For a valid virtual byte address v, compute
page =
j
v
16
k
, offset = v mod 16.
If the process’s page-table entry identifies resident frame f, the physical byte index is
physical = 16f + offset.
1
The virtual address must satisfy 0 ≤ v < 128. A memory access to an invalid virtual address is a protection
fault, not a page fault. An access to a valid virtual address whose page is not resident is a page fault; after
servicing the fault, retry the translation. Never index the RAM array until translation succeeds.
PID 1, virtual address 35: page 2, offset 3
If page 2 is resident in frame 6: physical address = 6*16+3 = 99
If page 2 is absent: PAGE FAULT, load page, then retry
PID 1, virtual address 128: PROTECTION FAULT
Page Tables and Frame Ownership
Each process has eight page-table entries. An entry records whether the page is present, its current frame
number (or INVALID), whether it is dirty, and the time/order in which it entered RAM (or equivalent FIFO
metadata). The machine tracks which frames are free and which (PID, page) owns each occupied frame.
Page-table entries belong to processes; frames and RAM belong to the machine. A process may have several
resident pages, and those pages need not occupy consecutive frames.
The Translation Lookaside Buffer (TLB)
The TLB caches recent translations. Each valid entry stores a PID, a virtual page number, and a physical
frame number. A lookup succeeds only when both the PID and page match. A TLB hit avoids a page-table
lookup; a miss consults the page table. When a translation becomes invalid because its page is evicted,
its cached TLB entry must no longer be usable. For this assignment, the scheduler flushes the entire TLB
whenever the CPU switches to a different PID. Track TLB hits and misses separately.
PID 0 reads virtual 18: page 1, offset 2 -> TLB MISS
PID 0 reads virtual 19: page 1, offset 3 -> TLB HIT
Switch PID 0 -> PID 1: TLB FLUSH
PID 1 reads virtual 18: page 1, offset 2 -> TLB MISS
Demand Paging and Page Faults
Initially no virtual page is resident. On a valid-address TLB miss, inspect the process’s page table. If its
page is absent, count one page fault and obtain a free frame. If RAM is full, select the oldest resident frame
using FIFO. Before reusing a victim frame, write its bytes back to the owning process’s backing store only
if the victim page is dirty. Mark the victim’s page-table entry nonresident, invalidate its cached translation,
load the requested page’s 16 bytes from the requesting process’s backing store, and update ownership and
page-table metadata. A newly loaded page is clean. The original access then completes. Count evictions
and dirty write-backs.
Important: FIFO is based on the order pages entered RAM, not the order in which they were most
recently accessed. A TLB hit does not change FIFO age. Do not implement LRU, CLOCK, or swapping
entire processes.
Reads, Writes, and the Previous Assignments
All simulated reads and writes must pass through the MMU. A memory operation is permitted only for the
active PID; passing a pointer to a different process record must not bypass isolation. A successful write
updates one RAM byte and marks the corresponding page dirty. A read does not mark a page dirty. Process
isolation follows from using the active process’s own page table and backing store, not from a contiguous
base register.
The heap offsets returned by the Assignment 3 simulated allocator remain virtual offsets: for example, a
block starting at virtual offset 30 can span pages 1 and 2. The allocation metadata is not itself a page table.
2
You do not need to reimplement malloc, calloc, realloc, or free. The supplied test driver may use
fixed virtual offsets as though they were returned by the earlier heap allocator. In your integration tests,
demonstrate that an access across a page boundary is translated byte by byte and that another process
cannot read the first process’s data by using the same virtual offset.
The Assignment 2 scheduler concept appears when a simulated context switch changes the active PID: flush
the TLB, but do not discard the processes’ page tables or resident frames. The Assignment 1 process concept
appears in the PID-specific address spaces and event trace.
Understanding the Simulator’s Data Structures
The provided structures represent distinct layers of a simulated memory system. They are not interchangeable, and a virtual address is never a host C pointer.
PageTableEntry One entry for one virtual page of one process. present indicates whether the page is
currently in RAM; frame identifies the physical frame or is INVALID; dirty records whether the
resident copy was modified; and loaded at records the page’s FIFO admission order. A nonresident
page can still have valid bytes in the backing store.
Process pid identifies a simulated process; pages[VIRTUAL PAGES] is its private page table; and backing[VIRTUAL SIZE]
is its persistent simulated backing store. Two processes have separate page tables and backing stores,
even when they refer to the same virtual page number or address.
Frame Describes one physical frame. occupied says whether it is in use; pid and page identify its current
owner; and loaded at records when that page entered the frame. These fields are metadata, not the
bytes stored in RAM.
TLBEntry One cached translation: valid marks whether the entry may be used, and pid, page, and frame
identify the translation. Matching only the virtual page is insufficient.
Machine Owns the shared ram byte array, physical frames, tlb, and registry of processes. process count
tracks registered processes; active pid identifies the process currently allowed to access memory;
tlb next supports TLB replacement; and sequence tracks FIFO admission order. The remaining fields
(accesses, tlb hits, tlb misses, page faults, evictions, writebacks, and protection faults)
are global statistics.
For example, PID 1’s virtual page 2 might be resident in physical frame 6. The process page table records
this mapping, the machine’s frame 6 records its owner as (PID 1, page 2), and a valid TLB entry may cache
the same mapping. The actual bytes reside in Machine.ram[96..111]; the process’s backing store contains
the persistent page image used for reloads. A second process’s virtual page 2 can be in a different frame.
Function Reference and Behavioral Examples
The @student functions form a small memory-management pipeline. The explanations below specify observable results, edge cases, and the responsibility of each function. They intentionally do not provide loops,
pseudocode, or step-by-step implementation instructions.
address parts(vaddr, page, offset)
This function describes a virtual byte location, not a physical frame. For a valid address it reports the page
containing that byte and the byte’s position within the page. It must reject addresses outside the process’s
virtual range without changing either output argument.
vaddr result
0 page 0, offset 0
15 page 0, offset 15
16 page 1, offset 0
3
31 page 1, offset 15
127 page 7, offset 15
-1, 128 INVALID; output variables unchanged
tlb lookup(m, pid, page)
The TLB is a small cache of translations, not a source of page contents. This function answers whether the
specified process and page have a usable cached frame. A miss returns INVALID; a hit returns the cached
frame. For example, (PID 1, page 2) may map to frame 6, while (PID 2, page 2) maps to frame 4. These
are different cache keys. The MMU, not this helper, counts TLB hits and misses.
tlb insert(m, pid, page, frame)
After a translation has been established, the simulator can remember it. Inserting (1,2,6) should make a
lookup of (1,2) return 6. If the mapping later changes to (1,2,3), subsequent lookups must not return frame
6. The TLB holds four entries; replacing a TLB entry does not evict a RAM page. The specified TLB
replacement policy is round-robin when no unused slot is available.
tlb invalidate(m, pid, page)
A cached mapping cannot remain usable after the underlying page is evicted. For example, invalidating
(1,2) should make a later lookup of (1,2) miss, without invalidating (2,2). Invalidating a mapping that is
not cached is harmless. The provided tlb flush() is different: it invalidates all cached mappings, as on a
context switch.
ensure resident(m, p, page)
This function answers the question: “Which physical frame currently holds this process’s virtual page?” If
the page is already resident, it can report its frame without another page fault. If the page is absent, the
simulated OS must make its bytes available in RAM and count a page fault. If RAM is full, FIFO decides
which resident page leaves RAM.
Initial state: all 8 frames are free.
PID 1 first accesses page 0: page fault; one frame becomes occupied.
PID 1 accesses page 0 again: still resident; no new page fault.
Eight distinct pages occupy the 8 frames.
PID 2 first accesses page 0: another fault; the oldest resident
page is evicted, regardless of which page was read most recently.
A clean evicted page does not require a dirty write-back. A dirty page must retain its modified bytes so
that a later reload produces the same values. The present, frame, and ownership fields must agree after
the operation.
mmu translate(m, p, vaddr)
This function is the boundary between a process’s virtual address and the machine’s physical RAM. It
rejects an invalid virtual address or a request from a nonactive process as a protection fault. For a permitted
address, it uses the current mapping, consulting demand paging when necessary.
PID 1, v=35 -> virtual page 2, offset 3.
If page 2 is in frame 6 -> physical byte 99.
If page 2 is resident but not cached -> TLB miss, no page fault.
If page 2 is absent -> TLB miss and page fault.
PID 1, v=128 -> protection fault, not page fault.
PID 2 requests access while PID 1 is active -> protection fault.
4
This function counts TLB hit/miss events and protection faults, but it does not count completed byte reads
or writes as successful accesses.
vm read(m, p, vaddr)
Reads a single byte through the MMU and returns its value from 0 through 255, or INVALID for a rejected
access. An untouched backing-store byte initially reads as zero. Repeated reads can change TLB statistics
without changing the byte. A read must not make a page dirty.
vm write(m, p, vaddr, value)
Writes one byte through the MMU, reports success/failure, and marks the resident page dirty. For example,
writing decimal 65 to virtual 35 and reading virtual 35 later should produce 65. The same virtual address
in another process remains independent. Invalid writes must not modify RAM. A successful read or write
counts as one access; a rejected one does not.
switch process(m, pid)
Models the scheduling decision from Assignment 2. A switch to a different registered PID clears cached TLB
mappings, but does not clear RAM or page tables. Switching to the same PID is valid and need not flush
the TLB. An unknown PID must be rejected without changing the current PID.
print report(m)
Prints cumulative counts for successful accesses, TLB hits, TLB misses, page faults, evictions, dirty writebacks, and protection faults. A TLB miss is not necessarily a page fault. For example, after a context switch,
a resident page may require a new TLB lookup without requiring another RAM frame. Use the exact report
labels in the starter file.
Provided Helpers
find process() finds a process by PID; machine init() prepares a clean simulated machine; add process()
registers a new PID with initially absent pages; and tlb flush() clears cached translations. Students do
not need to reimplement these helpers. The provided test functions create fresh machines so that the results
of one scenario do not affect another.
Ten Runnable Test Sessions
The starter now includes test 01() through test 10(). They are independent, labeled scenarios in the
provided main(). Run all ten or choose one by number:
gcc – std = c90 – pedantic – Wall – Wextra vm_handout . c -o pagiminator
./ pagiminator all
./ pagiminator 1
./ pagiminator 7
1. Address boundaries: exercise 0, 15, 16, 31, 32, 127, -1, and 128. Check page/offset and invalidaddress handling.
2. TLB cache operations: insert two PIDs’ mappings, test a miss, update an existing mapping, and
invalidate only one PID’s entry.
3. First page fault and subsequent hit: read virtual 18 and 19 in one process. Both addresses belong
to the same page.
4. Page boundary: write/read virtual 15 and 16, which belong to adjacent virtual pages.
5
5. Process isolation: write different values at virtual 35 for PID 1 and PID 2, then verify each process’s
value.
6. FIFO clean eviction: load eight distinct pages, then a ninth from another process. Inspect which
page is no longer resident.
7. Dirty eviction and reload: modify a page, fill RAM, evict it, then access it again. Check that its
original value survives.
8. Context-switch TLB flush: revisit a resident page after running a different PID. Compare TLB
misses with page faults.
9. Protection faults: try negative and out-of-range addresses, then attempt access through a nonactive
process record.
10. Four-byte conceptual heap object: write/read bytes at virtual offsets 14, 15, 16, and 17. Each
byte must be translated individually even though the object spans two pages.
What should you compare? Look at the requested byte values, resident-page flags, fault categories, and
report counters. The expected test XX.txt reference files contain full traces from the instructor solution.
Because the starter’s @student functions are intentionally incomplete, its initial output will not match these
reference traces. The provided tests are a starting point, not a substitute for students’ own boundary and
regression tests.
Your Work
Complete only the functions marked @student in the starter file. The provided code handles machine
initialization, process registration, and ten independent test scenarios selectable from the command line.
Student functions produce the required trace events as their operations occur. Student-function comments
state required behavior and examples without providing a step-by-step implementation.
Part 1: Address Decomposition and Protection (10 points)
address parts() validates a virtual byte address and reports its page number and offset. A negative address
and an address equal to the virtual limit must fail. Example: virtual 31 is page 1, offset 15; virtual 32 is
page 2, offset 0.
Part 2: TLB Operations (15 points)
tlb lookup(), tlb insert(), and tlb invalidate() maintain cached (PID, page) translations. Insertions
may use round-robin replacement of the four TLB slots; this policy is separate from FIFO replacement of
RAM frames. A stale mapping must never produce a successful translation.
Part 3: Page Faults and FIFO Replacement (30 points)
ensure resident() makes the requested virtual page resident. Correctly handle free frames, FIFO eviction,
dirty write-back, backing-store reload, page-table updates, frame ownership, and invalidation of a victim’s
TLB entry. A page fault occurs only when the page is absent, not on every TLB miss.
Part 4: Translation and Memory Access (20 points)
mmu translate() resolves a virtual address using the TLB and page table, invokes demand paging when
necessary, and returns a physical byte index or INVALID. vm read() and vm write() use that result to access
the RAM array. Writes mark pages dirty. A protection fault must not change RAM or backing-store data.
6
Part 5: Context Switching and Statistics (10 points)
switch process() updates the active PID and flushes the TLB only when the PID changes. print report()
displays totals for accesses, TLB hits, TLB misses, page faults, evictions, dirty write-backs, and protection
faults. Counters must reflect actual simulated events.
Part 6: Reasoning and Tests (15 points)
Submit a short analysis.txt (approximately 1–2 pages) that includes: (1) a hand-worked translation from
virtual address to physical address; (2) an explanation of why a TLB miss does not necessarily imply a page
fault; (3) a FIFO eviction example identifying whether write-back is needed; (4) a context-switch example;
and (5) an explanation of how a heap block spanning two pages can still be a valid allocation. Include at
least five labeled test scenarios and explain what each is intended to verify.
Visible Simulation
The driver prints events of the following form. Frame choices shown here are illustrative, not a guaranteed
complete trace:
[CPU] switch -> PID 0; TLB flush
[TLB] PID 0 page 2 MISS
[PAGE] PID 0 page 2 FAULT
[RAM] PID 0 page 2 loaded into frame 0
[MMU] PID 0 READ v=35 -> p=3 value=0
[TLB] PID 0 page 2 HIT
[MMU] PID 0 WRITE v=36 -> p=4 value=65
[CPU] switch -> PID 1; TLB flush
[TLB] PID 1 page 2 MISS
[PAGE] PID 1 page 2 FAULT
[RAM] PID 1 page 2 loaded into frame 1
Additional Testing Guidance
1. First read of an absent page (one page fault), then another read on that page (TLB hit).
2. Addresses 15 and 16: same process, different virtual pages.
3. Same virtual address for two PIDs, with different written values.
4. Fill all eight frames, request a ninth distinct page, and identify the FIFO victim.
5. Evict a dirty page, later reload it, and verify that its written byte survives.
6. Evict a clean page and verify no dirty write-back occurs.
7. Switch PIDs, then revisit an already resident page and distinguish a TLB miss from a page fault.
8. Reject virtual addresses −1 and 128 without changing RAM.
9. Write/read a 4-byte conceptual heap object spanning offsets 14–17 (translate each byte).
10. Compare hit/miss/fault counters before and after repeated access to a resident page.
Points
The 100-point rubric is provided separately in RUBRIC.txt.
7
General Notes
Implement incrementally. A correct address decomposition is necessary before paging can work. Distinguish
protection fault, TLB miss, and page fault in your explanations and traces. The simulator uses byte-level
operations; no host pointers are returned to simulated processes. The supplied scenarios are not the complete
grading suite.
Restrictions
• ANSI C/C90 only. Compile with gcc -std=c90 -pedantic -Wall -Wextra.
• Use only the supplied arrays and structures for RAM, backing store, page tables, frame ownership,
and TLB. Do not use the host’s malloc(), calloc(), realloc(), or free() to implement simulated
paging.
• No real processes, threads, file-backed swap, operating-system memory mapping, or external libraries.
• Do not change required function signatures, constants, or trace labels. Add private helpers if useful.
• Do not access RAM using an unchecked virtual address. Preserve PID isolation and backing-store
contents.
Two-Week Work Plan
Week 1: understand the structs, implement address decomposition, TLB operations, translation, and initial
page loading; test simple reads/writes and boundaries. Week 2: implement FIFO eviction and dirty writeback, context switching, statistics, multi-process tests, and the written analysis. Reserve time for regression
testing. The exact due date and time are those announced in Canvas; the submission window is two weeks.
Sample Build
gcc – std = c90 – pedantic – Wall – Wextra vm_handout . c -o pagiminator
./ pagiminator all
./ pagiminator 3
Submission
Submit vm handout.c and analysis.txt to Canvas/CodeGrade by the posted deadline, two weeks after
release. Do not submit the instructor solution or compiled binaries. All source must compile in the
designated grading environment. The starter intentionally contains placeholder implementations, so its
initial test output is not an expected-answer trace.
Agreement
By submitting, you acknowledge the restrictions and that the submitted work is your own. Ask the instructor
or GA about unclear requirements before the deadline
Solution Overview
The assignment covers implementing address decomposition, TLB lookup and replacement, demand paging, FIFO frame eviction, and dirty page write-backs. It also addresses MMU reads and writes, process context switching, protection faults, performance counters, and written analysis with labeled test scenarios.



