Paging and Virtual Memory

Learn how an operating system divides memory into pages and uses page tables to translate every address a program uses. Follow translations through the TLB, the small hardware cache that makes them fast, and through multi-level page tables that keep the tables small even for 64-bit address spaces. Then see how swapping lets programs use more memory than the machine has: handle page faults, compare page replacement policies such as FIFO, LRU and the clock algorithm on worked reference strings, and recognize thrashing and the remedies for it.

IntermediateLesson 4 of 9 in Operating Systems Course

What you will learn

  1. Divide memory into fixed-size pages and frames, and use a per-process page table to turn every virtual address into a physical address.
    • Split an address space into pages and frames
      Explain why paging replaces variable-sized segments, and split a virtual address into a page number and an offset.
    • Translate an address with a linear page table
      Read page table entries, follow the steps from a virtual to a physical address, and calculate how much memory a page table takes.
  2. Explain how a translation lookaside buffer caches recent translations, predict how often it hits from a program's access pattern, and keep it correct on misses and context switches.
    • Follow a TLB hit and a TLB miss
      Trace the hardware's steps with a translation lookaside buffer and use locality to predict how often lookups hit.
    • Handle TLB misses and context switches
      Compare hardware-managed and software-managed TLBs, keep translations correct across context switches, and calculate TLB reach.
  3. Calculate why linear page tables waste memory, compare the structures that shrink them, and translate addresses through multi-level page tables, weighing memory saved against slower misses.
    • Compare ways to shrink a page table
      Weigh bigger pages, hybrid segmentation and paging, and inverted page tables against the memory cost of a linear table.
    • Translate through a two-level page table
      Split a virtual address into directory index, table index and offset, and walk the page directory and page table to a physical address.
    • Scale page tables to 64-bit addresses
      Work out how many levels a page table needs, and explain how x86-64 four- and five-level tables and large pages work in practice.
  4. Keep pages that do not fit in memory on a disk or SSD, follow a page fault step by step, estimate its cost, and use page faults on purpose for lazy allocation and copy-on-write.
    • Swap pages and handle a page fault
      Explain swap space and the present bit, and follow the hardware and the operating system through a page fault.
    • Estimate the cost of page faults and keep frames free
      Calculate the effective access time with page faults, and explain how the operating system frees frames in advance and writes back modified pages.
    • Use page faults for lazy allocation, copy-on-write and sharing
      Explain how operating systems use the valid, present and protection bits to postpone work and share memory safely.
  5. Simulate and compare replacement policies on reference strings, explain how real systems approximate LRU, and recognize and remedy thrashing.
    • Measure replacement policies against the optimal policy
      Count hits and misses on a reference string, classify misses, and use the optimal policy as a benchmark.
    • Compare FIFO, random and LRU
      Simulate the classic policies on the same reference string, explain Belady's anomaly, and choose a policy for a given access pattern.
    • Approximate LRU with use bits and the clock algorithm
      Run the clock algorithm with use and dirty bits, and explain why real systems approximate LRU instead of implementing it exactly.
    • Recognize thrashing and allocate frames
      Explain thrashing with the working-set model and choose remedies such as admission control, page-fault frequency control and the out-of-memory killer.

Paging and Virtual Memory study guide

5 chapters

1

Translate virtual addresses with paging

Every instruction fetch, load, and store starts with an address in a process’s virtual space. Paging lets the operating system place its contents in separate physical frames while preserving the program’s view of consecutive addresses. You will split addresses, follow a linear page-table lookup, and distinguish the address of a mapping entry from the address of the requested data. The same calculations also reveal paging’s space costs.

1.1 Pages, frames, and address fields

A program uses virtual addresses. Physical memory holds the bytes in frames. Paging divides the virtual address space into equal-sized pages and physical memory into frames of the same size. The operating system can put any page into any free frame. Page 0 might occupy frame 12 and page 1 frame 3; the program still sees consecutive virtual addresses.

This removes external fragmentation for individual page allocations. With variable-sized segments, a request can fail because free space is split into holes that are too small. With paging, a free frame always fits one page. A sparse address space can leave a large gap between heap and stack without reserving physical frames for that gap.

Measure unused space inside pages

Paging still has internal fragmentation. A region must occupy whole pages even when its final page is partly empty. A 9,000-byte region needs three 4 KiB pages: two pages hold 8,192 bytes, leaving 808 bytes for the third. The allocation occupies 12,288 bytes, of which 3,288 bytes are unused. KiB means 1,024 bytes; MiB means 1,048,576 bytes. Some books use KB and MB for these binary quantities.

Split the address into fields

An address identifies both a page and a byte within it. For a page size of 2k bytes, the low k bits are the offset. The remaining high bits are the virtual page number, or VPN. A 32-bit address with 4 KiB pages has 12 offset bits and 20 VPN bits. There are 220 possible virtual pages in that address space.

For 0x00403A7C, the last three hexadecimal digits give offset 0xA7C, because each hex digit represents four bits. The first five digits give VPN 0x00403. This shortcut works here because the field boundary falls between hex digits. For a different page size, count bits before splitting the written hex value.

Decimal arithmetic gives the same result:

VPN=⌊VA/P⌋,offset=VA mod P

Here P is the page size in bytes. With 1,024-byte pages, virtual address 5,000 has VPN 4 and offset 904. Four complete pages account for 4,096 bytes; the remaining 904 bytes locate the address inside page 4. Offsets start at zero, so this page's offsets range from 0 through 1,023.

Translation replaces the VPN with a physical frame number. It copies the offset unchanged: byte 904 of a virtual page is byte 904 of its frame. The page number alone is not a byte address. Multiply a frame number by the page size to find the frame's starting address, then add the offset.

Choose a page size

Larger pages reduce the number of mappings and let each cached translation cover more bytes. They also waste more space in partially used pages and move more data when a page is loaded. A common base page size is 4 KiB; other systems use 16 KiB or 64 KiB. x86-64 also supports large mappings such as 2 MiB pages.

Key Takeaways

  • A virtual page and a physical frame have the same size.
  • Any free frame can hold any page; adjacent virtual pages need not occupy adjacent frames.
  • The low address bits give the offset, which translation preserves.
  • Round allocations up to whole pages when calculating internal fragmentation.
  • Larger pages reduce mapping overhead but increase potential waste.

1.2 Reading a linear page table

A page table records a process's mappings. In a linear page table, the VPN indexes an array: entry 4 describes virtual page 4. Each process has its own table, so the same virtual address can refer to different physical bytes in different processes. On a context switch, the operating system selects the new process's table through a page-table base register.

Read entry state and permissions

A page table entry, or PTE, contains a physical frame number (PFN) and control information. In the teaching model, a valid bit says that the page belongs to the address space; a present bit says that its contents are resident in physical memory. Protection bits control reads, writes, execution, and user access. A dirty bit records writes since it was last cleared. An accessed bit records use since it was last cleared; it is also called the reference or use bit.

These are conceptual roles, not a promise of identical hardware layouts. x86 has no separate valid bit in a PTE. When present is clear, the operating system consults its own records to distinguish an unused address from a valid page stored elsewhere. On x86, hardware sets the accessed and dirty bits; the operating system manages and clears them.

Locate the entry and the byte

To translate an address with a linear table:

  1. Split the virtual address into VPN and offset.
  2. Locate its entry at table base+VPN×PTE size.
  3. Check whether the mapping exists, is present, and permits this access.
  4. Form the physical address from PFN×page size+offset.
  5. Read or write the byte at that physical address.

With 1,024-byte pages, virtual address 5,000 gives VPN 4 and offset 904. Suppose PTE 4 is present and allows the requested read, with PFN 9. Frame 9 starts at 9,216, so the physical byte address is 10,120. The table's own address is a separate calculation: if entries occupy 4 bytes, PTE 4 lies 16 bytes after the table base.

For a hexadecimal example, 4 KiB pages split 0x00403A7C into VPN 0x403 and offset 0xA7C. If the permitted mapping holds PFN 0x1F2B5, the physical address is 0x1F2B5A7C. The PTE lies at base + 0x403 × 4 = base + 0x100C. Appending the offset forms a data address; multiplying the VPN by entry size locates the PTE. These two addresses serve different purposes.

A failed check raises an exception. The operating system may bring in a valid nonresident page, provide zeroed memory, or repair another legitimate mapping. An illegal address or forbidden access usually causes a segmentation fault. A present page can still reject a write if its protection forbids writing.

Count table space and memory reads

Linear tables are expensive even for small processes. With 32-bit virtual addresses and 4 KiB pages, every table needs 1,048,576 entries. At 4 bytes each, that is 4 MiB per process, including entries for unused virtual pages. One hundred processes need 400 MiB just for these tables.

They also add a lookup to each memory reference. In a simple model without a translation cache, the processor reads one PTE and then the requested data: two memory accesses. Sharing is still possible: two processes can deliberately map their separate virtual pages to the same PFN, as for read-only program code.

Key Takeaways

  • A linear table is an array indexed by VPN.
  • PTE location = table base+VPN×entry size.
  • Physical address = PFN×page size+offset.
  • Presence and permission answer different questions.
  • Table size depends on the whole virtual address space, including unused pages.
  • Separate process tables can deliberately share a physical frame.
2

Speed up translation with the TLB

Translating every reference through memory would add a lookup before every useful access. A TLB keeps recent translations close to the processor. Its success depends on access order as well as capacity, and its contents must remain correct when processes switch or mappings change. You will trace hits and misses, estimate average access time, and connect cached translations to the work the operating system performs.

2.1 TLB hits, misses, and locality

A translation lookaside buffer, or TLB, is a small hardware cache of address translations in the memory-management unit (MMU). It holds recent VPN-to-PFN mappings and access information. It caches translations, while a data cache holds program bytes. A program can miss in one cache and hit in the other.

Follow hits and misses

On a TLB hit, the MMU obtains the PFN from the cached entry, checks the access permissions, and combines the PFN with the unchanged offset. It does not need to read the page table. A hit never removes the need to enforce protection. The TLB's valid bit says that a cached entry is usable; it does not say whether a virtual page belongs to the process's address space.

On a TLB miss, the system must look up the translation in the page table. If the page is present and the access is allowed, it installs the translation and completes or retries the reference. No storage read is needed. If the table instead reports a missing mapping or forbidden access, a page fault requires operating-system handling. A TLB miss alone is not a page fault.

Predict reuse from locality

TLBs can hold far fewer entries than the number of virtual pages, yet they work well because programs show locality. Spatial locality means nearby addresses are used close together in time. Once one translation is cached, many addresses within that page can use it. Temporal locality means recently used addresses are likely to be used again, as with the instructions in a loop.

