Virtual Memory in Operating System.
Virtual Memory in Operating System.
INTRODUCTION
Definition
Virtual memory is a crucial memory management
strategy providing an abstract layer over physical
storage, allowing programs to act as if they have
contiguous working memory.
Function
It allows a computer to compensate for physical
memory shortages by temporarily transferring data
between RAM and disk storage.
WHY WE NEED VIRTUAL MEMORY?
2. Improving Performance
Improve computer performance by making more
efficient use of physical RAM.
Example: By paging pages to and from the disk, the
operating system optimizes the use of RAM, keeping
frequently used pages in memory.
CONTINUE…
Physical memory is the actual, tangible memory Virtual memory is a memory management technique that
hardware installed in a computer. extends the usable memory beyond the physical RAM
installed in the system.
It serves as the immediate workspace for the CPU, It creates an illusion of a larger memory space by using a
storing actively used data and programs combination of RAM and space on the hard disk.
Access to data in physical memory is fast, making it When physical memory is insufficient to hold all the data
crucial for quick retrieval and execution of instructions and programs actively in use, the operating system swaps
by the CPU. portions of data between the RAM and the disk.
HOW VIRTUAL MEMORY WORKS?
Address Translation
When a program is executed, it generates memory
addresses to access data and instructions.
These addresses are initially virtual addresses,
meaning they refer to locations in virtual memory.
Page Tables
Virtual memory is often organized into fixed-size
blocks called pages.
The page table is a data structure that maintains the
mapping between virtual pages and physical pages in
RAM.
Each entry in the page table contains information
about the corresponding page's location in physical
memory.
Page Faults
If a program tries to access data that is not currently
in RAM (a page fault), it triggers the operating
system to intervene.
HOW VIRTUAL MEMORY WORKS?
Swapping to Disk
The operating system decides which pages to keep in
RAM and which to move to disk based on factors
like usage patterns.
If a page is not in RAM, it is swapped from the disk
into an available location in RAM.
Demand Paging
Virtual memory systems often use a strategy called
demand paging, where pages are loaded into RAM
only when they are needed, not preemptively.
DIAGRAMMATICAL WORKING
ADVANTAGES OF VIRTUAL MEMORY
Definition
Demand paging is a strategy where the OS loads
pages into RAM only when they are needed,
reducing unnecessary initial loading.
Advantage
This minimizes the system's resource usage and
speeds up the overall responsiveness of the operating
system.
Example
Loading specific portions of a large application into
RAM based on user interactions.
HOW DEMAND PAGING WORKS?
2. Page Replacement
If the system doesn’t have enough free memory to
load the requested page, it must select a page to evict
from memory to make room for the requested page.
The system uses a page replacement algorithm in
order to select the page to evict.
CONTINUE…
Page Table Management
The next step is to manage the page table. The
operating system must maintain a page table for each
process, which maps virtual pages to physical pages.
The operating system must update the page table
whenever a page is loaded or evicted from memory.
Swapping
When the operating system evicts a page from
memory, it’s typically swapped to disk to make room
for other pages.
Additionally, the operating system must manage the
swapping of pages between memory and disk.
CONTINUE…