Q.The operating system in computer or mobile allocates memory to different applications for their execution. How does an operating system keep track of the free memory that can be allocated among programs/applications to be executed?
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The operating system maintains data structures (free lists, bitmaps, or buddy systems) that record which memory blocks are free and which are allocated, enabling efficient allocation and deallocation during program execution.
Why Memory Tracking Matters
When multiple programs run concurrently, each needs its own chunk of RAM. The operating system acts as a memory manager: it must know at every instant which portions of physical memory are occupied and which are available. Without this bookkeeping, two programs might be assigned overlapping addresses, corrupting each other's data.
The core challenge is dynamic allocation. Programs request memory at unpredictable times and release it when done. The OS must respond quickly to allocation requests, minimize wasted space (fragmentation), and reclaim freed blocks for reuse.
Common Data Structures for Free-Memory Tracking
1. Free List (Linked List of Free Blocks)
The OS maintains a linked list where each node represents a contiguous block of free memory. Each node stores:
- The starting address of the block.
- The size of the block.
- A pointer to the next free block.
When a program requests bytes, the OS scans the list using one of several strategies:
- First Fit: allocate the first block large enough.
- Best Fit: allocate the smallest block that fits (minimizes leftover space).
- Worst Fit: allocate the largest block (leaves larger fragments).
When memory is freed, the OS adds the block back to the list and coalesces adjacent free blocks to reduce fragmentation.
First Fit is fastest; Best Fit reduces external fragmentation but requires a full scan.
2. Bitmap (Bit Vector)
Memory is divided into fixed-size units (e.g., 4 KB pages). A bitmap uses one bit per unit:
- 0 = free
- 1 = allocated (or vice versa)
To allocate contiguous units, the OS scans the bitmap for consecutive zeros. Deallocation simply flips the corresponding bits back to zero.
Trade-off: Bitmaps are space-efficient for large memories but scanning for contiguous runs can be slow.
3. Buddy System
Memory is divided into blocks whose sizes are powers of two (e.g., 1 KB, 2 KB, 4 KB, …). Each size class has its own free list.
- Allocation: If a request for bytes arrives, the OS finds the smallest power-of-two block . If none exists, it splits a larger block recursively.
- Deallocation: When a block is freed, the OS checks if its "buddy" (the adjacent block from the same split) is also free. If so, they are merged back into a larger block.
This reduces external fragmentation and makes coalescing efficient, but can waste space due to internal fragmentation (a 65 KB request gets a 128 KB block).
4. Memory Allocation Table (MAT) / Partition Table
For systems using fixed partitioning, the OS maintains a table with one entry per partition:
- Partition size
- Status (free / allocated)
- Process ID (if allocated)
This is simple but inflexible; modern OSes rarely use pure fixed partitioning.
5. Page Tables (for Virtual Memory)
In systems with paging, physical memory is divided into fixed-size frames and logical memory into pages. The OS keeps:
- A page table per process (maps virtual pages to physical frames).
- A free frame list or bitmap tracking which frames are unallocated.
When a process requests memory, the OS allocates free frames and updates the page table. The Memory Management Unit (MMU) translates virtual addresses to physical addresses on the fly.
Page tables enable virtual memory: each process sees a contiguous address space, even if its pages are scattered in physical RAM or swapped to disk.
Handling Fragmentation
- External fragmentation: Free memory exists but is scattered in small, non-contiguous blocks. Solved by compaction (moving allocated blocks together) or using paging.
- Internal fragmentation: Allocated blocks are larger than requested (e.g., allocating a 4 KB page for a 100-byte request). Minimized by choosing appropriate block sizes or using segmentation.
Example: Free List in Action
Suppose physical memory is 16 KB, initially all free. The free list starts with one node: …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.