Consider 16,384 four-byte integers stored consecutively in a page-aligned array. With 4 KiB pages, each page holds 1,024 integers, so the array spans 16 pages. Starting with an empty TLB and no interfering translations, the first integer on each page causes a miss. The next 1,023 on that page hit. There are 16 misses and 16,368 hits in all, giving a hit rate of about 99.9%.

Access order changes that result. In C, int a[1024][1024] stores rows consecutively. Assume four-byte integers, page alignment, 4 KiB pages, and a 64-entry LRU TLB. Each row occupies one page. Row-by-row traversal has one miss per row, or 1,024 misses. Column-by-column traversal visits 1,024 different pages before returning to the first. Its translation has already been evicted, so all 1,048,576 array references miss. The array's size is unchanged; the reuse distance changes.

Average hit and miss costs

The timing model must say what a hit and miss cost. Suppose memory takes 100 ns, the TLB lookup adds no time, and a miss in a linear table adds one memory read. A hit costs 100 ns and a successful miss costs 200 ns. At a 98% hit rate:

EAT=0.98(100)+0.02(200)=102 ns

This average includes the final data access in both cases. Counting only the extra PTE read as the entire miss cost would understate the total. With multi-level tables, a miss may need several table reads, so locality matters even more.

Key Takeaways

  • The TLB stores translations and permissions, not program data.
  • A hit still enforces access permissions.
  • A TLB miss can be resolved without a page fault.
  • Nearby accesses share a translation; repeated accesses reuse it.
  • Access order can change TLB miss rates dramatically.

2.2 Keeping cached translations correct

A TLB miss needs a translation lookup, but architectures divide that work differently. With a hardware-managed TLB, as on x86 and ARM, the MMU walks the page table starting at the selected table root. Hardware defines the format it can walk. If the mapping is usable, it fills the translation cache without calling an operating-system handler for the ordinary miss.

A software-managed TLB, used in classic MIPS and SPARC designs, raises an exception on a miss. An operating-system handler finds the mapping and inserts it using privileged instructions. This gives the operating system more freedom over its table structure. Returning from this exception retries the instruction that missed; returning from a system call normally continues after the call.

Keep the refill handler reachable

The miss handler needs reliable access to its own instructions and data. If servicing a miss immediately triggers the same unresolved kind of miss inside the handler, progress can fail. Designs avoid this with untranslated memory or permanently wired translations for the handler's essential code and data.

Select the right address space

Context switches introduce another problem. Process A might map VPN 7 to frame 20 while process B maps VPN 7 to frame 90. Keeping A's untagged entry after switching to B would send B to the wrong frame. Loading B's page-table root does not by itself make an untagged cached mapping safe.

One solution is to flush the relevant TLB entries on a switch. Their valid bits are cleared, forcing the new process to refill them. Another solution tags entries with an address-space identifier (ASID). Lookup then matches both the virtual page and its address-space tag. x86 calls its tag a process-context identifier, or PCID. Entries for several address spaces can remain cached while the hardware selects only those belonging to the current context. Tag reuse still has to be managed so that an old entry cannot be mistaken for a new address space.

Invalidate changed mappings

A PTE change also makes a cached translation stale. Suppose the operating system removes write permission in memory but leaves a writable TLB entry. The processor might continue allowing writes through that old entry. The operating system must invalidate affected translations. On a machine with several cores, every core that could cache the mapping must participate. This coordination is called a TLB shootdown.

Calculate translation coverage

Capacity matters as well as correctness. TLB reach is the amount of memory represented by the cached translations:

reach=entries×page size

A 64-entry TLB reaches 256 KiB with 4 KiB pages and 128 MiB with 2 MiB pages. Reach describes mapping coverage, not the capacity of physical memory. Real processors may have separate TLB capacities for different page sizes, so this calculation compares a fixed entry count.

When a TLB is full, it replaces a translation. LRU favors recently used entries; random replacement chooses without tracking recency. Cycling through one more page than fits defeats LRU because each translation is evicted just before it is needed again.

Key Takeaways

  • Hardware or an operating-system handler can refill a TLB.
  • ASIDs distinguish identical VPNs belonging to different address spaces.
  • Changing a PTE requires invalidating stale cached translations.
  • A TLB shootdown coordinates invalidation across cores.
  • Reach equals entry count times page size.
3

Make page tables smaller

Large virtual address spaces make a full array of page mappings impractical. Page-table structures save space by organizing or omitting mappings in different ways. You will compare those choices, follow a two-level walk, and extend the same bit-field reasoning to x86-64. Each structure balances the memory used for mappings against the work needed when the TLB lacks a translation; large pages change both sides of that balance.

3.1 Alternatives to a full linear table

A linear page table reserves one entry for every possible virtual page. Most processes use only a small part of their address space: code and heap lie near one end, stack near the other, and a large gap separates them. A table with millions of invalid entries still consumes memory. Shrinking this cost means changing page size, table organization, or both.

Reduce the page count

Larger pages reduce the number of VPNs. With a 32-bit address space and 16 KiB pages, 14 bits form the offset and 18 bits form the VPN. A linear table then needs 262,144 entries. At 4 bytes each it occupies 1 MiB, compared with 4 MiB for 4 KiB pages. This saves table space even though the process can still address 4 GiB of virtual bytes.

The cost moves elsewhere. A small allocation can waste more of its last page, and bringing a page into memory transfers more bytes. Increasing page size does not distinguish a densely used part of the address space from an unused gap; it merely gives both fewer entries.

Omit gaps with separate segment tables

A segmentation-and-paging hybrid gives code, heap, and stack their own page tables. Each segment has a table base and a bound on its page numbers. The gap between segments needs no entries. Translation first selects the segment, checks its bound, and then looks up the page within that segment.

This approach depends on a useful division into segments. Its tables can have different lengths and may need contiguous physical space, reintroducing external fragmentation for the tables themselves. The process's data pages remain fixed-size; the fragmented objects are now the variable-sized page tables.

Index physical frames instead

An inverted page table changes what an entry describes. It has one entry per physical frame for the whole machine, recording the occupying process and VPN. With 16 GiB of physical memory and 4 KiB frames, it needs 4,194,304 entries regardless of how many processes have large virtual address spaces. Entry size is still needed to turn that count into a byte total.

An ordinary table uses the VPN as a direct array index. An inverted table instead searches for the pair consisting of address-space identity and VPN. A hash structure can make this efficient, but collisions may require extra probes. Shared frames also need extra handling because one frame may have several virtual names. Hashed page tables, such as those used in PowerPC systems, use related lookup ideas; a hashed table is not necessarily a strict one-entry-per-frame inverted table.

Allocate tables by used region

Multi-level page tables retain indexed lookup while allocating lower-level table pages only where mappings are needed. An upper-level entry can mark an entire unused range without allocating its lower-level table. This is the common solution on modern systems. The saving is greatest for sparse address spaces, while a TLB miss needs more lookup steps.

Choose comparisons by asking what controls size. A linear table scales with virtual pages per process. An inverted table scales with physical frames for the system. A hierarchy scales with the table branches needed for the mappings. None of these counts is the number of bytes of program data currently resident.

Key Takeaways

  • Larger pages reduce PTE count but can increase internal fragmentation.
  • Separate segment tables omit gaps but can require variable-sized table allocations.
  • An inverted table has one entry per physical frame for the system.
  • Inverted lookup needs an address-space identity and VPN.
  • A hierarchy omits lower-level tables for unused address ranges.

3.2 Walking a two-level page table

A two-level page table divides a large linear table into page-sized pieces. A page directory points to those pieces. The directory is allocated, but a lower-level page-table page is allocated only when its region needs mappings. An absent directory entry can represent a whole unused range.

Derive the 10/10/12 split

Take a 32-bit virtual address, 4 KiB pages, and 4-byte entries. Each page-table page holds 1,024 entries, so a 10-bit index selects an entry. The address splits into 10 directory bits, 10 table bits, and 12 offset bits. Each lower-level table maps 1,024 pages, covering 4 MiB of virtual addresses. The directory also has 1,024 entries and occupies one 4 KiB page.

Follow directory and table entries

The walk follows physical pointers:

  1. Add directory index×4 to the directory's physical base. Read that page directory entry (PDE).
  2. If it points to a table page, multiply its PFN by 4,096 to obtain that table's physical base.
  3. Add table index×4 and read the PTE.
  4. Check the leaf mapping and combine its PFN with the offset.

The PDE points to a table, while the PTE points to the requested data page. Confusing these roles sends a reference into page-table memory instead of the program's data.

For virtual address 0x00803ABC, the directory index is 2, the table index is 3, and the offset is 0xABC. Suppose directory entry 2 points to frame 0xA1. Its table starts at 0xA1000. Entry 3 is 12 bytes into that table, at 0xA100C. If the permitted, present PTE contains PFN 0x2F3C4, the data address is 0x2F3C4ABC.

Notice the two different multipliers. A table index counts entries, so multiply it by entry size. A PFN counts frames, so multiply it by page size. The offset counts bytes within the final page and needs neither multiplier. The directory base and pointers used during the walk are physical addresses; using virtual pointers would demand another translation to perform this translation.

Count tables and lookup reads

Space depends on how mappings are distributed. Suppose a process uses the bottom 8 MiB of its 4 GiB space and the top 4 MiB, with both regions aligned to directory boundaries. The low region needs two table pages, and the high region one. Adding the directory gives four pages, or 16 KiB, instead of a 4 MiB linear table. Mapping the same number of data pages sparsely across many directory regions could need more table pages.

In the basic teaching scheme, an invalid PDE means that none of the pages in its 4 MiB region belong to the address space. The walk stops without reading a PTE. Complete operating systems can also use missing entries for lazy allocation, so their software records decide the meaning of a hardware nonpresent entry.

The hierarchy saves space by adding work on a TLB miss. An uncached two-level walk reads a PDE and a PTE before accessing data: three memory reads in all, compared with two for a linear table. A TLB hit bypasses those table reads. This makes a high hit rate especially valuable as the hierarchy gets deeper.

Key Takeaways

  • The 10/10/12 split follows from 4 KiB pages and 4-byte entries.
  • A PDE locates a table page; a PTE locates a data frame.
  • Multiply indices by entry size and PFNs by page size.
  • Count the directory as well as the allocated lower-level table pages.
  • A TLB miss costs extra table reads; a hit bypasses the walk.
  • Sparse mappings save most when they share a small number of table pages.

3.3 Deep tables and large pages on x86-64

The number of table levels follows from three quantities: the implemented virtual address width, the page size, and the entry size. First calculate the offset width. Then calculate how many entries fit in one table page and how many bits select an entry. Finally divide the remaining VPN bits into index fields, rounding the number of levels up if needed.

Derive the four levels

