Learning outcomes
- Explain variable partitioning and the issues of external fragmentation.
These notes explain three important memory-management concepts in Operating Systems: multiprogramming with variable partitions, memory protection schemes, and paging. The aim is to understand how memory is allocated, protected, and translated efficiently in a multiprogrammed system.
In a multiprogramming system, several processes are kept in main memory at the same time so that the CPU always has work to do. In variable partition allocation, memory is divided dynamically according to the actual size required by each process. Unlike fixed partitions, the operating system does not define partition sizes in advance.
| Strategy | Idea | Advantage | Drawback |
|---|---|---|---|
| First Fit | Allocate the first hole that is large enough. | Fast and simple. | May leave many small holes near the beginning of memory. |
| Best Fit | Allocate the smallest hole that is still large enough. | Tries to reduce leftover waste in one allocation. | Usually requires more searching and may create many tiny unusable holes. |
| Worst Fit | Allocate the largest available hole. | Leaves a relatively large remaining hole. | Often performs poorly overall. |
The major problem of variable partition allocation is external fragmentation. Total free memory may be sufficient, but it may be split into many small noncontiguous holes. As a result, a process still cannot be loaded.
| Type of Fragmentation | Meaning | Common in Variable Partitions? |
|---|---|---|
| External Fragmentation | Free memory exists, but it is scattered into small pieces. | Yes, this is the main problem. |
| Internal Fragmentation | Unused memory exists inside an allocated block. | Usually much less important here than external fragmentation. |
Compaction is a technique used to reduce external fragmentation. The OS moves processes so that all free memory is combined into one large block. This makes allocation easier, but compaction is expensive because moving processes in memory takes time and requires relocation support.
Suppose free holes are 40 KB, 15 KB, 70 KB, 25 KB and a new process needs 20 KB.
Which one is best depends on future requests, so there is no magic wand here.
Memory protection prevents one process from reading or writing another process’s memory and also prevents user programs from damaging the operating system area. Without protection, one faulty program can corrupt the whole system.
In contiguous memory allocation, a simple and effective protection mechanism uses two hardware registers:
Paging supports protection more flexibly because each page-table entry can contain control bits.
| Protection Item | Purpose |
|---|---|
| Valid / Invalid Bit | Shows whether the page belongs to the logical address space of the process. |
| Read / Write / Execute Bits | Control permitted operations on a page. |
| Trap on Violation | If a process performs an illegal access, the hardware transfers control to the OS. |
Paging is a noncontiguous memory-allocation technique that divides a process’s logical memory into fixed-size pages and physical memory into fixed-size frames. A page can be placed in any free frame.
| Term | Meaning |
|---|---|
| Page | A fixed-size block of logical memory. |
| Frame | A fixed-size block of physical memory. |
| Page Table | A table that maps page numbers to frame numbers. |
| Offset | The displacement within a page or frame. |
If the page size is 2n bytes, then a logical address is divided into:
Given: Page size = 1024 bytes
Logical address: 2050
Page number = 2050 / 1024 = 2
Offset = 2050 mod 1024 = 2
If the page table says Page 2 → Frame 7, then:
A TLB is a small, fast associative memory that stores recently used page-table entries. Without a TLB, every memory reference may require an extra access to the page table. With a TLB hit, translation becomes much faster.
| Basis | Variable Partitions | Paging |
|---|---|---|
| Allocation style | Contiguous | Noncontiguous |
| Size of blocks | Variable | Fixed-size pages and frames |
| Main issue | External fragmentation | Internal fragmentation |
| Protection method | Base/relocation + limit register | Valid-invalid bit and protection bits |
| Need for compaction | Often yes | No, not for external fragmentation |
| Page table needed | No | Yes |
Multiprogramming with Variable Partitions: Memory is allocated dynamically in variable-size contiguous blocks. It is flexible but suffers from external fragmentation.
Protection Schemes: Protection ensures one process cannot damage another or the OS. Base-limit registers are used in contiguous allocation; protection bits are used in paging.
Paging: Logical memory is divided into pages and physical memory into frames. It removes external fragmentation and supports virtual memory, but adds page-table and translation overhead.