Virtual memory
Virtual memory is a memory management technique that gives the illusion of a large, continuous memory space to programs, even if the physical memory (RAM) is limited. It allows the operating system to use disk space (e.g. a swap file or page file) to extend RAM, enabling multitasking and isolation between processes.
Physical memory
Physical memory refers to the actual hardware (RAM) installed in a computer. It's where data and programs are stored temporarily while they are being used or executed.
Pages and Frames
In operating system memory management, pages and frames are fundamental concepts related to paging, a memory management scheme that eliminates the need for contiguous allocation of physical memory. Pages and Frames are different aspects of memory.
Comparison of Pages and Frames
Feature | Pages | Frames |
---|---|---|
Definition | Fixed-size blocks of a logical (virtual) address space | Fixed-size blocks of physical memory (RAM) |
Belong to | Process address space | Physical memory |
Size | Same as frame size (e.g., 4KB, 8KB) to ensure 1-to-1 mapping | Same as page size |
Purpose | Divide the virtual memory of a process into manageable units | Hold the actual data from pages loaded into physical memory |
Managed by | Memory management unit (MMU) and OS | Memory management unit (MMU) and OS |
Mapping | Pages are mapped to frames using page tables | Frames store the actual data of the pages mapped to them |
Location | Exist in virtual memory (on disk or RAM) | Reside in physical memory (RAM) |
Swapping | Pages can be swapped in and out of disk (e.g., to/from swap space) | Frames are occupied by pages when they are loaded into RAM |
Example | A process has 10 pages in its virtual address space | The OS has 1000 frames available in RAM, each of 4KB |
Comparison of MMU and Paging Tables
Aspect | Memory Management Unit (MMU) | Paging Tables (Page Tables) |
---|---|---|
Definition | Hardware component that handles memory address translation and protection. | Data structure used by OS to store mappings of virtual addresses to physical addresses. |
Role | Performs address translation (virtual → physical) at runtime using page tables. | Stores the actual mappings and metadata for each page. |
Location | Part of the CPU (hardware). | Stored in memory (RAM), managed by the OS. |
Function | Translates virtual addresses to physical addresses using page table entries. | Keeps track of virtual pages, frame numbers, valid/invalid bits, etc. |
Speed | Very fast; works in nanoseconds. | Slower access; must be read by MMU during address translation (may be cached in TLB). |
Dependency | Depends on page tables for translation. | Used by the MMU to perform translation. |
Managed by | Hardware (CPU manufacturers). | Operating System (software). |
Note
MMU = The brain that performs the translation.
Page Table = The dictionary that contains the translations.
Virtual memory = Simulated memory using disk + RAM.
Physical memory = Real, hardware-based RAM.
Swapping
- Swapping is a memory management technique where entire processes are temporarily moved between main memory (RAM) and secondary storage (disk).
- Free up RAM when it's full, by moving inactive processes to disk (called "swap space"), and bringing them back when needed.
- Whole process is swapped in or out.
Segmentation
- Segmentation divides a process's memory into logical segments, such as code, data, stack, etc.
- Allows logical organization, protection, and sharing of memory.
- Each segment is of variable size, and has its own base and limit.
Comparision of Swapping and Segmentation
Feature | Swapping | Segmentation |
---|---|---|
Definition | Moving entire processes between RAM and disk | Dividing a process into variable-sized segments |
Purpose | Manage memory when RAM is full | Allow logical division of process memory |
Unit of Transfer | Entire process | Individual segments (e.g., code, data, stack) |
Memory Division | Not divided logically — whole process is moved | Divided based on logical units of a program |
Size | Process size can vary Segment sizes | Vary based on program structure |
Addressing | Uses single linear address space per process | Each segment has its own base and limit |
Use Case | Used in memory overcommitment (swap in/out) | Used for easier protection and sharing of memory |
Overhead | High (due to entire process movement) | Moderate (due to managing multiple segments) |
Note
Swapping = Moving entire processes in/out of memory.
Segmentation = Dividing process memory into logical parts.
No comments:
Post a Comment