For four-level x86-64 paging, the implemented virtual address width is 48 bits. A 4 KiB page supplies 12 offset bits. An 8-byte entry gives 512 entries per table page, selected by 9 bits. The VPN has 36 bits, so four 9-bit indices are needed. An uncached successful walk follows four entries and then accesses the data.

The levels are PML4, page-directory-pointer table, page directory, and page table. Their indices occupy bits 47–39, 38–30, 29–21, and 20–12. CR3 identifies the physical root. Linux names the corresponding levels PGD, PUD, PMD, and PTE; its generic hierarchy includes a P4D level, which is folded away when the architecture uses only four levels.

Distinguish address width from RAM

A 48-bit implemented address space contains 256 TiB of addressable bytes. Addresses are still held in 64-bit values: in the ordinary canonical form, bits above bit 47 repeat that bit. The valid low and high ranges are separated by a noncanonical gap. Calling this a 48-bit address space does not mean every 64-bit pattern is usable or that a process receives 256 TiB of RAM.

A linear table would be enormous. There are 236 virtual pages; multiplying by 8-byte entries gives 239 bytes, or 512 GiB per process. A hierarchy represents unused ranges with absent branches instead of reserving all those entries.

Processors supporting five-level paging can use 57 implemented virtual address bits when that mode is enabled. One more 9-bit index is added above the PML4, giving 128 PiB of addressable bytes and one more possible table read. The upper bits of a canonical address then repeat bit 56. Processor support and the enabled paging mode determine which width applies.

Stop the walk at a large page

Large pages stop the walk early. On x86-64, an entry at page-directory level can directly map a 2 MiB page, leaving 21 offset bits. A page-directory-pointer entry can map a 1 GiB page, leaving 30 offset bits. Lower bits that would otherwise select lower-level entries now select bytes within that large page.

This reduces both walk length and the number of translations needed for a given region. It increases TLB reach, which can help databases and other large workloads. The physical mapping needs a suitably aligned contiguous run of frames, and a partly used large page can waste much more memory. Linux supports explicit huge-page allocation and transparent huge pages; the supported sizes depend on the architecture.

The simple cost count assumes no cached table entries. Real processors cache paging structures, and table reads can hit in ordinary caches. Four levels therefore do not guarantee four main-memory delays on every TLB miss. They describe the dependency chain and its uncached cost.

Key Takeaways

  • Calculate index width from entries per table page.
  • Four-level x86-64 divides 36 VPN bits into four 9-bit indices.
  • Implemented virtual address width is smaller than the 64-bit address container.
  • A large-page entry ends the walk early and gives more bits to the offset.
  • Walk caches reduce typical cost without changing the hierarchy.
4

Go beyond physical memory with swapping

A process can own more virtual pages than it currently keeps in physical memory. The operating system supplies page contents when an access needs them, sometimes from swap and sometimes without any storage read. You will follow the faulting instruction through the handler and back to execution, estimate the cost of major faults, and see why faults also support useful features such as zero-filled memory and copy-on-write.

4.1 Following a page from swap back to memory

Virtual address spaces can together exceed physical memory because not every page must stay resident. Swap space stores displaced page contents on a disk or SSD. Linux can use a swap partition or swap file; Windows uses a page file. Physical memory holds the currently resident subset of pages.

Paging moves individual pages. A page-out writes a page to backing storage before its frame is reused; a page-in reads it back. Historically, swapping also meant moving an entire process. In modern discussions, the word often refers to page movement, so identify the object being moved.

Interpret the missing mapping

A PTE's present bit tells hardware whether a resident mapping is available. If a valid page has been swapped out, the operating system records where its contents can be found, either in software-defined entry bits or separate metadata. A present bit of zero does not itself identify swap: it can also describe unallocated or lazily allocated memory.

A page fault is an exception caused by an access that cannot complete with the current mapping. It can report absence or a protection violation. The handler decides whether the access is legitimate and how to resolve it. Successful handling can load stored bytes, supply zeroed memory, map an existing resident frame, or make a private copy. A truly invalid access usually results in a segmentation fault.

Restore a saved page

Follow a swapped-page read with 1,024-byte pages:

  1. Virtual address 5,000 gives VPN 4 and offset 904.
  2. The TLB has no usable translation. The page-table walk finds the valid page nonpresent; software records identify swap block 37.
  3. The handler obtains frame 9. If no frame is free, memory reclamation must first make space.
  4. The operating system reads block 37 into frame 9. The faulting process waits; another runnable process can use the CPU.
  5. On completion, the operating system installs PFN 9, sets the mapping present, and makes the process runnable.
  6. The instruction is retried. Translation now reaches physical address 10,120.

The instruction resumes its intended operation after the bytes are available. Advancing past the failed instruction would lose a load or store. The process may observe a delay, but its virtual address has not changed.

Classify the fault and predict demand

A major fault needs a storage read. A minor fault is resolved without that I/O, such as by providing a zero-filled frame or mapping a frame already resident. A large count of minor faults therefore does not imply the same device traffic as the same count of major faults. On Linux, /usr/bin/time -v reports the two counts for a command.

Demand paging waits until a page is touched before supplying it. This lets a program begin without loading all of its contents. Prefetching brings in pages expected to be needed soon. Good predictions avoid later waits; poor predictions consume bandwidth and memory for pages never used.

Keep the events distinct. A TLB miss asks for a translation lookup. A page fault asks the operating system to handle a mapping problem. A segmentation fault is a usual outcome for a forbidden access. A resident, permitted page can cause a TLB miss without either of the other events.

Key Takeaways

  • Nonpresent does not automatically mean stored in swap.
  • A major fault needs a storage read; a minor fault does not.
  • A swapped-page fault blocks the process while the read completes.
  • The handler repairs the mapping and retries the faulting instruction.
  • Demand paging waits for use; prefetching predicts future use.
  • A TLB miss, page fault, and segmentation fault are different events.

4.2 Fault cost, dirty pages, and free frames

A rare storage read can dominate average memory time. Let p be the probability that a reference causes a major fault, M the ordinary access time, and F the total service time for a faulting reference. A simple two-case model gives:

EAT=(1−p)M+pF

Here F includes the storage read, operating-system work, and any required dirty-victim write-back. It is the total fault case, not merely a small PTE lookup penalty.

Calculate the effect of rare faults

Assume an ordinary access takes 100 ns and a major fault takes 8 ms in total. Convert 8 ms to 8,000,000 ns before averaging. With one fault per 1,000 references:

EAT=0.999(100)+0.001(8000000)=8099.9 ns

This is about 81 times the ordinary access time. A fault rate of 0.1% sounds small, but a fault costs as much as many thousands of memory references.

For a slowdown below 10%, require an average below 110 ns. Rearranging gives:

p<110−1008000000−100≈1.25×10−6

That is fewer than roughly one major fault per 800,000 references. The allowed probability depends on the assumed service time. For an illustrative SSD service time of 0.1 ms, the wait is shorter, but it is still 100,000 ns: one thousand 100-ns accesses.

Keep frames ready

The operating system tries to have frames ready before a fault needs one. A background page daemon, such as Linux's kswapd, reclaims memory when free frames fall below a low watermark. In the basic watermark model, it continues toward a high watermark. This avoids making every fault wait for a victim to be selected and prepared.

Preserve changes before reuse

A dirty page contains changes since the dirty state was last cleared. Before its frame is reused, those changes must be preserved if the page remains part of a process's memory. Writing it back can happen in the background. After successful write-back, the resident page can be marked clean; a later write makes it dirty again.

A clean page can be discarded without a new write only when its contents can be recovered or regenerated. Unmodified program code can be read again from the executable. A page with an up-to-date swap copy can be read from swap. A clean anonymous page with no recoverable copy cannot simply be forgotten. The dirty bit alone does not prove that backing storage exists.

If a fault must evict a dirty page synchronously, it can require a victim write followed by the demanded read. Preferring a clean, recoverable victim avoids that write on the fault's critical path. Clustering combines several writes into larger transfers, especially useful on disks.

Key Takeaways

  • Convert all timing values to one unit before averaging.
  • A small major-fault probability can dominate effective access time.
  • A background page daemon keeps a reserve of free frames.
  • Dirty state records writes since the last clearing, not simply since loading.
  • Discarding a clean page safely requires recoverable or regenerable contents.
  • Background write-back can remove a victim write from the fault path.

4.3 Demand zeroing, shared code, and copy-on-write

Page faults are useful control points for postponing work. A mapping can belong to a process before the operating system assigns it a private frame. With demand zeroing, the first access obtains zero-filled memory. This avoids allocating and clearing every reserved page up front. Zeroing also prevents a process from seeing another process's leftover data.

The fault needs no disk read because the required contents are zeros, not saved bytes. It is a minor fault. A system can optimize the implementation, but the visible result remains that newly supplied memory has the required zero contents.

Share read-only code

Separate page tables do not require separate copies of every page. Two PTEs can hold the same PFN, even at different virtual addresses. Processes running the same program can share read-only code. Fifty processes using an editor can refer to one resident copy of each shared code page. Read-only protection stops one process from changing those instructions for everyone.

Create private contents on a write

Copy-on-write (COW) permits initial sharing of pages that may later need private contents. After fork(), parent and child have separate address spaces but can share their ordinary private data frames. The operating system marks their writable private mappings read-only and records that they are COW mappings. Reads succeed without copying.

When either process first writes a shared COW page, the write violates its current protection and causes a page fault. The handler recognizes the legitimate COW case, allocates a private frame, copies the page, installs a writable mapping for the writer, and retries the instruction. The other process retains the original contents. The operating system must also make cached translations agree with the changed mappings.

For a process with 400 MiB of resident private data, suppose its child writes three distinct 4 KiB pages before calling exec(). The data copied because of those writes total 12,288 bytes. Repeated writes to one already-private page do not cause a fresh full-page copy each time. Page-table creation and other process bookkeeping still have costs; COW avoids eagerly copying all 400 MiB of data.

This is especially useful when fork() is soon followed by exec(), which replaces the child's address space. Copying all the old data immediately would perform work the child may never use. Intentionally shared writable mappings have different semantics: COW describes the private mappings that must diverge on a write.

A read-only PTE alone does not establish COW. A write to genuinely read-only program code is an error; a write to a COW-protected data page can be repaired. Software records distinguish the cases, so the same hardware protection exception can produce either a successful retry or a segmentation fault.

Protect kernel mappings

Kernel mappings also use protection. A traditional design maps kernel memory into each process's address space with supervisor-only access, allowing kernel entry without selecting a wholly different mapping. User-mode code cannot access those pages just because they have addresses. Kernel page-table isolation, introduced on affected systems after Meltdown became public in 2018, removes most kernel mappings while user code runs and switches mappings on kernel entry.

