Chapter 5

Memory management

Separate address translation from allocation. Translation answers where an address refers; allocation answers which regions exist and how much metadata or unused space they consume. Page sizes, addressable units and entry widths must be resolved before counting bits.

5.1 Relocation, segmentation and protection

Compile-time binding fixes addresses when a location is already known. Load-time binding relocates code when it is loaded. Execution-time translation allows mappings to change while the process runs. Logical addresses belong to the process's view; physical addresses identify memory locations.

With segmentation, different logical segments can have different lengths and protection. Pure segmentation needs each segment to fit a contiguous physical region and can suffer external fragmentation. With segmented paging, a segment selects its page table and its offset is split into a page number and page offset.

5.2 Contiguous allocation and fragmentation

Past papers · CS 2014–2026 (23 papers): 3 questions, 5 marks

Allocation ruleSelection among holes large enough
First fitFirst suitable hole in the stated scan order
Next fitContinue from the previous scan position
Best fitSmallest suitable hole
Worst fitLargest suitable hole

After allocation, replace the selected hole with its remainder; remove a zero remainder. Merge only physically adjacent free holes after deallocation. A total free byte count is insufficient if no single hole is large enough. Fixed partitions waste room inside an assigned partition; variable partitions can leave separated external holes. Compaction requires relocation support.

For final-page waste uniform over the integer byte counts 0,1,…,P−10,1,\ldots,P-1, the exact average is (P−1)/2(P-1)/2 bytes; the familiar half-page estimate is P/2P/2. Neither is a deterministic waste for a particular process.

Buddy allocation splits a power-of-two block into equal halves until the smallest permitted block fits. Only free buddies of the same size coalesce. Two adjacent free blocks are not necessarily buddies. Slab allocation instead keeps caches of objects of selected sizes; it is a way to allocate kernel objects, not a replacement for address translation.

5.3 Paging and address fields

Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks

Equal-sized pages can occupy any free frames, so ordinary frame allocation avoids external fragmentation. The last allocated page can still contain unused bytes: paging does not eliminate internal fragmentation.

Page translation replaces the page number and preserves the offset.Page translation replaces the page number and preserves the offset.

For an array trace, convert each referenced element into its byte address, then into a page number. Row-major and column-major loop orders can produce very different reference strings. Page replacement operates on those page numbers, not on element indices.

5.4 Page-table size and hierarchy

Past papers · CS 2014–2026 (23 papers): 10 questions, 17 marks

The MMU translates addresses and checks access permissions; it traps on a missing or forbidden mapping. The OS creates page tables, allocates frames and handles those traps. Multilevel tables reduce metadata for sparse address spaces; multiple page sizes do not logically require multiple table levels.

A present bit says whether the mapping is resident; a permission bit says whether an operation is allowed. Reference/accessed bits record use, and dirty bits record modification. Names such as “valid” can combine several meanings in simplified problems, so use the supplied definition.

For sparse mappings, count distinct index prefixes rather than dividing allocated data bytes by one table's reach. Two far-apart pages may need two leaf tables even though adjacent pages need only one. Include the root and partially used intermediate tables. An inverted table has one entry per physical frame; lookup must identify the process and virtual page, commonly using hashing. Sharing needs additional representation.

If the question fixes the number of levels, subtract the offset bits and all inner-level index bits from the address width to obtain the outer index width. The resulting outer table may span several pages. Do not add a level merely to force that specified outer table into one page.

5.5 TLB reach, width and effective access time

Past papers · CS 2014–2026 (23 papers): 5 questions, 9 marks

A TLB caches translations. A hit avoids a page-table walk but normally still needs the data access. A miss can find a resident page in memory; it is not itself proof of a page fault.

5.6 Page-size trade-off

Larger pages shorten linear page tables and increase TLB reach for a fixed entry count. They can also transfer unused data and increase internal waste. There is no universal best page size independent of workload and hardware.

Last-minute recall

  • A length limit excludes the offset equal to that length.
  • Fragmentation depends on the allocation unit and alignment.
  • Paging preserves the offset and changes the page-number field.
  • Physical width determines frame bits; virtual width determines table entries.
  • Count allocated page-table nodes at every level, including the root.
  • A TLB entry contains a mapping, not an entire page of data.
  • TLB miss, nonresident page and protection fault are different conditions.
  • Divide bits by 8 only after deciding the storage alignment rule.

Revise offline: the whole Operating System handbook as one PDF

50 pages · 2.0 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections