Module 5

Module 5

Memory Management


Memory Hierarchy Overview

Computer memory is organized as a hierarchy based on speed, cost, and capacity.
Faster memory is more expensive and smaller; slower memory is cheaper and larger.

General order (fastest → slowest):
Registers → Cache → Main Memory (RAM) → Secondary Storage → Tertiary Storage


CPU Registers

Description

Speed


Cost

Capacity

Use Case


Cache Memory

Description

Levels


Speed

Cost


Capacity

Use Case


Main Memory (RAM)

Description

Type


Speed

Cost

Capacity

Use Case


Secondary Memory (Storage)

Description

Types


Speed

Cost


Capacity

Use Case


Tertiary / Offline Storage

Description

Examples


Speed

Cost


Capacity

Use Case


Comparative Summary

Memory Type Speed Cost per Bit Capacity
Registers Fastest Highest Very Small
Cache Very Fast Very High Small
RAM Fast Medium Medium–Large
SSD / HDD Slow Low Large
Tertiary Slowest Lowest Very Large

Memory Management is a core function of an Operating System (OS) that handles
the efficient use of primary memory (RAM).


It ensures that:


Definition of Memory Management

Memory management refers to the process by which an operating system:


Objectives of Memory Management


Memory Allocation

Memory Allocation is the process of assigning memory space to a program or process.

The OS:


Types of Allocation


Memory Deallocation

Memory Deallocation occurs when a process terminates or releases memory.

Importance:

The OS updates its memory management tables accordingly.


Memory Protection

Memory Protection ensures that one process cannot access another process’s memory.

Methods:


Benefits:


Memory Swapping

Swapping is the process of moving processes between main memory and disk.


Purpose:

Swapping is a key component of virtual memory.


Virtual Memory

Virtual Memory allows programs to use more memory than physically available.

Key features:


Memory Mapping

Memory Mapping translates virtual addresses to physical addresses.

Performed using:


Advantages:


Memory Fragmentation

Fragmentation occurs when memory is broken into small unusable pieces.

Types:


Impact:


Memory Compaction

Memory Compaction is a technique to reduce external fragmentation.


Memory Paging

Paging divides memory into fixed-size units called pages.

Components:


Benefits:


Page Table

A Page Table stores the mapping between:


Memory Protection


Relocation and Limit Registers


Relocation Register


Limit Register


Address Validation


Address Mapping by MMU


Role of MMU


Pasted image 20260118212531.png


Dispatcher and Context Switch


Protection Benefits


Dynamic OS Size Support


Swapping


Pasted image 20260118195302.png


Swapping and Priority-Based Scheduling



Roll Out and Roll In


Memory Space and Swapping


Address Binding and Swapping



Backing Store


Ready Queue and Process States


Role of the Dispatcher



Context Switch Time in Swapping


Swap Time Example (Given Values)

Assumptions:

Calculation:


Total Swap Time Calculation


Impact on CPU Scheduling


Swapping and Round-Robin Scheduling


Contiguous Memory Allocation


Placement of the Operating System


Need for Multiprogramming


Contiguous Memory Allocation Concept


Fixed-Size Partitioning


Multiple-Partition Method


Process Life Cycle in Memory


Dynamic Memory and Holes


Hole Splitting


Hole Merging


Dynamic Storage Allocation Problem


Memory Allocation Strategies


First Fit Strategy


Best Fit Strategy


Worst Fit Strategy


Comparison of Fit Strategies


Fragmentation


External Fragmentation


Pasted image 20260118212726.png


Worst-Case External Fragmentation


Compaction


Conditions for Compaction


Dynamic Relocation and Compaction


Cost of Compaction


Noncontiguous Memory Allocation


Paging and Segmentation


Internal Fragmentation


Example of Internal Fragmentation


Pasted image 20260118212923.png


Solution Approach


Virtual Memory




Paging


Assets/Pasted image 20260119092648.png


Hardware Support for Paging


Assets/Pasted image 20260119092837.png


Memory Division in Paging


Loading Pages into Memory


Backing Store Structure


Address Structure in Paging


Page Table


Assets/Pasted image 20260119093024.png


Address Translation



Logical Address Structure


Logical Address Representation


Fragmentation in Paging


Internal Fragmentation in Paging


Internal Fragmentation Example


Hardware Support for Paging


Page Table Using Registers


Large Page Tables in Modern Systems


Page Table in Main Memory


Problem with PTBR Approach


Translation Look-Aside Buffer (TLB)


Characteristics of TLB


TLB Operation


TLB Size


Assets/Pasted image 20260119093419.png


Segmentation


Purpose of Segmentation


Segmented Memory System


Memory Allocation in Segmentation


Addressing in Segmentation


Logical Address Structure


Segment Table


Address Validation and Mapping


Example: Segment Mapping


Example Calculations


More Examples


Protection Example


Assets/Pasted image 20260119093739.png


Variable Partition Memory Allocation


Characteristics of Variable Partitioning


Page Fault


Page Fault in Virtual Memory


Page Fault Handling


Page Swapping Process


Performance Impact


Importance of Reducing Page Faults


Page Replacement Algorithms


First-In-First-Out (FIFO) Page Replacement


FIFO Working and Limitation



Least Recently Used (LRU) Page Replacement Algorithm


Working, Advantages, and Limitations of LRU



Optimal Page Replacement Algorithm


Purpose and Working of Optimal Algorithm



Disk Structure


File System


Types of File Systems


Disk Partitions


Boot Records and Importance


Assets/Pasted image 20260119095910.png


Category Details
Platter Size (Historical Range) 0.85” to 14”
Common Platter Sizes 3.5”, 2.5”, 1.8”
Storage Capacity 30 GB to 3 TB per drive
Theoretical Transfer Rate 6 Gb/sec
Effective Transfer Rate ~1 Gb/sec
Seek Time Range 3 ms to 12 ms

Typical Desktop Seek Time ~9 ms
Average Seek Time Basis Measured or calculated using 1/3 of total tracks
Latency Dependency Based on spindle (RPM) speed
Latency Formula Latency = 60 / RPM
Average Latency ½ × (60 / RPM)

Disk Addressing and Logical Block Mapping



Disk Scheduling


Disk I/O Requests and Bandwidth



Request Queues and Scheduling Need


Rotational Latency


Rotational Latency – Calculation and Optimization


Seek Time


Seek Time – Measurement and Importance


Rotational Latency & Seek Time – Numerical Example


Example Hard Disk Specifications


Rotational Latency Calculation


Seek Time Calculation


Scheduling algorithms


Disk Management


Disk Management – Partition Operations


Disk Management – Advanced Features


RAID – Redundant Array of Independent Disks


Reliability Factors in RAID


RAID – Performance & Improvements


Disk Striping and RAID Levels


RAID Mirroring and Stripes


RAID Array Management


RAID levels

Assets/Pasted image 20260119101506.png


Assets/Pasted image 20260119101618.png


Assets/Pasted image 20260119101708.png