Key Takeaways

  • Demand-zero memory needs no storage read and must not expose old data.
  • Different page tables can map the same read-only code frame.
  • COW shares private data until a write requires a private copy.
  • The handler uses software records to distinguish COW from a forbidden write.
  • COW avoids copying data that a child soon discards through exec.
5

Choose page replacement policies and prevent thrashing

When a needed page has no free frame, the operating system must choose what to remove. That choice changes future fault rates, but even a good policy cannot keep every active page resident when demand is too high. You will compare policies on reference strings, use hardware bits to approximate recency, and connect a process’s working set to frame allocation. The final step is recognizing when repeated paging prevents useful progress.

5.1 Counting misses and finding the optimal victim

A replacement policy chooses a resident page to evict when a needed page has no free frame available. Physical memory acts as a cache of page contents. The policy tries to keep pages whose future use will avoid expensive faults. A replacement miss is an abstract residency event; whether it needs I/O depends on where the missing contents come from.

Record hits and misses

Compare policies using the same reference string, the same frame count, and the same initial state. A reference string lists page numbers in access order. For each reference, first ask whether the page is resident. If it is, record a hit. Otherwise record a miss, load the page, and evict a victim only if memory is already full.

First references are misses even while free frames remain. These compulsory misses cannot be avoided by choosing another victim. Later misses caused by insufficient capacity are capacity misses. Page replacement has no placement conflicts: a page can occupy any frame. Conflict misses belong to caches with restricted placement, not this fully flexible frame model.

Choose the farthest future use

The optimal policy, OPT or MIN, chooses the page whose next use is farthest in the future. A page never used again is an ideal victim. This produces the fewest misses for a known reference string, but a running operating system cannot know arbitrary future references. OPT provides a benchmark for practical policies.

Use three initially empty frames and the string 1, 2, 3, 1, 4, 1, 5, 2, 1, 4, 3, 1. The first three references fill memory and miss. The next 1 hits. At reference 5, page 4 arrives: resident pages 1, 2, and 3 are next used at positions 6, 8, and 11. Evict 3, whose next use is farthest away.

After 1 hits, page 5 arrives at position 7. Residents 1, 2, and 4 are next used at positions 9, 8, and 10, so OPT evicts 4. The next 2 and 1 hit. Page 4 misses at position 10; either 2 or 5 can go because neither is used again. Page 3 then misses and removes another page with no future use. The final 1 hits.

Compare totals and workloads

The trace has 7 misses and 5 hits. Counting all 12 references, the hit rate is 5/12, or about 41.7%. There are five distinct pages, hence five compulsory misses. If the reported rate excludes those misses, it becomes 5/7, or about 71.4%. Both rates can describe the same trace, so always identify the denominator.

To avoid losing your place, keep the current reference separate from the future suffix. OPT compares the next use of each resident page after the current position; it does not choose whichever page has the greatest numeric label or was loaded first. If two pages are never used again, either choice preserves optimality.

Workloads affect how much policy matters. When references are equally likely across all pages, past use provides little guidance. With locality, a small hot set receives many references, and preserving it improves hit rate. The gap between a practical policy's miss count and OPT's count measures possible improvement on that workload.

Key Takeaways

  • Count initial fills as misses, even before any eviction.
  • OPT evicts the resident page whose next use is farthest away.
  • OPT is a benchmark because it requires future references.
  • Page replacement has capacity misses but no frame-placement conflict misses.
  • State whether the hit-rate denominator includes compulsory misses.

5.2 FIFO, LRU, and workload effects

FIFO evicts the page loaded earliest among the current residents. A queue tracks arrival order. A hit does not move the page to the back of that queue. This makes FIFO easy to maintain, but it can evict a page that is still used frequently simply because it arrived long ago.

Track last use instead of arrival

LRU, least recently used, tracks the most recent use of every resident page. On a hit, that page becomes the most recently used; on a miss with full memory, the page with the oldest last use leaves. This follows temporal locality: recent use often predicts near-future use. Arrival time and last-use time are different histories.

Random replacement chooses a resident victim randomly without maintaining recency order. Its result varies across runs. It can avoid the deterministic failure pattern of LRU on a cyclic workload, but it can still make unlucky choices. LFU, least frequently used, tracks counts instead of recency. Without aging, it can retain a page that was popular in an earlier program phase but is now unused.

Trace policies on the same string

Compare three empty frames on 1, 2, 3, 1, 4, 1, 5, 2, 1, 4, 3, 1. Pages 1, 2, and 3 first fill memory. The hit on 1 leaves FIFO's order unchanged, so the arriving 4 evicts 1. LRU instead treats 1 as recent and evicts 2. The following reference to 1 therefore misses under FIFO and hits under LRU.

For LRU, the later misses evict 3 for page 5, 4 for page 2, 5 for page 4, and 2 for page 3. It finishes with 8 misses and 4 hits. FIFO makes 10 misses and 2 hits. OPT makes 7 misses on the same string. LRU improves on FIFO here but does not reach the future-aware optimum.

Explain Belady’s anomaly

More frames do not improve every policy on every string. Belady's anomaly is an increase in misses when FIFO receives more frames. For 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5, FIFO has 9 misses with three frames and 10 with four. Extra capacity changes the queue's later victims, so its resident sets are not necessarily nested.

LRU and OPT are stack algorithms: with consistent handling of ties, the resident set for a smaller frame count is contained in the set for a larger count. Increasing capacity therefore cannot turn a smaller-memory hit into a larger-memory miss. LRU gives 10 misses with three frames and 8 with four on the anomaly string.

Recognize poor recency workloads

LRU still has poor workloads. Cycle three times through pages 1, 2, 3, 4 with three frames. Each new page evicts the one that will be needed next, producing 12 misses. OPT needs 6. Random replacement can retain useful pages across a cycle and performs better on average here. A one-time scan can likewise push a useful hot set out of an LRU cache.

A policy comparison must include its workload and frame count. Locality makes recency useful in many programs, which motivates approximations of LRU in real systems. A periodic loop just beyond capacity rewards a different choice; no observed advantage on one short trace establishes a universal ranking.

Key Takeaways

  • FIFO hits do not change arrival order; LRU hits do change recency.
  • LFU counts uses, while LRU records when the last use occurred.
  • Random replacement varies across runs and can still choose poor victims.
  • FIFO can show Belady’s anomaly.
  • LRU and OPT have nested resident sets as capacity increases.
  • A cyclic workload just beyond capacity can defeat LRU.

5.3 Approximating recency with a clock hand

Exact LRU needs work on every memory reference. With timestamps, each reference updates a timestamp and victim selection searches for the oldest. With an ordered list, the victim is available at the tail, but each reference must move its page to the front. Updating this structure in software on every load and store would be too expensive.

Read the use bit

Hardware offers a cheaper signal: the use bit, also called the accessed or reference bit. Hardware sets it when a page is read or written. The operating system clears it to begin another observation interval. A set bit means at least one use since the last clearing; it is not a frequency count and does not reveal the exact last-use order.

Scan for a victim

The clock algorithm places frames in a circle and keeps a hand pointing to the next candidate. On replacement, it examines the candidate's use bit. If the bit is 1, the hand clears it and advances. If the bit is 0, that frame is the victim. The new page enters with its use bit set, and the hand advances past it. A hit sets the referenced page's bit without moving the hand.

Suppose the circle holds A with bit 1, B with bit 0, and C with bit 1, with the hand at A. A fault on D clears A and moves to B. B already has bit 0, so D replaces B with bit 1, and the hand ends at C. If the next reference is a fault on E, the hand clears C, then finds A at 0 and replaces A. If A had been accessed between those faults, its bit would be 1 and it would receive another chance.

If every bit is 1 and no new accesses intervene, one sweep clears them all. The hand then evicts its starting page when it returns. That particular selection resembles FIFO's next arrival-order victim, but clock generally follows use history and hand position; it is not always equivalent to FIFO.

A full clock trace needs an initialization convention. Here, empty frames fill in order with bit 1; the hand remains at frame 0 until the first replacement. Hits set bits. Each replacement advances the hand. Under that convention, three frames on 1, 2, 3, 1, 4, 1, 5, 2, 1, 4, 3, 1 produce 10 misses. A short string can hide the benefit of a recency approximation; clock often tracks locality well over longer runs.

Consider write cost and real variants

Dirty state adds the cost of preserving a victim. An enhanced-clock preference ranks (use, dirty) pairs as (0,0), (0,1), (1,0), then (1,1). This favors a page with neither recent use nor unsaved changes. Implementations differ in how scans clear bits and schedule writes. Background write-back can make a dirty candidate clean before replacement needs it.

Real systems use richer variants. VAX/VMS placed removed pages on clean or dirty lists so a process could reclaim one before its frame was reused. Linux has used active and inactive lists and offers multi-generational LRU, which groups pages by observed recency. These systems use hardware evidence to guide operating-system decisions; the hardware's use bit does not itself choose a victim.

Key Takeaways

  • Exact LRU bookkeeping on every reference is expensive.
  • A use bit records any use since clearing, not a count.
  • Clock clears a 1 and advances; it evicts a page found at 0.
  • Hits set use bits but do not move the clock hand.
  • Clean, unreferenced pages are attractive enhanced-clock victims.
  • State initialization and hand movement when tracing clock.

5.4 Working sets, frame allocation, and thrashing

Thrashing occurs when processes spend most of their time faulting pages into memory and evicting pages that are needed again soon. The storage device stays busy while CPU utilization falls, even though programs still have work to do. A low CPU load alone does not identify thrashing; the combination of heavy paging and poor progress is the clue.

The cause is memory demand beyond the available frames. A process needs a useful collection of pages resident to complete its current phase. If several processes' active collections do not fit together, their faults repeatedly displace useful pages. Starting still more processes can worsen this pressure even though the CPU appears underused.

Estimate current page demand

The working set, written W(t,Δ), estimates a process's current needs. In the reference-window model, it is the set of distinct pages in the last Δ references ending at time t. Count each page once, even if it appears several times in the window. The working-set size is a number of pages, not the number of references.

With window 5 and the string 1, 2, 1, 3, 2, 1, 4, 5, 4, 5, 4, 6, 5, 4, examine the state after reference 6. The last five references are 2, 1, 3, 2, 1, giving {1, 2, 3}, size 3. After reference 8 the window is 3, 2, 1, 4, 5, giving size 5. After reference 11 it is 4, 5, 4, 5, 4, giving size 2. Demand temporarily peaks while old and new phases overlap.

Control active demand and allocation

A short window can omit pages still needed; an overly long one can include pages from a finished phase. Peter Denning's working-set model links these changing needs to allocation. A working-set policy runs processes only when their combined working sets fit. If they do not, it suspends one or more processes and releases their frames. This is admission control.

