They allow a modern operating system to run multiple programs at the same time without them interfering with each other
Memory Paging
It is a memory management system that allows physical memory (RAM) to be seen as a continuous block by an application, even though in reality it is scattered in pieces all over the place
Pages and Frames: The OS divides virtual memory (the memory seen by the program) into chunks called Pages and physical memory (real RAM) into chunks called Frames. Both are typically 4 KB in size
The Page Table: This is the “map” that translates addresses. When your C code accesses address 0x1234, the hardware (MMU) looks in this table to find out which cell in physical RAM it actually corresponds to
Isolation: Each process has its own table. Therefore, Process A can write to address 0x500 and Process B can also write without conflicting, because they are pointing to completely different locations in physical RAM
Change of Context
Since you only have a limited number of CPU cores, but you want to run 50 programs at once, the kernel has to “swap” them quickly. This is called Context Switching
When the kernel decides it’s time for Process A to stop using the CPU so that Process B can take over:
- Save State: Saves all the values of the CPU registers (EAX, EBX, ESP, EIP, etc.) of Process A into a data structure in the kernel (called a PCB or Process Control Block)
- Change the “Map”: Updates the CPU pointer so that it now uses the Page Table of Process B.Suddenly, memory “changes” magically before the processor’s eyes
- Restore State: Loads the values of the registers that were saved the last time Process B was running
- Jump: The CPU resumes execution at the exact point where Process B left off
- If the video driver (Process 1) wants to communicate with the kernel, the CPU has to perform a complete context switch
- In a monolithic system, since everything is in the same “bucket” (Ring 0), you don’t need to change memory maps to go from the driver to the scheduler; you simply jump to another function
- Paging: It’s the lie that the program has all the memory to itself
- Context Switching: It’s the lie that the program has the CPU to itself