OPERATING SYSTEM NOTES
3. MEMORY MANAGEMENT
3.2. Memory allocation technique
Swapping Time Example
-
Swapping is mechanisms in which a process can be swapped temporarily out of main memory (or move) to secondary storage (disk) and make that memory available to other processes. At some later time, the system swaps back the process from the secondary storage to main memory.
Though performance is usually affected by swapping process but it helps in running multiple and big processes in parallel and that's the reason Swapping is also known as a technique for memory compaction.
Memory Allocation
Main Memory Layout
-
Main memory usually has two partitions:
Low Memory -- Operating system resides in this memory.
High Memory -- User processes are held in high memory.
Type | Description |
---|---|
Single-Partition Allocation | Uses relocation + limit register to protect OS & processes. |
Multiple-Partition Allocation | Memory is split into fixed-sized partitions. Each partition holds one process. |
Fragmentation
Type | Description |
---|---|
External | Enough total memory exists, but not in a contiguous block. |
Internal | Memory block > process size, leading to unused space inside the block. |
Solutions
-
External → Use Compaction (rearrange memory)
-
Internal → Allocate best-sized block (just big enough)
Contiguous Memory Allocation
Single-Partition
-
OS in low memory, user processes in high memory
-
Use relocation and limit registers for protection
Multiple-Partition
-
Divide memory into fixed partitions
-
Each partition runs one process
-
OS maintains free/used memory table
Allocation Strategies
Strategy | Description |
---|---|
First-fit | First block that fits is allocated |
Best-fit | Smallest block that fits is allocated |
Worst-fit | Largest available block is used |
Paging
Paging is a memory management technique used by operating systems to avoid external fragmentation and efficiently manage memory.
Key Points
-
Divides memory into fixed-size blocks:
-
Pages (logical)
-
Frames (physical)
-
-
No external fragmentation
-
Internal fragmentation may occur
Address Translation
In an operating system that uses paging, every time a program accesses memory (for data or instructions), the address it uses is not the real physical address in RAM. Instead, it uses a logical address (also called a virtual address). The operating system and hardware work together to convert this into a physical address that actually points to a location in RAM.
-
Logical Address = Page Number + Offset
-
Physical Address = Frame Number + Offset
-
Uses Page Table to map pages → frames
Advantages & Disadvantages
Pros | Cons |
---|---|
No external fragmentation | Page Table takes space |
Easy swapping (equal size) | May cause internal fragmentation |
Efficient implementation | -- |
Segmentation
Key Points
-
Divides process into logical segments (e.g., code, stack, data)
-
Variable size segments (unlike fixed-size pages)
-
Segments loaded into non-contiguous memory, but each segment is contiguous
Address Format
-
Logical Address = Segment Number + Offset
-
Segment Table stores:
-
Base (starting address)
-
Length (size)
-
Paging | Segmentation |
---|---|
Fixed-size pages | Variable-size segments |
Based on memory | Based on logical divisions in a program |
Less flexible | More flexible, more natural |