Page-fault frequency (PFF) control uses measured fault rates. Above an upper threshold, a process needs more frames. Below a lower threshold, some frames can be reassigned. If a process needs frames and none are available, suspending a process may be necessary. Two thresholds reduce continual adjustments around a single cutoff.

With global replacement, a fault can evict another process's page. This adapts flexibly to changing demand but lets one process increase another's faults. With local replacement, victims come only from the faulting process's allocation. This limits interference but cannot rescue a process whose assigned frames are too few without an allocation change.

Choose remedies for memory pressure

Useful remedies reduce demand or increase capacity: run fewer programs, add physical memory, or improve locality, such as traversing arrays in storage order. Faster swap reduces the cost of each major fault; it does not make an oversized active set fit. Replacing a disk with an SSD may improve progress without removing the cause.

Under extreme pressure, Linux's out-of-memory killer can terminate a selected process when reclaim and swapping cannot free enough memory. Selection uses memory-related badness scoring and policy adjustments, not simply the identity of the largest process. Memory becomes reclaimable as the process exits, and its work is lost. This is a last-resort release of resources, distinct from suspending a process so it can resume later.

Key Takeaways

  • Thrashing combines heavy paging with little useful progress.
  • A working set counts distinct pages in a recent window.
  • Admission control limits active processes to memory that can support them.
  • PFF adjusts frame allocation using upper and lower fault-rate thresholds.
  • Global replacement allows cross-process eviction; local replacement isolates victim selection.
  • Faster swap reduces delay but does not increase frame capacity.
  • An OOM kill loses a process’s work; suspension can preserve it.

Paging and Virtual Memory examples

5 Walkthroughs

1

Translate a virtual address step by step

11 steps
Split an address, locate its PTE, enforce the mapping, and calculate the final physical byte address.
  1. 1
    IntroductionFrom an address to a byte

    A load instruction names a virtual byte address. The bytes themselves live in physical frames, and the current process’s page table connects the two. Follow one address through the split, the entry lookup, and the final access.

    Keep two questions separate: where is the entry describing this page, and where is the byte that the instruction wants? Both are addresses, but they point to different objects.

  2. 2
    ExplanationPages can move without changing program addresses

    A page is a fixed-size piece of virtual memory; a frame is an equal-sized piece of physical memory. Page 0 might occupy frame 15 while page 1 occupies frame 2.

    The program still sees consecutive virtual addresses across those pages. Any free frame fits any page, so the operating system does not need one long physical hole for an entire process.

  3. 3
    ExampleSeparate the page from its offset

    Use 2 KiB pages and virtual address 11,600. Each page contains 2,048 bytes. Five complete pages account for 10,240 bytes, so this address belongs to VPN 5.

    The remaining 1,360 bytes give its offset. In binary, the low 11 bits hold that offset because a page has 211 byte positions. The higher bits identify the virtual page.

  4. 4
    ExampleMeasure unused allocation space

    A region needs 10,700 bytes and uses 2 KiB pages. Five pages hold only 10,240 bytes, so it needs six pages. Their total capacity is 12,288 bytes.

    Subtract the useful region size to find 1,588 unused bytes inside the allocation. This is internal fragmentation. Free frames elsewhere are not part of that waste; the unused bytes sit inside an allocated page.

  5. 5
    ChallengeTry another address split

    With 8 KiB pages, a process references virtual address 25,100. What VPN and offset identify this byte?

    ---reveal---

    Three pages account for 24,576 bytes, leaving offset 524. The VPN is 3 and the offset is 524. The offset must be smaller than 8,192; that bound helps catch a quotient or subtraction error before you translate the page.

  6. 6
    ExplanationFind the entry before the data

    In a linear page table, the VPN indexes a per-process array. If its base is physical address 20,000 and entries have 8 bytes, PTE 5 begins at 20,040.

    Multiplying by entry size locates mapping information. It does not locate the requested program byte. The entry must supply a physical frame number and permit the requested operation before the processor can form the data address.

  7. 7
    Key InsightCheck the mapping’s state

    A page can belong to a process while being nonresident. It can also be resident while forbidding a particular operation. Presence and permission answer different questions.

    The teaching model gives valid, present, and protection separate roles. x86 does not provide a separate valid bit; when a hardware mapping is nonpresent, operating-system records distinguish swap, lazy allocation, and an unused address.

  8. 8
    ExampleFinish the translation

    Return to virtual address 11,600 with 2 KiB pages: VPN 5, offset 1,360. Suppose PTE 5 allows the read, is present, and names frame 14.

    Frame 14 begins at byte 28,672. Adding the unchanged offset gives physical byte address 30,032. The PTE at 20,040 tells us this result; it is not itself the address from which the program reads its data.

  9. 9
    ChallengeChoose the correct final address

    With 1 KiB pages, virtual address 3,250 maps through a present, permitted PTE to frame 11. What physical address results? Explain which part stays unchanged.

    ---reveal---

    The address has VPN 3 and offset 178. Frame 11 starts at 11,264, so the result is 11,442. The offset stays 178 because a page and its frame have the same internal byte positions.

  10. 10
    ChallengeConnect the split to table size

    A system has 24-bit virtual addresses, 4 KiB pages, and 8-byte linear-table entries. How much memory does the full table occupy?

    ---reveal---

    The offset uses 12 bits, leaving 12 VPN bits and 4,096 entries. Multiplying by eight gives 32,768 bytes, or 32 KiB. The table still contains entries for unused pages; allocating few data frames does not shrink this full linear array.

  11. 11
    RecapRead the two address calculations

    Use the VPN to locate a mapping entry, check its state, and use its PFN to locate a frame. Then carry the original offset into that frame.

    Entry size controls movement through the table; page size controls movement through physical frames. Keeping those units visible makes the same method work with decimal addresses, hexadecimal addresses, and different page sizes.

2

Use the TLB without losing correctness

12 steps
Trace hits, misses, locality, context tags, invalidation, and TLB reach.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionWhy repeated translation can be fast
  2. 2
    ExplanationA hit saves a table lookup
  3. 3
    Key InsightA miss can end entirely in memory
  4. 4
    ExampleCount a sequential array’s misses
  5. 5
    ExampleBuild an average from complete cases
  6. 6
    ChallengeApply locality to a second pass
  7. 7
    ExplanationChoose who performs the refill
  8. 8
    ExampleTag translations by address space
  9. 9
    ConnectionA table edit needs cache invalidation
  10. 10
    ChallengeCalculate translation coverage
  11. 11
    ChallengeSeparate a capacity problem from a correctness problem
  12. 12
    RecapFollow both performance and correctness
3

Walk smaller page tables

14 steps
Compare table organizations, follow a two-level example, and derive deeper tables and large-page mappings.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionSpend less memory on mappings
  2. 2
    ExplanationAsk what one entry describes
  3. 3
    ConnectionCompare two ways of omitting waste
  4. 4
    ChallengeCheck an inverted-table count
  5. 5
    ExplanationDivide the VPN into two indices
  6. 6
    ExampleRead the directory entry
  7. 7
    ExampleFollow the physical pointer to the leaf
  8. 8
    ChallengeCount allocated tables for sparse mappings
  9. 9
    ExplanationDerive a deeper hierarchy
  10. 10
    Key InsightKeep the implemented width in view
  11. 11
    ExampleLet a directory entry map the data
  12. 12
    ChallengeWork out another level count
  13. 13
    ChallengeJudge a large-page proposal
  14. 14
    RecapCount space and lookup work separately
4

Handle faults and postpone unnecessary work

14 steps
Restore a swapped page, estimate its cost, and apply demand zeroing and copy-on-write.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionWait for contents, then retry
  2. 2
    ExplanationInterpret a nonpresent mapping
  3. 3
    ExampleLocate the saved page
  4. 4
    ExampleInstall the mapping and resume
  5. 5
    ChallengeDistinguish two kinds of fault
  6. 6
    ExampleConvert the cost before averaging
  7. 7
    ExplanationPrepare victims before faults need them
  8. 8
    Key InsightCheck whether a clean page is recoverable
  9. 9
    ChallengeAdd the victim write to the critical path
  10. 10
    ExplanationSupply zeros only when needed
  11. 11
    ExplanationShare private pages until a write
  12. 12
    ChallengeCount copied pages, not write instructions
  13. 13
    ChallengeInfer the cause from the fault behavior
  14. 14
    RecapUse faults to supply the right contents
5

Compare victims and prevent thrashing

20 steps
Trace policies, run the clock hand, estimate working sets, and choose remedies for excessive paging.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionKeep useful pages resident
  2. 2
    TipFix the simulation conditions
  3. 3
    ExampleChoose a future-aware victim
  4. 4
    ExampleFinish the benchmark trace
  5. 5
    ChallengeFind the unavoidable part
  6. 6
    ExplanationUse arrival order for FIFO
  7. 7
    ExampleUse last access for LRU
  8. 8
    Key InsightAvoid assuming recency always predicts reuse
  9. 9
    ChallengeInterpret an extra-frame result
  10. 10
    ExplanationReplace exact order with a use signal
  11. 11
    ExampleMake one clock decision
  12. 12
    ChallengeGive a recently touched page another chance
  13. 13
    ConnectionAccount for dirty victims
  14. 14
    ExplanationRecognize memory pressure that blocks progress
  15. 15
    ExampleCount a working set at a phase change
  16. 16
    ExplanationAllocate by demand or by fault symptoms
  17. 17
    ChallengeDistinguish isolation from capacity
  18. 18
    ConnectionChoose a remedy that changes the cause
  19. 19
    ChallengeConnect working sets to replacement
  20. 20
    RecapConnect traces to the running system

Paging and Virtual Memory practice questions

50 Practice Questions in 5 sets

Set 1: Practice 1: Build the paging model10 Practice Questions

Question 1 of 10

With 2,048-byte pages, virtual address 7,300 has a permitted, present mapping to frame 6. What physical byte address does the access reach?
  1. 7,300
  2. 14,336
  3. 13,290
  4. 13,444
Show answerHide answer
Answer: D
The virtual page is 3 and the offset is 1,156, since three pages account for 6,144 bytes. Frame 6 starts at 12,288, giving physical address 13,444. Using the original virtual page number would leave the address unchanged and ignore the mapping to frame 6.

Question 2 of 10

How many offset bits does an 8 KiB page require?
  1. 10 bits
  2. 13 bits
  3. 12 bits
  4. 16 bits
Show answerHide answer
Answer: B
An 8 KiB page contains 8,192 byte positions, so its offsets run from 0 through 8,191 and require 13 bits. Twelve bits select only 4,096 positions, which is enough for a 4 KiB page. The address width determines the remaining VPN bits, not the offset width for this page size.

