Show understanding of virtual memory, paging and segmentation for memory management

16.1 Purposes of an Operating System (OS)

Why do we need an OS? 📚

An OS is the invisible manager that lets many programmes run on a computer at the same time. It does three main things:

  • Resource allocation – decides who gets CPU time, memory, and I/O devices.
  • Protection & isolation – keeps one programme from messing up another.
  • Convenience – provides a friendly interface (commands, files, etc.).

Key Functions of an OS

  1. Process Management – create, schedule, and terminate processes.
  2. Memory Management – keep track of which parts of memory are free or used.
  3. File System – organise data on storage devices.
  4. Device Management – control hardware devices.
  5. Security & Protection – enforce access rights.

Memory Management: Virtual Memory, Paging & Segmentation

Think of your computer’s memory as a huge library. Virtual memory lets each programme think it owns a whole library, even if the real library is smaller. The OS maps the programme’s “library” to the real shelves.

Paging 📄

Paging splits the virtual library into equal‑sized pages (e.g., 4 KB each). The real shelves are frames of the same size. A page table keeps a record:

Page No. Frame No. Valid?
0 5
1 12
2

When a programme asks for address 0x00001234, the OS splits it into page = 0 and offset = 0x1234, looks up the frame (5), and produces the physical address 0x00051234.

Segmentation 🗂️

Segmentation divides a programme into logical parts: code, data, stack, heap. Each segment has a base (starting address) and a limit (size). The OS stores a segment table:

Segment Base Limit
Code 0x00000000 0x0000FFFF
Data 0x00010000 0x0000FFFF
Stack 0x00020000 0x0000FFFF

A logical address segment = 1, offset = 0x0000ABCD becomes physical 0x0001ABCD if offset ≤ limit. If the offset is too large, a segmentation fault occurs.

Paging + Segmentation

Many OSes combine both: each segment is further divided into pages. This gives the logical organisation of segmentation and the efficient, fixed‑size handling of paging.

Exam Tips for 16.1

  • When asked to calculate the number of pages, use ceil(virtualSize / pageSize).
  • Explain the difference between a page fault and a segmentation fault – one is a missing page in RAM, the other is an illegal offset.
  • Describe how the OS uses the page table to translate virtual to physical addresses.
  • Show how the OS handles a page fault – load the page from disk, update the table, and resume.
  • Remember that segmentation provides protection because each segment can have its own read/write/execute permissions.
  • When combining segmentation and paging, note that the segment base + offset gives a linear address, which is then paged to a frame.
  • Use the TLB (Translation Lookaside Buffer) to explain why address translation is fast.
  • Include a quick example: “If a program needs 1 MB of virtual memory and the page size is 4 KB, it needs ceil(1 MB / 4 KB) = 256 pages.”

Revision

Log in to practice.

2 views 0 suggestions