BCS401 Operating System Semester IV · AY 2025-26 onward
Unit 4 · Memory Management

Lecture 4: Paging and Protection schemes

Learning outcomes

  • Outline memory protection mechanisms such as base/limit registers and access control.
Lecture Notes

Main content

Study Notes: Protection Schemes, Paging, Segmentation, Paged Segmentation, Virtual Memory Concepts, and Demand Paging

These notes explain the key memory-management concepts used by operating systems to protect memory, organize address spaces, and run processes larger than main memory. The topics move from simple protection mechanisms to advanced virtual-memory ideas.

Memory Protection Paging Segmentation Virtual Memory Demand Paging MMU

1. Protection Schemes

1.1 Why protection is required

In a multiprogramming system, many processes stay in memory at the same time. If memory is not protected, one process may accidentally or intentionally overwrite another process or even the operating system itself. Protection mechanisms make sure that each process accesses only its own legal address range.

Main goal: Prevent illegal memory access and isolate one process from another.

1.2 Base and limit register scheme

A simple hardware-based protection method uses:

  • Base (or relocation) register – stores the starting physical address of the process.
  • Limit register – stores the size of the process address space.
If logical address < limit, then physical address = base + logical address
Otherwise, trap to operating system
CPU Base Register = 4000 Limit Register = 1200 Address Check logical < limit ? Valid Access Physical = 4000 + logical Invalid Access Protection Trap
Figure 1: The base-limit protection scheme checks each address before allowing access.

1.3 Advantages and limitations

Point Explanation
Advantage Simple and fast hardware protection for contiguous allocation.
Limitation Works well only when the process occupies one contiguous memory block.
Result As memory schemes became more flexible, page-level and segment-level protection became more useful.

1.4 Protection with paging and segmentation

In modern memory systems, protection is finer and more flexible:

  • Each page can have valid-invalid, read, write, and execute bits.
  • Each segment can have its own limit and access rights.
Protection summary: base-limit protection is simple, while page/segment protection is more flexible and supports modern address-space design.

2. Paging

2.1 Basic concept

Paging is a noncontiguous memory-management scheme. Logical memory is divided into fixed-size pages, and physical memory is divided into equal-size frames. Any page can be loaded into any free frame.

Main idea: A process need not occupy one continuous physical block. This removes the major external-fragmentation problem of contiguous allocation.

2.2 Address translation in paging

A logical address is divided into:

  • Page number (p)
  • Offset (d)

The page number indexes the page table, which gives the corresponding frame number. The frame number is then combined with the offset to form the physical address.

Logical Address = [ Page Number | Offset ]
Physical Address = [ Frame Number | Offset ]
Logical Address [ p | d ] Page Table Page 0 → Frame 4 Page 1 → Frame 1 Physical Address [ f | d ] Physical Memory Frame 0 Frame 1 ← Page 1 Frame 2 Frame 3 Frame 4 ← Page 0 Frame 5
Figure 2: Paging uses a page table to translate page number into frame number.

2.3 Page table and MMU

Address translation is handled by the MMU (Memory Management Unit). The MMU uses the page table to map logical pages to physical frames.

2.4 TLB (Translation Lookaside Buffer)

A TLB is a small, fast associative memory that stores recent page-table entries. If the required entry is found in the TLB, address translation becomes much faster.

Mini Numerical

Page size = 1024 bytes, logical address = 2500

  • Page number = 2500 / 1024 = 2
  • Offset = 2500 mod 1024 = 452

If Page 2 maps to Frame 7, then:

Physical Address = (7 × 1024) + 452 = 7620

2.5 Advantages and disadvantages

Advantages

  • Eliminates external fragmentation.
  • No need for contiguous physical memory.
  • Supports fine-grained protection.
  • Supports sharing and virtual memory.

Disadvantages

  • Causes internal fragmentation.
  • Requires page-table overhead.
  • Adds translation overhead.
  • Needs hardware support.

3. Segmentation

3.1 Basic concept

Segmentation divides a program into logical units called segments. Each segment corresponds to a meaningful program part, such as:

  • main program
  • procedure or function
  • stack
  • heap
  • data segment
  • symbol table

Unlike paging, segment sizes are variable. Segmentation matches the programmer’s logical view of memory more naturally.

3.2 Logical address in segmentation

In segmentation, a logical address has two parts:

  • Segment number (s)
  • Offset (d)
Logical Address = < segment number, offset >

3.3 Segment table

Each segment table entry usually stores:

  • Base – starting physical address of the segment
  • Limit – length of the segment
Logical Address < Segment No, Offset > Segment Table Seg 0 → Base 1000, Limit 400 Seg 1 → Base 2500, Limit 700 Seg 2 → Base 4200, Limit 300 Limit Check offset < limit ? Valid Physical = base + offset Invalid Segmentation Fault / Trap Physical Memory Seg 0 Seg 1 Seg 2
Figure 3: In segmentation, each segment has its own base and limit.

3.4 Advantages and disadvantages

Advantages Disadvantages
Matches the programmer’s logical view of memory. Causes external fragmentation.
Easy to protect and share logical program units. May require compaction.
Each segment can have its own protection. Allocation is more complex because segments are variable-sized.

4. Paged Segmentation

4.1 Meaning

Paged segmentation combines the ideas of segmentation and paging:

  • A program is first divided into segments according to logical meaning.
  • Each segment is then divided into fixed-size pages.