Question 3 of 10

What must still be checked when a write finds its translation in the TLB?
  1. Whether the cached permissions allow writing
  2. Whether the page has a second free frame
  3. Whether the data is also stored in the TLB
  4. Whether the page table has a new linear index
Show answerHide answer
Answer: A
A TLB entry carries access permissions as well as the frame number, so a hit must still allow the requested write. Finding a translation does not grant unrestricted access. The TLB holds mapping information; the program data can be elsewhere in the memory hierarchy.

Question 4 of 10

A 128-entry TLB maps 4 KiB pages. What is its reach?
  1. 32 KiB
  2. 128 KiB
  3. 512 KiB
  4. 4 MiB
Show answerHide answer
Answer: C
Each entry covers one 4 KiB page, so 128 entries represent 512 KiB of memory. The entry count alone is not a byte capacity. A reach of 4 MiB would require eight times as much translation coverage at this page size; it cannot be inferred from the amount of installed RAM.

Question 5 of 10

A full 30-bit virtual address space uses 4 KiB pages and 8-byte linear-table entries. How much memory does one table occupy?
  1. 256 KiB
  2. 1 MiB
  3. 8 MiB
  4. 2 MiB
Show answerHide answer
Answer: D
Removing 12 offset bits leaves 18 VPN bits, giving 262,144 entries. Eight bytes per entry makes 2,097,152 bytes, or 2 MiB. The 256 KiB result counts entries as if each occupied one byte; table storage must include the actual entry size.

Question 6 of 10

A two-level system uses 4 KiB pages and 4-byte entries in both levels. One process maps pages in exactly five directory regions. How much memory holds its directory and lower-level tables?
  1. 20 KiB
  2. 40 KiB
  3. 24 KiB
  4. 4 MiB
Show answerHide answer
Answer: C
Each occupied directory region needs one 4 KiB lower-level table, and the process also needs its 4 KiB directory. Six table pages total 24 KiB. Counting only the five lower-level tables gives 20 KiB and omits the root that makes those tables reachable.

Question 7 of 10

A valid page is supplied with a zero-filled frame on first access, without any storage read. What kind of page fault occurred?
  1. A minor page fault
  2. A major page fault
  3. A TLB hit
  4. A segmentation fault
Show answerHide answer
Answer: A
The operating system repaired the mapping without reading page contents from storage, so this is a minor fault. A major fault requires a storage read. Supplying zero-filled memory is a legitimate resolution of a page fault; the exception does not by itself mean the process made an invalid access.

Question 8 of 10

Ordinary access takes 80 ns; total major-fault service takes 2 ms. If one reference in 10,000 causes a major fault, what is the effective access time in the two-case model?
  1. 80.02 ns
  2. 279.992 ns
  3. 199.992 ns
  4. 2,079.992 ns
Show answerHide answer
Answer: B
Convert 2 ms to 2,000,000 ns and use fault probability 0.0001. The average is 0.9999×80+0.0001×2000000=279.992 ns. The 199.992-ns value leaves out the ordinary-reference contribution, while using milliseconds as if they were nanoseconds understates the fault cost.

Question 9 of 10

With two initially empty frames, OPT processes 2, 7, 2, 9, 7, 2. How many misses occur, including first uses?
  1. 3 misses
  2. 5 misses
  3. 4 misses
  4. 6 misses
Show answerHide answer
Answer: C
The first 2 and 7 miss, then 2 hits. At 9, OPT evicts 2 because 7 is needed sooner; 7 hits and the final 2 misses, giving four misses. Three is only the number of distinct pages and omits the later capacity miss when page 2 returns.

Question 10 of 10

With three initially empty frames, OPT processes 6, 1, 4, 6, 8, 1, 9, 6, 4. What are its total misses and its hit rate after excluding compulsory misses?
  1. 6 misses; 75% hits
  2. 5 misses; 100% hits
  3. 6 misses; 33.3% hits
  4. 7 misses; 50% hits
Show answerHide answer
Answer: A
The five distinct pages cause five compulsory misses; OPT also misses when 4 returns at the end, for six misses total. The hits are the fourth, sixth, and eighth references. Excluding five compulsory references leaves four references and three hits, so 75% is correct; 33.3% uses all nine references instead.
Set 2: Practice 2: Follow lookups and faults10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A hypothetical machine uses 39-bit virtual addresses, 4 KiB pages, and 8-byte entries in page-sized tables. How many levels are needed?
  1. 3 levels
  2. 2 levels
  3. 4 levels
  4. 5 levels
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

A table page has 4,096 bytes and each entry has 8 bytes. How many bits select one entry?
  1. 8 bits
  2. 9 bits
  3. 10 bits
  4. 12 bits
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A 17,500-byte region uses 8 KiB pages. How many bytes are unused in its allocated pages?
  1. 1,116 bytes
  2. 8,192 bytes
  3. 7,076 bytes
  4. 15,268 bytes
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

In a linear table with 8-byte entries, where is PTE 11 relative to the table base?
  1. 88 bytes after the base
  2. 11 bytes after the base
  3. 19 bytes after the base
  4. 80 bytes after the base
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A page-aligned array contains 6,144 four-byte values. It is read once in order with 8 KiB pages, an empty TLB, and no interfering references. How many TLB misses occur?
  1. 6 misses
  2. 12 misses
  3. 6,144 misses
  4. 3 misses
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A swapped-page read completes and the handler installs a present mapping. What should happen to the instruction that faulted?
  1. It is skipped so execution can continue
  2. It is retried using the repaired mapping
  3. It is replaced by a new system call
  4. It is completed with the swap-block number
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

After fork, a child writes to five distinct shared COW pages of 4 KiB each, then writes to the first of those pages again. How much page data is copied for these writes?
  1. 4 KiB
  2. 24 KiB
  3. 20 KiB
  4. 40 KiB
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

With three initially empty frames, process 4, 8, 2, 4, 6, 8, 4 under FIFO and LRU. What are their total miss counts?
  1. FIFO: 6; LRU: 5
  2. FIFO: 5; LRU: 6
  3. FIFO: 6; LRU: 6
  4. FIFO: 5; LRU: 5
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

Clock has frames A(1), B(1), C(0), D(1), with the hand at B. A fault loads E. What is the replacement result, including the new hand position?
  1. B leaves; E has bit 1; hand points to C
  2. C leaves; E has bit 1; hand points to D
  3. C leaves; E has bit 0; hand points to D
  4. D leaves; E has bit 1; hand points to A
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

Three processes have working-set sizes 7, 5, and 4 pages. Only 12 frames are available. If admission control suspends exactly one whole process and minimizes the number of working-set pages removed, what should it suspend and how many needed frames remain spare?
  1. Suspend the 5-page process; 1 frame spare
  2. Suspend the 7-page process; 3 frames spare
  3. Suspend no process; 4 frames spare
  4. Suspend the 4-page process; 0 frames spare
Show answerHide answer

Save this lesson to see this answer.

Set 3: Practice 3: Combine the mechanisms10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A 28-bit virtual address space has 16 KiB pages and 8-byte entries in a full linear table. What is the table size?
  1. 64 KiB
  2. 128 KiB
  3. 256 KiB
  4. 2 MiB
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

The operating system removes write permission from a mapping that two cores may have cached. What cached state must it update?
  1. Invalidate only the data bytes on both cores
  2. Invalidate the translation only on the writing core
  3. Invalidate the stale translation on both cores
  4. Replace the address-space identifiers of all processes
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

An inverted table covers 8 GiB of physical memory using 8 KiB frames. How many entries does it need?
  1. 1,048,576 entries
  2. 262,144 entries
  3. 2,097,152 entries
  4. 8,388,608 entries
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A 32-bit two-level system uses 4 KiB pages and 4-byte entries. The directory starts at physical 0x3000. A permitted access uses virtual 0x01407120; its PDE contains PFN 0x52 and its PTE contains PFN 0x9C. What are the PDE address, PTE address, and final data address?
  1. 0x3005, 0x52007, 0x9C120
  2. 0x3014, 0x5201C, 0x52120
  3. 0x301C, 0x52014, 0x9C120
  4. 0x3014, 0x5201C, 0x9C120
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A major fault needs a 0.15-ms page read. If its selected victim is dirty, a required synchronous write takes 0.20 ms first. Ignoring all other overhead, how much slower is this fault than one using a clean victim with recoverable contents?
  1. 0.20 ms slower
  2. 0.05 ms slower
  3. 0.15 ms slower
  4. 0.35 ms slower
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

Why must a newly supplied demand-zero page contain zeros before the process reads it?
  1. To make the page’s virtual address equal its frame number
  2. To ensure the page has a saved copy in swap already
  3. To prevent the processor from ever setting its dirty bit
  4. To prevent exposure of another process’s leftover data
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A 20-reference trace starts empty, touches eight distinct pages, and records 13 misses. What hit rate does it have after excluding compulsory misses?
  1. 7/20, or 35%
  2. 12/20, or 60%
  3. 7/12, about 58.3%
  4. 7/13, about 53.8%
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A two-frame LRU simulation starts empty on 9, 3, 9, 7, 3, 9, 7. What is the miss count, and can a three-frame LRU simulation have more misses on this same string?
  1. 5 misses; more frames cannot add misses
  2. 6 misses; more frames cannot add misses
  3. 6 misses; more frames can add misses
  4. 7 misses; more frames can add misses
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

Clock starts full with A(1), B(0), C(1), hand at A. References are D, A, E, with D and E absent initially; hits set bits and replacements set the new bit and advance the hand. What are the final frame contents in the original frame order and the hand position?
  1. E, D, C; hand at B
  2. A, E, D; hand at B
  3. E, D, C; hand at C
  4. A, D, E; hand at A
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

After reference 9 in 2, 6, 2, 8, 6, 9, 9, 6, 4, what is the working set for a five-reference window?
  1. {4, 6, 9}
  2. {2, 4, 6, 8, 9}
  3. {4, 6, 8, 9}
  4. {4, 9}
Show answerHide answer

Save this lesson to see this answer.

Set 4: Practice 4: Analyze costs and access patterns10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A 34-bit virtual address uses 8 KiB pages. How many VPN bits and virtual pages does the address space have?
  1. 13 VPN bits; 213 pages
  2. 22 VPN bits; 222 pages
  3. 21 VPN bits; 234 pages
  4. 21 VPN bits; 221 pages
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

A page-aligned C array has 128 rows and 1,024 four-byte integers per row. A 64-entry LRU TLB starts empty; pages are 4 KiB, and only array references count. How many TLB misses occur in a row traversal and in a column traversal?
  1. Row: 128; column: 131,072
  2. Row: 128; column: 128
  3. Row: 1,024; column: 131,072
  4. Row: 131,072; column: 128
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

