CHapter-05 Operating System
CHapter-05 Operating System
Operating system
Memory Management
Memory Management:
The function of the operating system that handles or manages primary
memory.
Keeps track of each byte in memory.
Allocates memory to processes when needed and deallocates when
done.
Compaction: -
Compaction is the solution for memory wastage occurred in dynamic
partitioning. The operating system observes the number of holes in the
memory and compacts them after a period so that a contiguous memory can
be allocated for a new process.
🧰 Hardware Requirement
To support paging, a special register called the Page Table Base Register
(PTBR) stores the address of the page table.
When a process starts, the PTBR is loaded with that process's page table
address.
When the process ends or is switched, PTBR is updated for the new
process.
❌ Invalid Pages
Sometimes, a process doesn’t use all its pages.
To prevent the use of these unused or illegal pages, a valid-invalid bit is
added in the page table:
o Valid → page is in use
o Invalid → page is not in use; access is not allowed
💡 Example:
A compiler needs 1500 KB of memory.
If two users run it separately, it would normally use 3000 KB (1500 × 2).
With shared pages, both users use the same code pages, so only 1500
KB is used.
The page tables of both users point to the same code in memory.
❗ The Problem:
If page size = 4 KB, and each page table entry = 4 bytes
Then a 32-bit address space needs 1 million entries
Total memory for one page table = 4 MB
Keeping such a large page table in one block (contiguous space) is hard
🔁 How it works:
1. Logical address is divided into 3 parts:
o p1: Index for outer page table
o p2: Index for inner page table
o d: Offset inside the page
2. First, p1 is used to find the correct inner page table
3. Then p2 finds the correct page frame
4. Offset d gives the exact memory location inside the page