OS Presentation 2023

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

Virtual Memory

SHAYAN ALI CSC-21S-129


MUHAMMAD FURQAN CSC-21S-
082
ARSAL AZHAR CSC-21S-019
What is Virtual Memory?
• Virtual memory is a computer memory management technique that allows an operating system
to use a combination of physical RAM (Random Access Memory) and secondary storage, such
as a hard disk drive, to effectively increase the amount of usable memory available to programs.

What is the importance of Virtual Memory?

• Virtual memory expands the effective memory capacity of a computer system beyond its
physical limits.
• It facilitates memory sharing, swapping, and paging, optimizing memory usage and improving
overall system performance. It enables multitasking and efficient memory allocation for
running multiple programs simultaneously.
Why Do We Need Virtual Memory ?
• Increased Addressable Memory:

1. Virtual memory allows a computer system to access more memory than what is physically
available.
2. This allows programs to utilize more memory than the available physical RAM, enabling them to
run larger and more complex tasks.

• Memory Isolation and Protection:

1. Virtual memory facilitates memory isolation between different processes running on a computer.
2. This isolation prevents one process from accessing or modifying another process's memory,
enhancing security and stability.
• Efficient Memory Management:

1. Virtual memory enables efficient memory management by utilizing techniques like demand paging
and page swapping.
2. Demand paging loads only the necessary portions of a program into physical memory, allowing
for efficient memory usage.
3. Page swapping moves infrequently used pages of memory between RAM and disk storage, freeing
up physical memory for other tasks.

• Simplified Program Development:

1. Virtual memory simplifies program development by providing a uniform and consistent memory
model for applications.
2. Programmers can develop applications using a flat, contiguous address space, independent of
physical memory limitations.
What is Demand Paging in
Virtual Memory ?

• Demand paging is a virtual memory management technique where pages are loaded into
memory only when they are explicitly requested by processes.

• Instead of loading the entire program into memory at once, only the required pages are
brought into memory as needed.

• When a process references a page that is not in physical memory, a page fault occurs, and
the operating system brings the required page from disk into memory.

• Demand paging allows for efficient memory utilization by loading pages on-demand,
reducing the initial memory footprint of processes.
Benefits of demand Paging in
Virtual Memory
1. Reduced Memory Footprint:
Demand paging reduces the amount of physical memory required to run processes
by loading only necessary pages.

2. Faster Process Startup Time:


Since demand paging loads only essential pages initially, the process startup time is
reduced as it doesn't have to load the entire program into memory.

3. Efficient Memory Sharing:


Multiple processes can share the same page in memory, which reduces memory
duplication and allows for better resource utilization.

4. Improved Overall System Performance:


Demand paging helps to avoid unnecessary I/O operations by loading pages only
when they are needed.
Copy-on-Write in Virtual Memory
• Definition:
Copy-on-write (COW) is a memory management technique used in virtual memory systems to
optimize memory usage and improve efficiency. It is particularly relevant in scenarios where multiple
processes or threads share the same memory resources.

How is Memory Shared with Copy-on-Write ?


When COW is implemented, the operating system initially maps the virtual pages of two or more processes to
the same physical memory page. In this scenario, the processes share the same underlying memory content.
However, if any process attempts to modify the shared memory page, the operating system triggers a copy
operation.
Benefits of Copy-on-Write
• Memory Efficiency:
COW reduces memory consumption by deferring the creation of separate copies until necessary. This
is especially advantageous when processes primarily read from shared memory.

• Performance Improvement:
Copying memory can be a costly operation, particularly when dealing with large memory pages. By
postponing the copy until modifications occur, COW minimizes the overhead associated with copying.

• Simplified Memory Sharing:


COW allows multiple processes to easily share memory without the need for explicit coordination
or synchronization mechanisms.
Usage in Operating Systems and Virtualization Tech.

• Copy-on-write is widely used in various operating systems and virtualization technologies to


optimize memory utilization and enhance system performance in scenarios involving shared
memory. It is a fundamental technique for managing memory efficiently and improving
overall system scalability.
Examples of Copy-on-Write Usage

• Copy-on-Write is widely used in operating systems, such as Unix/Linux, to optimize process


creation and memory management.
• Forking a process in Unix/Linux typically employs Copy-on-Write to save memory and
improve performance.
Page Replacement in Virtual Memory

Definition:
Page replacement is a crucial aspect of virtual memory management, where the operating system dynamically
moves pages between physical memory and secondary storage (such as a hard disk or SSD) to efficiently
utilize limited physical memory resources. When the physical memory becomes full and a new page needs to
be brought in, the operating system selects a victim page to be replaced with the new page. This process is
known as page replacement.
Page Replacement Algorithm
When a page fault occurs the operating system needs to select a page to replace from physical
memory to make room for the required page. This selection is done using a page replacement
algorithm.

There are Four Types of Algorithms using in Page Replacement.

1. FIFO (First-In-First-Out):
The page that has been in memory the longest is selected for replacement.
2. LRU (Least Recently Used):
This algorithm replaces the page that has not been used for the longest time.
3. LFU (Least Frequently Used):
This Algorithm replaces the page that has been accessed the fewest number of times
4. Optimal:
It replaces the page that will not be used for the longest time in furture.
ALLOCATION
Definition:
OF FRAMES The allocation of frames in virtual memory refers to the
assignment of physical memory (RAM) frames to the

IN pages of a process's virtual address space. The operating


system manages this allocation to enable efficient
memory utilization and provide each process with the
VIRTUAL necessary memory resources.

MEMORY
Memory Allocation Policies and Consideration.

• Memory Management Unit (MMU):


The MMU is responsible for translating virtual addresses to physical addresses using the page table.
• Page Replacement Algorithms:
The choice of a page replacement algorithm affects frame allocation indirectly. The algorithm
determines which pages are evicted from memory when a new page needs to be allocated. By selecting
appropriate victim frames, the system can optimize memory utilization and overall performance.
Page Table Entries and Frame Allocation
The mapping between virtual pages and physical frames is maintained in the process's page table. Each entry in the
page table represents a virtual page and stores the corresponding physical frame number.

The allocation can be done using following 3 strategies.

1. Contiguous Allocation:
2. Non-Contiguous Allocation
3. Segmentation

You might also like