Processes A and B both use VPN 12, mapped to different frames. Their TLB entries carry distinct ASIDs. Why can both entries remain cached across a switch?
  1. Lookup matches the PFN and the cached permissions
  2. Lookup matches the current ASID together with the VPN
  3. Lookup matches only the VPN after updating the table root
  4. Lookup matches only the current ASID across all its pages
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A 32-bit two-level system has 4 KiB pages and 4-byte entries. Process A maps 1,024 consecutive pages starting at virtual zero. Process B maps 1,024 pages, one in each directory region. How much table memory does each need, including its directory?
  1. A: 4 KiB; B: 4 MiB
  2. A: 8 KiB; B: 8 KiB
  3. A: 8 KiB; B: 4 MiB + 4 KiB
  4. A: 4 MiB; B: 4 MiB + 4 KiB
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

In four-level x86-64 paging, replace a fully populated, aligned 2 MiB region of 4 KiB mappings with one 2 MiB mapping. Assume upper tables are still needed for other mappings. How many leaf-table pages and walk reads per TLB miss are removed for that region?
  1. 512 table pages; one walk read
  2. One table page; two walk reads
  3. One table page; one walk read
  4. 512 table pages; two walk reads
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A reference misses in the TLB, but its PTE is present and permits the access. Does obtaining this translation require a major page fault?
  1. Yes; every TLB refill reads the page from swap
  2. No; the translation can be filled without a storage read
  3. Yes; the present bit is cleared by the TLB miss
  4. No; the access completes without any permission check
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

Ordinary references take 120 ns and major-faulting references take 3 ms total. What maximum major-fault probability keeps the average at or below 150 ns in the two-case model?
  1. 150/3000000=5.0×10−5
  2. 30/3000120≈1.0×10−5
  3. 120/3000000=4.0×10−5
  4. 30/2999880≈1.0×10−5
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

Compare three initially empty frames on 5, 2, 8, 5, 1, 2, 5, 8 under LRU and OPT. How many misses does each make?
  1. LRU: 6; OPT: 5
  2. LRU: 7; OPT: 5
  3. LRU: 6; OPT: 6
  4. LRU: 7; OPT: 6
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

An enhanced-clock scan compares X with (use, dirty) = (0,1) and Y with (1,0). Under the standard class preference, which page is preferred and what preservation cost can it require?
  1. Y; preserving it can require a write
  2. X; its zero use bit removes any write need
  3. X; preserving it can require a write
  4. Y; its zero dirty bit proves it was unused
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

Two processes each need six pages to make progress, but together receive eight frames. A proposed fix changes global replacement to local replacement and gives each four frames. Why can this leave thrashing unresolved?
  1. Each allocation still falls below its process’s working set
  2. Local replacement makes each allocation permanently fixed
  3. Eight frames suffice when each page has a separate owner
  4. Both processes still choose victims from one global pool
Show answerHide answer

Save this lesson to see this answer.

Set 5: Practice 5: Transfer and diagnose10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

With 8 KiB pages, virtual 0x00012345 has a permitted present mapping to PFN 0x2D. What physical address results?
  1. 0x0005A345
  2. 0x0002D345
  3. 0x0005B345
  4. 0x00012345
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

Two designs have zero added TLB lookup time and no page faults or walk caches. Memory takes 90 ns. Design L has a linear table and 95% TLB hits; design H has a four-level table and 99% hits. What are their average reference times?
  1. L: 94.5 ns; H: 90.9 ns
  2. L: 85.5 ns; H: 89.1 ns
  3. L: 94.5 ns; H: 93.6 ns
  4. L: 99 ns; H: 97.2 ns
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

With a fixed virtual address width, a linear table changes from 4 KiB pages and 8-byte entries to 16 KiB pages and 16-byte entries. How does its total byte size change?
  1. It becomes one quarter as large
  2. It becomes half as large
  3. It stays the same size
  4. It becomes twice as large
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A hypothetical system uses 46 implemented virtual address bits, 8 KiB pages, and 8-byte entries in page-sized tables. Lower indices are filled to capacity. How many levels are needed and how many index bits remain for the root?
  1. Three levels; 10 root-index bits
  2. Four levels; 6 root-index bits
  3. Five levels; 3 root-index bits
  4. Four levels; 3 root-index bits
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A dirty page is successfully written back while remaining resident. No process writes it afterward. What is its state, and can another reference use it without a page-in?
  1. Dirty and resident; yes
  2. Clean and resident; yes
  3. Clean and nonresident; no
  4. Dirty and nonresident; no
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

Processes A, B, and C initially share two 4 KiB private-data pages through COW. A writes both pages, B then writes the first, and C then writes the second. A handler reuses an original frame only once it has a sole owner. How much additional physical page memory do these writes require?
  1. 16 KiB
  2. 12 KiB
  3. 20 KiB
  4. 24 KiB
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A reference trace uses seven distinct pages and starts with empty memory. How many compulsory misses must it contain?
  1. 0 compulsory misses
  2. 6 compulsory misses
  3. 7 compulsory misses
  4. 14 compulsory misses
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

Two initially empty FIFO simulations process 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5, 1, with three and four frames. What are the miss counts, and does the larger allocation show Belady’s anomaly on this full string?
  1. Three: 9; four: 10; yes
  2. Three: 10; four: 10; no
  3. Three: 11; four: 10; no
  4. Three: 10; four: 11; yes
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

Clock has frames R(1), S(1), T(1), with the hand at S. No hits occur while it scans for a victim. What page is evicted, and where does the hand end after the replacement?
  1. R is evicted; hand ends at S
  2. S is evicted; hand ends at T
  3. T is evicted; hand ends at R
  4. S is evicted; hand ends at S
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

At one instant, processes A and B have reference windows 7, 4, 7, 9, 4, 7 and 2, 8, 2, 5, 8, 2. The window size is six and their page sets are disjoint. They have five frames total. What does a working-set admission policy infer?
  1. Demand is twelve frames; shorten both windows automatically
  2. Demand is five frames; both working sets already fit
  3. Demand is six frames; reduce the active process set
  4. Demand is three frames; both processes can share all frames
Show answerHide answer

Save this lesson to see this answer.

Stuck on your own question? Homework Help

Key Terms

79 Key Terms, each with its definition

A

Address-space identifier
An address-space identifier tags cached translations with their address-space context so identical VPNs from different processes remain distinct.
Different ASIDs let two translations for virtual page 7 coexist safely in the same TLB.
Admission control
Admission control limits the active process set so available frames can support its memory demand, suspending processes when necessary.
If active working sets exceed capacity, suspending one process can let the remaining processes progress.

B

Belady’s anomaly
Belady’s anomaly is a rise in page misses when a policy receives more frames on the same reference string and initial conditions.
FIFO can exhibit the anomaly; extra capacity changes its later arrival-order victim choices.

C

Canonical address
A canonical address is an x86-64 address whose unused upper bits repeat the highest implemented virtual-address bit.
In ordinary four-level mode, bits above bit 47 must repeat it for the address to be canonical.
Capacity miss
A capacity miss occurs when limited frame capacity prevents retaining a page until a later reference needs it again.
A returning page can miss even though it was loaded earlier because another page reused its frame.
Clean page
A clean page has no changes pending under its dirty-state tracking; discarding it safely still requires recoverable or regenerable contents.
Unmodified code can be dropped and later reloaded from its executable without a fresh write.
Clock hand
A clock hand marks the next frame to examine during clock replacement and advances as candidates are cleared or replaced.
After the clock replaces the page in one frame, the clock hand advances to the next frame in the ring.
Clock replacement
Clock replacement scans a ring of frames, clearing set use bits and evicting the first candidate it encounters with a clear bit.
A page with use bit 1 gets another chance when the hand clears its bit and moves onward.
Clustering
Clustering groups page transfers into larger storage operations, reducing the overhead of many separate small transfers, especially on disks.
A page daemon can combine several dirty-page writes while preparing frames for later reuse.
Compulsory miss
A compulsory miss is a first-use miss on a page that has not yet been loaded, unavoidable by changing the victim selection policy.
A trace starting empty and touching five distinct pages has five compulsory misses.
Copy-on-write
Copy-on-write shares private page contents initially and creates a private writable copy when a process first writes a shared page.
A child that changes only three 4 KiB pages can avoid copying the parent’s entire data region.

D

Demand paging
Demand paging supplies a page when a reference first requires it, avoiding the need to prepare every page before execution begins.
A program can begin running while pages it has not yet touched remain without resident contents.
Demand zeroing
Demand zeroing supplies zero-filled memory at first use instead of allocating and clearing every reserved page in advance.
A newly touched heap page can be supplied without a disk read while hiding a recycled frame’s old bytes.
Directory index
A directory index is the high VPN field that selects an entry in the page directory during a hierarchical address translation.
The top ten bits select directory entry 2 for virtual address 0x00803ABC in the 10/10/12 scheme.
Dirty bit
A dirty bit records whether a page has been written since its dirty state was last cleared, helping identify unsaved changes.
After write-back completes, the operating system can clear dirty state while the page remains resident.

E

Effective access time
Effective access time is the probability-weighted average time for memory references under a specified hit, miss, or fault cost model.
A 98% TLB hit rate gives 102 ns when hits take 100 ns and successful misses take 200 ns.
Enhanced clock
Enhanced clock incorporates dirty state into second-chance victim selection so access history and the cost of preserving contents both matter.
A page whose use and dirty bits are both 0, the preferred (0,0) class, has no recent recorded use and no changes awaiting write-back.

F

FIFO replacement
FIFO replacement evicts the resident page loaded earliest, maintaining arrival order without refreshing that order on hits.
A frequently used page can still be FIFO’s victim if it arrived before all other resident pages.
Five-level paging
Five-level paging adds an upper table level on supporting x86-64 processors, enabling 57 implemented virtual-address bits when selected.
Enabling the extra level adds another nine-bit index before the four familiar lower indices.
Frame
A frame is a fixed-size block of physical memory that can hold one virtual page of the corresponding page size.
The operating system can use any free 4 KiB frame to hold a newly needed 4 KiB page.

G

Global replacement
Global replacement permits a faulting process to evict a page belonging to another process, sharing the frame pool flexibly.
A growing process can increase another process’s fault rate by taking frames that held its pages.

H

Hardware-managed TLB
A hardware-managed TLB is refilled by processor hardware walking a hardware-defined page-table format when a translation is missing.
An ordinary x86 TLB miss can be handled without entering an operating-system refill handler.
Hashed page table
A hashed page table locates mapping records through a hash of virtual-page identity, with extra handling when keys collide.
A hash lookup can find a process-and-VPN mapping without scanning every entry in an inverted structure.

I

