is a game-changer in computer architecture. It lets your computer run more apps than it has physical memory for by swapping data between RAM and disk. This clever trick gives each process its own space, keeping things safe and efficient.
and are two ways to make virtual memory work. Paging splits memory into fixed-size chunks, while segmentation uses variable-sized logical units. Both help manage memory, but paging is more common in modern systems due to its simplicity.
Virtual Memory: Concept and Role
Memory Management Technique
Top images from around the web for Memory Management Technique
Understanding Virtual Address, Virtual Memory and Paging - Stack Overflow View original
Virtual memory is a memory management technique that allows a computer to compensate for shortages of physical memory by temporarily transferring data from RAM to disk storage
Enables a computer to run more applications and processes simultaneously, even if the total memory requirements exceed the available physical RAM
The operating system manages virtual memory by creating a virtual address space for each process, which is divided into fixed-size pages or variable-size segments
The is responsible for translating virtual addresses to physical addresses and handling page faults when required data is not found in physical memory
Benefits and Advantages
Allows running multiple applications concurrently, even when their combined memory requirements surpass the physical RAM capacity
Provides each process with its own isolated virtual address space, preventing unauthorized access between processes
Enables efficient utilization of available physical memory by allocating and deallocating pages or segments as needed
Supports memory protection and access control mechanisms, enhancing system stability and security
Address Translation and Page Tables
Address Translation Process
Address translation is the process of converting a virtual address used by a program into a corresponding in RAM
In a paging system, the virtual address space is divided into fixed-size pages, and the physical memory is divided into frames of the same size
The MMU uses the page number from the virtual address as an index into the to find the corresponding physical number
If the required page is not found in physical memory (a page fault occurs), the operating system intervenes to load the page from disk into an available frame and updates the page table accordingly
Page Table Structure and Usage
Page tables are used to map virtual page numbers to physical frame numbers, enabling the MMU to perform address translation
The page table contains entries for each virtual page, including the corresponding physical frame number and additional information such as valid/invalid bits and access permissions
The operating system maintains and updates the page table to reflect the current mapping between virtual and physical memory
Page table entries may also include additional flags or bits to indicate page status, such as dirty (modified) or referenced (recently accessed) bits
Paging vs Segmentation
Paging Characteristics
Paging divides the virtual address space into fixed-size pages and the physical memory into frames of the same size
Simplifies memory management by using a single page table and fixed-size pages, making it easier to allocate and deallocate memory
Can suffer from when a process does not fully utilize its allocated pages, wasting memory space
Widely used in modern operating systems due to its simplicity and hardware support (x86, ARM)
Segmentation Characteristics
Segmentation divides the virtual address space into variable-size segments based on logical units such as functions or data structures
Allows for better memory utilization by allocating memory based on the actual size of logical units, reducing internal fragmentation
Requires more complex memory management, as each segment needs its own base address and limit, and the operating system must manage multiple segment tables
Provides a more natural and flexible way to organize and protect memory based on logical program structure (code, data, stack segments)
Less commonly used in modern operating systems compared to paging
Virtual Memory Performance: Page Faults and Thrashing
Page Fault Handling
Page faults occur when a required page is not found in physical memory, causing the operating system to load the page from disk, which is a slow operation compared to accessing RAM
The operating system handles page faults by locating the required page on disk, loading it into an available physical frame, updating the page table, and resuming the interrupted process
Frequent page faults can significantly degrade system performance, as the CPU must wait for the required data to be loaded from disk
Techniques such as prefetching, caching, and optimizing page replacement algorithms can help reduce the impact of page faults
Thrashing and Mitigation Strategies
occurs when a system spends more time swapping pages in and out of memory than executing useful work, leading to severe performance degradation
Happens when the total working set of all processes exceeds the available physical memory, causing constant page faults and disk I/O
To mitigate thrashing, operating systems employ techniques such as:
Working set management: Monitoring and adjusting the set of pages a process actively uses
Page replacement algorithms: Selecting which pages to evict from memory when a page fault occurs (LRU, LFU, Clock)
Memory ballooning: Dynamically adjusting the memory allocation of virtual machines in a hypervisor environment
Proper sizing of physical memory and optimizing application memory usage can help reduce the occurrence of page faults and thrashing