This gives the logical advantages of segmentation and the physical-allocation advantages of paging.

4.2 Address format

Logical Address = < Segment Number, Page Number, Offset >

4.3 Translation process

  1. Use the segment number to find the page table for that segment.
  2. Use the page number to find the frame number.
  3. Combine the frame number with the offset to form the physical address.
Logical Address < Segment, Page, Offset > Segment Table Seg 0 → PT0 Seg 1 → PT1 Seg 2 → PT2 Page Table Page 0 → Frame 8 Page 1 → Frame 2 Page 2 → Frame 6 Physical Address [ Frame | Offset ] Physical Memory Frames Frame 2 Frame 6 Frame 8
Figure 4: Paged segmentation first selects a segment, then a page inside that segment.

4.4 Why it is useful

  • Segmentation gives logical organization.
  • Paging removes external fragmentation within segments.
  • Protection and sharing can be applied more flexibly.

5. Virtual Memory Concepts

5.1 Meaning

Virtual memory is a memory-management technique that allows the execution of a process that is not completely loaded into main memory. Only the required part of the process needs to be in RAM; the rest can stay on disk until needed.

Big idea: Virtual memory separates the logical memory seen by the programmer from the physical memory actually available.

5.2 Why virtual memory is needed

  • Programs can be larger than physical memory.
  • Only needed pages must be loaded.
  • Memory utilization improves.
  • More processes can stay active in the system.
Logical Address Space Page 0 Page 1 Page 2 Page 3 Page 4 Main Memory Page 0 in Frame Free / Other Process Page 3 in Frame Free / Other Process Page 4 in Frame Backing Store / Disk Page 1 on Disk Page 2 on Disk
Figure 5: Virtual memory allows some pages to remain on disk while only needed pages stay in RAM.

5.3 Important terms

Term Meaning
Virtual address space The logical memory space seen by a process.
Physical memory The actual RAM available in the machine.
Backing store Disk space used to hold pages not currently in memory.
Page fault Occurs when a referenced page is not currently in memory.

6. Demand Paging

6.1 Meaning

Demand paging is a virtual-memory technique in which a page is loaded into memory only when it is actually needed. If a process never uses a page, that page is never brought into RAM. Nice and efficient — when it works well.

6.2 Basic idea

  • Process starts with only some pages in memory.
  • Page-table entries for absent pages are marked invalid.
  • When the CPU references a missing page, a page fault occurs.
  • The OS loads the required page from disk into a free frame.
  • The page table is updated and the instruction is restarted.
1. CPU references page 2. Check page table 3. Invalid entry Page Fault 4. Locate page on disk 5. Load page into RAM 6. Update page table 7. Restart instruction
Figure 6: Demand paging loads a page only when it is actually referenced.

6.3 Steps in handling a page fault

  1. The CPU references a page.
  2. The page-table valid-invalid bit shows that the page is not in memory.
  3. A page-fault trap occurs to the operating system.
  4. The OS checks whether the memory reference is legal.
  5. If valid, the OS finds a free frame.
  6. The required page is read from disk into that frame.
  7. The page table is updated.
  8. The interrupted instruction is restarted.

6.4 Performance issue

Demand paging works well only if page faults are rare. If page faults happen too often, the CPU spends too much time waiting for disk I/O instead of executing instructions.

Important: Page-fault service time is much larger than normal memory-access time. That is why even a small page-fault rate can hurt performance badly.

6.5 Advantages and disadvantages of demand paging

Advantages

  • Only needed pages are loaded.
  • Faster program start in many cases.
  • Better memory utilization.
  • Supports larger address spaces.

Disadvantages

  • Page faults are expensive.
  • Requires backing store and hardware support.
  • Too many page faults can lead to severe slowdown.

7. Paging vs Segmentation vs Paged Segmentation

Basis Paging Segmentation Paged Segmentation
Basic unit Fixed-size page Variable-size segment Segment divided into pages
User view Not natural to programmer Natural logical view Natural + efficient
Fragmentation Internal fragmentation External fragmentation Reduced external fragmentation
Protection Per page Per segment Both levels possible
Complexity Moderate Moderate Higher

8. Quick Exam Notes

Protection schemes: Memory protection ensures that a process accesses only its legal memory area. Base-limit registers are used in contiguous allocation, while page and segment protection bits are used in modern systems.

Paging: Logical memory is divided into fixed-size pages and physical memory into frames. A page table maps pages to frames. Paging removes external fragmentation and supports virtual memory.

Segmentation: A program is divided into logical variable-size segments such as code, data, and stack. Each segment has a base and limit, making logical organization easy but causing external fragmentation.

Paged segmentation: A hybrid method in which each logical segment is further divided into pages, combining the strengths of segmentation and paging.

Virtual memory: Allows a process to execute even if the whole process is not in RAM. It separates logical address space from physical memory.

Demand paging: Loads a page only when it is actually referenced. If the page is absent, a page fault occurs and the OS brings it from disk into memory.

One-Page Summary

9. Likely University Questions

  1. Explain memory protection using base and limit registers.
  2. What is paging? Explain address translation with a neat diagram.
  3. What is segmentation? How is it different from paging?
  4. Explain paged segmentation with suitable address format.
  5. What is virtual memory? Why is it needed?
  6. Explain demand paging and page-fault handling.
  7. Differentiate between paging, segmentation, and paged segmentation.