Internal fragmentation
Internal fragmentation is allocated space left unused inside a fixed-size block, such as the partly filled final page of a region.
A 9,000-byte region in three 4 KiB pages leaves 3,288 allocated bytes unused.
Inverted page table
An inverted page table has one entry per physical frame for the system, recording the address-space identity and virtual page occupying it.
With 16 GiB of RAM and 4 KiB frames, a strict inverted table has 4,194,304 frame entries.

K

Kernel page-table isolation
Kernel page-table isolation separates most kernel mappings from those used during user execution, switching mapping context on kernel entry.
On affected systems, isolation reduces exposure from Meltdown at the cost of extra mapping-switch work.

L

Large page
A large page is a mapping larger than the base page size that can end a hierarchical walk at a higher-level entry.
An x86-64 directory entry can map a 2 MiB page directly and omit the lowest table lookup.
LFU replacement
LFU replacement selects the page with the lowest counted access frequency, which can favor pages that were popular long ago.
Without aging, a formerly hot page may remain while a useful page from a new phase is evicted.
Linear page table
A linear page table is an array with one entry for every possible virtual page, using the virtual page number as its index.
A full 32-bit linear table with 4 KiB pages and 4-byte entries occupies 4 MiB per process.
Local replacement
Local replacement confines victim selection to the faulting process’s own frame allocation, limiting cross-process eviction.
A four-frame allocation still cannot hold a six-page working set merely because replacement is local.
LRU replacement
LRU replacement evicts the resident page whose most recent access is oldest, updating recency when a reference hits.
A hit on an old arrival protects it under LRU even though it remains old in FIFO’s queue.

M

Major page fault
A major page fault requires a storage read to obtain the page’s contents before the operating system can complete the mapping.
Reading a swapped-out data page from an SSD is still a major fault even if the SSD is fast.
Memory-management unit
A memory-management unit is processor hardware that translates addresses and enforces mapping permissions during memory references.
The MMU can reject a write through a read-only translation even when the TLB lookup hits.
Minor page fault
A minor page fault is resolved without reading page contents from storage, such as by supplying zeroed memory or mapping a resident frame.
A demand-zero allocation can increment the minor-fault count without causing swap traffic.
Multi-generational LRU
Multi-generational LRU is a Linux page-reclaim approach that groups pages by observed recency to guide eviction under memory pressure.
Generation-based aging gives the reclaim code more recency information than one unaged use bit.
Multi-level page table
A multi-level page table is a hierarchy of indexed tables that allocates lower-level branches only where address mappings need them.
An unused virtual range can be represented by an absent branch instead of thousands of unused leaf entries.

O

Optimal replacement
Optimal replacement evicts the page needed farthest in the future and gives the minimum miss count for a fully known reference string.
OPT is a simulation benchmark because an operating system cannot know an arbitrary program’s future accesses.
Out-of-memory killer
An out-of-memory killer terminates a selected process under extreme pressure so its memory can be reclaimed as the process exits.
The killed process loses its work, while the released resources may let other processes continue.

P

Page
A page is a fixed-size block of virtual addresses that is mapped as one unit to an equal-sized physical frame.
A 4 KiB virtual page can occupy frame 12 even if the next virtual page occupies frame 3.
Page daemon
A page daemon is a background operating-system worker that reclaims memory and prepares free frames before urgent allocations need them.
Linux’s kswapd can begin reclaiming pages while a small reserve of free frames still remains.
Page directory
A page directory is an upper-level table whose entries locate lower-level page-table pages or mark their regions as absent.
In a 10/10/12 system, one directory entry covers a virtual region containing 1,024 data pages.
Page directory entry
A page directory entry is a record that points to a lower table and carries state or permissions for the virtual region it represents.
A non-leaf PDE’s frame number locates a page of PTEs, not the program’s final data frame.
Page fault
A page fault is an exception raised when a memory access cannot complete with its current mapping, including absence or a protection violation.
The handler can repair a COW write fault but reject a write to genuinely read-only program code.
Page offset
A page offset is the byte position within a page, encoded in the low address bits and preserved during translation.
An offset of 904 still identifies byte 904 after the page is mapped into physical frame 9.
Page table
A page table is an operating-system-managed structure that records a process’s virtual-to-physical mappings and access information.
Switching the current page table lets two processes use the same virtual address for different data.
Page table entry
A page table entry is a mapping record containing a physical frame number and state or protection information for a virtual page.
The processor checks a page table entry before using its frame number to complete a translation.
Page-fault frequency control
Page-fault frequency control adjusts a process’s frame allocation using upper and lower thresholds on its measured fault rate.
A process above the upper threshold needs more frames; one below the lower threshold can release some.
Page-table walk
A page-table walk follows indexed mapping entries from the selected root toward a leaf that identifies the requested physical page.
A two-level walk reads a PDE and a PTE before the processor accesses the requested data.
Paging-structure cache
A paging-structure cache retains intermediate page-table information so later walks can avoid repeating some upper-level lookups.
A four-level TLB miss may cost fewer than four main-memory delays when intermediate entries are cached.
Physical frame number
A physical frame number identifies a frame by its index in physical memory, rather than by the byte address of the frame’s start.
For 4 KiB pages, physical frame number 3 identifies the frame beginning at byte address 12,288.
PML4
A PML4 is the top-level table in four-level x86-64 paging, selected through CR3 and indexed by virtual-address bits 47–39.
The PML4 entry leads to a pointer-directory table before the walk reaches directory and leaf levels.
Prefetching
Prefetching supplies pages before demand reaches them, using an expected access pattern to reduce later waiting for page contents.
Reading ahead may help a sequential access pattern but wastes resources if the predicted pages are unused.
Present bit
A present bit tells hardware whether an entry supplies a resident mapping; a clear bit requires software to determine the page’s status.
A clear present bit can lead the handler to swap metadata or to a demand-zero allocation.
Protection bits
Protection bits specify permitted operations on a mapping, such as reading, writing, execution, and access from user mode.
A resident code page can reject a write even though its frame number is available.

R

Random replacement
Random replacement chooses a resident victim randomly, avoiding recency ordering while producing different outcomes across runs.
Random choices can outperform LRU on an oversized cycle on average, but one run can still be unlucky.
Reference string
A reference string is an ordered sequence of page numbers used to simulate hits, misses, and victim choices for a replacement policy.
The same reference string and initial frames let FIFO and LRU be compared under equal conditions.

S

Segmentation fault
A segmentation fault is a usual operating-system response to an invalid or forbidden memory access that the handler cannot legitimately repair.
A TLB miss on a present permitted page does not by itself cause a segmentation fault.
Segmentation-and-paging hybrid
A segmentation-and-paging hybrid gives each segment a bounded page table, omitting entries for virtual gaps between segments.
Separate heap and stack tables save gap entries but can require different-sized table allocations.
Shared code page
A shared code page is a physical page of program instructions mapped read-only into more than one process’s address space.
Several instances of an editor can use one resident copy of the same code page through different PTEs.
Software-managed TLB
A software-managed TLB uses an operating-system exception handler to find a missing translation and install it with privileged instructions.
A classic MIPS refill handler returns so the processor can retry the instruction that missed.
Sparse address space
A sparse address space has large unused virtual regions between mapped areas, such as the gap between a process’s heap and stack.
The large virtual gap needs no data frames merely because addresses exist on both sides of it.
Spatial locality
Spatial locality is the tendency to access nearby addresses close together in time, allowing one page translation to serve many references.
Reading adjacent array elements often produces many TLB hits after the first element on a page.
Stack algorithm
A stack algorithm has nested resident sets as frame capacity increases, ensuring that additional frames do not increase its miss count.
LRU and OPT have the stack property, although LRU can still make more misses than OPT.
Supervisor-only mapping
A supervisor-only mapping permits privileged kernel access while denying ordinary user-mode references to the mapped memory.
A user-mode read of a supervisor-only kernel page is rejected even when the mapping is present.
Swap space
Swap space is a reserved storage area used to preserve page contents displaced from physical memory, such as a swap file or partition.
A fault handler can read a displaced page’s bytes from its recorded swap location into a free frame.

T

Table index
A table index is the VPN field that selects an entry within the lower-level table located by the preceding directory entry.
Table index 3 locates a PTE 12 bytes after its table base when entries occupy four bytes.
Temporal locality
Temporal locality is the tendency to reuse recently accessed addresses, making recent translation history useful for caching.
A short loop repeatedly executes code on the same few pages and can reuse their cached mappings.
Thrashing
Thrashing is sustained heavy page movement with little useful execution because active processes need more resident pages than memory holds.
Low CPU use alongside constant paging can signal that starting more processes would worsen pressure.
TLB flush
A TLB flush invalidates cached translations in its scope, forcing later references to refill them from current mapping information.
Flushing on a context switch prevents an untagged translation from being used by the next process.
TLB miss
A TLB miss occurs when no usable translation for a requested virtual page and context is found in the translation cache.
A TLB miss can be filled from a present PTE without reading any page contents from swap.
TLB reach
TLB reach is the amount of memory represented by a set of cached translations, calculated as entry count multiplied by page size.
Sixty-four entries represent 256 KiB with 4 KiB pages, assuming every entry maps that page size.
TLB shootdown
A TLB shootdown coordinates invalidation across processor cores that may cache a mapping changed by the operating system.
Removing write permission requires remote cores to stop using any older writable translation.
Translation lookaside buffer
A translation lookaside buffer is a fast hardware cache of recent virtual-page translations and their access information.
Sequential access to many integers on one page can reuse a single cached TLB translation.

U

Use bit
A use bit records whether a page has been accessed since the operating system last cleared the bit; it does not count accesses.
Ten reads after clearing still leave the same bit value as one read: the use bit is 1.

V

Victim page
A victim page is a resident page selected for eviction so its physical frame can be reused for another page’s contents.
OPT chooses the resident victim with the most distant next use in the known future string.
Virtual page number
A virtual page number is the high-order part of a virtual address that identifies which virtual page contains the requested byte.
With 1,024-byte pages, virtual address 5,000 has virtual page number 4 and offset 904.

W

Watermark
A watermark is a free-memory threshold used to trigger or limit background reclamation so the system maintains a reserve of frames.
When free memory falls below a low watermark, reclaim work starts toward a higher free-frame target.
Working set
A working set is the set of distinct pages a process used within a recent reference window, estimating its current resident needs.
For the five-reference window 4, 5, 4, 5, 4, the working set is {4, 5}, of size two.
Write-back
Write-back preserves a resident page’s modified contents in backing storage, allowing its dirty state to be cleared after success.
Writing a page back does not require evicting it immediately; the process can keep using the frame.

About this lesson

By StudeliReport a mistake

Make your own Study Materials

Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.

Get Started