Module 5 ppt
Memory heirarchy
| 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
Memory management refers to the process by which an operating system:
- Allocates memory to processes
- Deallocates memory when no longer needed
- Protects memory from unauthorized access
- Optimizes memory utilization and system performance
Memory Allocation
Memory Allocation is the process of assigning memory space to a program or process.
The OS:
- Keeps track of used and free memory blocks
- Allocates memory when a process starts
Types of Allocation
- Contiguous allocation
- Non-contiguous allocation
Memory Deallocation
Memory Deallocation occurs when a process terminates or releases memory.
Importance:
- Prevents memory wastage
- Makes memory available for other processes
- Avoids memory leaks
Memory Protection
Memory Protection ensures that one process cannot access another process’s memory.
Memory Swapping
Swapping is the process of moving processes between main memory and disk.
- Inactive processes are swapped out to disk
- Active processes are swapped into memory
Virtual Memory
Virtual Memory allows programs to use more memory than physically available.
Key features:
- Uses disk as an extension of RAM
- Only required portions of a program are loaded into memory
- Improves multitasking capability
Memory Mapping
Memory Mapping translates virtual addresses to physical addresses.
Performed using:
- Page tables
- Memory Management Unit (MMU)
Memory Fragmentation
Fragmentation occurs when memory is broken into small unusable pieces.
Types:
- Internal Fragmentation
- External Fragmentation
Memory Paging
Paging divides memory into fixed-size units called pages.
Components:
- Pages (virtual memory)
- Frames (physical memory)
- Page table
Page Table
A Page Table stores the mapping between:
- Virtual page numbers
- Physical frame numbers
Memory Protection
- Memory protection is required to prevent:
- One process from accessing another process’s memory
- User processes from modifying operating system memory
Relocation and Limit Registers
- Protection can be provided using:
- Relocation register - The value of the smallest physical address
- Limit register - The range of logical addresses

Dispatcher and Context Switch
- When the CPU scheduler selects a process:
- The dispatcher performs a context switch
- During context switch:
- Relocation register is loaded
- Limit register is loaded
- Values correspond to the selected process
Swapping
- Swapping is a memory management technique used by the operating system
- A process must be in memory to be executed
- Swapping allows processes to be temporarily moved out of main memory to disk

Swapping and Priority-Based Scheduling
- A variant of swapping is used in priority-based scheduling algorithms
- If a higher-priority process arrives:
- The OS swaps out a lower-priority process
- Loads and executes the higher-priority process
- After completion:
- The lower-priority process is swapped back in
- Execution resumes from where it stopped