Virtual Storage:
Virtual storage in operating systems refers to a memory management
technique that creates an illusion of a larger memory space than is physically
available
Types of Virtual Memory
In a computer, virtual memory is managed by the Memory Management Unit
(MMU), which is often built into the CPU. The CPU generates virtual addresses
that the MMU translates into physical addresses.
There are two main types of virtual memory:
Paging
Segmentation
Paging
Paging divides memory into small fixed-size blocks called pages.
When the computer runs out of RAM, pages that aren't currently in use are
moved to the hard drive, into an area called a swap file.
The swap file acts as an extension of RAM.
When a page is needed again, it is swapped back into RAM, a process
known as page swapping.
This ensures that the operating system (OS) and applications have enough
memory to run.
Demand Paging: The process of loading the page into memory on demand
(whenever a page fault occurs) is known as demand paging. The process includes
the following steps are as follows:
Page and Frame
A page is a fixed size block of data in virtual memory and a frame is a fixed size
block of physical memory in RAM where these pages are loaded.
Think of a page as a piece of a puzzle (virtual memory) While, a frame as the
spot where it fits on the board (physical memory).
When a program runs its pages are mapped to available frames so the program
can run even if the program size is larger than physical memory.
Segmentation
Segmentation divides virtual memory into segments of different sizes.
Segments that aren't currently needed can be moved to the hard drive. The
system uses a segment table to keep track of each segment's status,
including whether it's in memory, if it's been modified, and its physical
address.
Segments are mapped into a process's address space only when needed.
Another method of dividing memory, but using variable-size blocks called
"segments". Segments are swapped between RAM and disk.
Segmentation offers a more programmer-friendly view of memory and can
help reduce internal fragmentation, but it may lead to external fragmentation.
Benefits of Virtual Storage:
Increased Multiprogramming:
More processes can be loaded into memory at the same time, improving system efficiency.
Larger Programs:
Allows execution of programs larger than the available physical memory.
Efficient Memory Usage:
Only the necessary parts of a program need to be in memory at any given time.
Protection:
Each process has its own virtual address space, preventing one process from interfering
with another.
Flexibility and Scalability:
Virtual storage allows for dynamic allocation and deallocation of memory resources,
adapting to changing needs.