UNIHIVE

Study Hub UNIPORT CSC 394

CSC 394 · Operating Systems

Memory management

Address binding, logical vs physical addresses, contiguous allocation and fragmentation, placement strategies, paging, segmentation and address translation.

Our notes

2 min read

Basics

  • Logical (virtual) address: generated by the program. Physical address: the real location in RAM. The MMU (memory management unit) translates one to the other.
  • Address binding can happen at compile time, load time or run time (run-time binding allows programs to move in memory).
  • Swapping: moving a whole process out to disk and back.

Contiguous allocation

Each process gets one block of memory.

  • Fixed partitions: memory divided in advance; wasted space inside a partition is internal fragmentation.
  • Variable partitions: blocks made to fit; free holes appear between processes, external fragmentation. Compaction moves processes together to join holes (costly).

Placement strategies (worked)

Free holes: 100K, 500K, 200K, 300K, 600K (in that order). Requests: 212K, 417K, 112K, 426K.

Strategy212K417K112K426K
First fit (first hole big enough)500K (288 left)600K (183 left)288K (176 left)waits
Best fit (smallest hole big enough)300K (88 left)500K (83 left)200K (88 left)600K (174 left)
Worst fit (largest hole)600K (388 left)500K (83 left)388K (276 left)waits

Here best fit places all four.

Paging

Physical memory is cut into fixed-size frames, and logical memory into pages of the same size. A page table maps each page to a frame. No external fragmentation (a little internal fragmentation in each process's last page).

  • Logical address = (page number p, offset d). With page size 2ⁿ, the low n bits are the offset.

Worked example. Page size 1 KB (1,024 bytes). Logical address 3,500: p = 3500 ÷ 1024 = 3 remainder 428, so d = 428. If the page table maps page 3 to frame 7, the physical address = 7 × 1024 + 428 = 7,596.
Worked example (bits). 32-bit addresses, 4 KB pages (2¹²): offset 12 bits, page number 20 bits → up to 2²⁰ (about a million) pages per process.

  • TLB (translation look-aside buffer): a small fast cache of recent page-table entries. Effective access time = hit ratio × (TLB + memory) + miss ratio × (TLB + 2 × memory). With TLB 20 ns, memory 100 ns, hit ratio 80%: 0.8 × 120 + 0.2 × 220 = 96 + 44 = 140 ns.
  • Large page tables are split up: multilevel (hierarchical) or inverted page tables.

Segmentation

Memory is divided into variable-size segments that match the program's logical parts (code, data, stack, functions). Address = (segment number, offset); the segment table holds base and limit for each. An offset ≥ limit is an error (trap). Matches the programmer's view, but causes external fragmentation.
Worked example. Segment 2 has base 4,300 and limit 400. Address (2, 53) → 4,300 + 53 = 4,353. Address (2, 500) → 500 ≥ 400 → trap (invalid).

Paging vs segmentation

PagingSegmentation
fixed-size pagesvariable-size segments
invisible to the programmerfollows the program's structure
internal fragmentationexternal fragmentation

Many systems combine them (segmented paging).

Exams usually ask: logical vs physical addresses; internal vs external fragmentation; first/best/worst fit on given holes; page number and offset calculations; physical address from a page table; TLB effective access time; segmentation address translation.

Common mistake: in paging, adding the page number to the frame number. The physical address is frame number × page size + offset.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

We link to free material and never copy it. Every link was opened by our team before it went up.

All CSC 394 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.