Nothing Special   »   [go: up one dir, main page]

Virtual Memory in Operating System.

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

VIRTUAL MEMORY IN OS

PRESENTED BY: SOMAN AHMAD


ABDUL AZIZ
DIGITAL COMMUNICATIONS

WHAT IS VIRTUAL MEMORY?

WHY NEED VIRTUAL MEMORY?

HOW VIRTUAL MEMORY WORKS?

ADVATAGES/DISADVANTAGES OF VIRTUAL MEMORY?

WHAT IS DEMAND PAGING IN OS?

BENEFITS OF DEMAND PAGING?


VIRTUAL MEMORY

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?

1. Running Larger Programs


 Virtual memory allows running larger programs than
the available physical RAM.
Example: Running resource-intensive applications that
exceed the constraints of physical 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…

3. Concurrent Program Execution


 Virtual memory enables the concurrent execution of
multiple programs.
Example: Suppose you have a computer with 4 GB of
physical RAM.
 Program A: Requires 2 GB of RAM.
 Program B: Requires 1.5 GB of RAM.
 Program C: Requires 1 GB of RAM.
With virtual memory, the operating system can use a
combination of RAM and disk space to create the
illusion that each program has its dedicated space in
memory.
CONTINUE…

4. Flexible Memory Management


 Virtual memory provides a more flexible memory
management scheme.
Example: Consider a computer with 2 GB of RAM. If
there are three programs each requiring 1 GB, virtual
memory allows the OS to swap portions of these
programs between RAM and disk, enabling all three
programs to run concurrently.
PHYSICAL VS VIRTUAL MEMORY

Physical Memory Virtual Memory

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.

Mapping to Physical Memory:


 The Memory Management Unit (MMU), a hardware
component, translates virtual addresses to physical
addresses.
 The MMU uses data structures, such as page tables,
to map virtual addresses to corresponding physical
addresses in RAM.
HOW VIRTUAL MEMORY WORKS?

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

Concurrency Data Sharing


 Enables the concurrent execution of multiple  Common data can be shared between RAM and
applications or programs. virtual memory.

Dynamic Size Improved CPU Utilization


 Users can adjust the size of virtual memory,  Enhances CPU utilization by accommodating more
providing flexibility. processes in main memory.

Large Program Execution Cost Savings


 Allows running programs larger than the available  Saves costs by avoiding the need to purchase
main memory. additional physical RAM.
DISADVANTAGES OF VIRTUAL MEMORY

Performance Impact: Overall System Performance:


 Slows down the computer as hard drive speed is  May impact the overall performance of the system
slower than RAM. negatively.

Application Switching Delay:


 Switching between applications takes more time due
to swapping.

Hard Drive Space Usage:


 Allocates space on the hard drive, reducing available
user space.
DEMAND PAGING

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?

1. Page Fault Handling


 A page fault is generated when a process attempts to
access a memory address or a page that isn’t
currently available on the main memory.

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…

Demand Paging Algorithms


 Demand paging requires complex algorithms and
data structures to manage memory efficiently and
ensure that processes have the memory resources
they need to execute.
ADVANTAGES OF DEMAND PAGING

On-Demand Loading Cost Efficiency


 Loads only the pages demanded by the executing  Helps reduce the bill of material (BOM) cost,
process, conserving memory resources. especially in devices like smartphones where main
memory is expensive compared to secondary storage.
Increased Process Concurrent Execution:  Enables cost savings in hardware resources.
 More processes can be loaded into main memory
simultaneously, reducing context switching time.

Reduced Loading Latency


 Decreases loading latency during program startup as
less information is accessed from secondary storage.
DISADVANTAGES OF DEMAND PAGING

Initial Program Delay Security Risks


 Initial access to pages not in memory may cause  Potential security risks, including vulnerability to
delays. timing attacks.
 Requires careful consideration of security
Low-Cost Embedded Systems implications, especially in sensitive applications.
 Low-cost, low-power embedded systems may lack a
memory management unit supporting page
replacement. Thrashing
 There is a risk of thrashing, where repeated page
Complexity in Memory Management
faults occur excessively, impacting overall system
 Memory management, particularly with page
performance.
replacement algorithms, becomes more complex.

You might also like