0% found this document useful (0 votes)
4 views

OS Virtual Memory

Uploaded by

Sourav Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

OS Virtual Memory

Uploaded by

Sourav Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Operating System

Topperworld.in

Virtual memory in os

Virtual Memory
✓ Virtual memory is a common technique used in a computer's operating
system (OS).
✓ Virtual memory uses both hardware and software to enable a computer
to compensate for physical memory shortages, temporarily transferring
data from Random Access Memory (RAM) to disk storage.
✓ Virtual Memory is implemented using Demand Paging.
✓ It can also be implemented using Demand Segmentation.

Here are the key concepts associated with virtual memory:

Address Spaces:
• Physical Address Space:
✓ The actual hardware memory (RAM) available in the system.
• Virtual Address Space:
✓ The logical address space visible to processes.
✓ It can be larger than the physical address space.
Pages:
• Page Size:
✓ Virtual memory is divided into fixed-size blocks called pages.
✓ Similarly, physical memory is divided into page frames of the same
size.
• Page Table:
✓ A data structure that maps virtual pages to physical page frames.
✓ The operating system uses the page table to translate virtual
addresses to physical addresses.

©Topperworl d
Operating System

Page Faults:
• Page Fault:
✓ Occurs when a program accesses a page that is not currently in
physical memory.
• Page Replacement:
✓ If physical memory is full, the operating system must decide which
pages to keep in RAM and which to move to disk.
Demand Paging:
• Lazy Loading:
✓ Only loads pages into physical memory when they are needed,
reducing the initial loading time of programs.
• Copy-On-Write:
✓ Allows multiple processes to share the same physical pages until one
of them modifies the content, triggering a copy of the page to a new
location.
Swapping:
• Swapping Out:
✓ Moving an entire process or part of it from RAM to disk to free up
space.
• Swapping In:
✓ Bringing a process or part of it back into RAM when it is needed.
Memory-Mapped Files:
• File Mapping:
✓ Allows a part of a file to be directly mapped into the virtual memory,
enabling I/O operations to be treated as ordinary memory access.

Benefits of Virtual Memory:


➢ Increased Address Space: Programs can use more memory than
physically available.
➢ Isolation: Processes are isolated from each other and from the
operating system.
➢ Ease of Management: Simplifies memory management and allows for
more efficient use of resources.
➢ Combination Approach: Some systems use a combination of paging
and segmentation to manage virtual memory efficiently.

©Topperworl d
Operating System

➢ Thrashing: Excessive paging activity that occurs when the system is


spending more time swapping pages than executing actual instructions.
➢ LRU (Least Recently Used): Replaces the page that has not been used
for the longest time.
➢ FIFO (First-In-First-Out): Replaces the oldest page in memory.
➢ Optimal: Replaces the page that will not be used for the longest time in
the future (theoretical optimum).

Advantages
✓ Virtual Memory allows you to run more applications at a time.
✓ With the help of virtual memory, you can easily fit many large
programs into smaller programs.
✓ With the help of Virtual memory, a multiprogramming environment
can be easily implemented.
✓ Data should be read from disk at the time when required.
✓ Common data can be shared easily between memory.
✓ The process may even become larger than all of the physical
memory.
Disadvantages
✓ Virtual memory reduces the stability of the system.
✓ The performance of Virtual memory is not as good as that of RAM.
✓ If a system is using virtual memory then applications may run slower.
✓ Virtual memory negatively affects the overall performance of a
system.
Demand Paging
• CPU generates a logical address which is converted to a physical address
by MMU (Memory Management Unit).
• When a page referenced by CPU is not found in the main memory, this
is called Page Fault.
• Demand Paging is a process of copying a page from the disk into the
main memory whenever required or when a Page Fault occurs.
This is done by the Operating System through the following steps:

©Topperworl d
Operating System

• When a CPU references to a Page that is not present in the main


memory, a Page Fault occurs.
• To execute the process, the Operating System needs to bring the
reference page in the main memory.
• The Operating System then searches for the required page in the Disk
Storage. It is a very slow process.
• Then it stores the page in one of the vacant frames of the main memory.
• Then Page table is updated according to that frame number for future
references.
• Then the CPU executes the program again.
Working :

▪ Let’s say the CPU wants to access a page for a specific process.
▪ The first step is to look for the required page in the page table.
▪ Suppose we find the required page in the page table.
▪ Therefore, the CPU access the page and forwards it to the process.
▪ However, if we can’t find the target page, the page table generates a
trap or page fault signal.
▪ Furthermore, the page table sends the signal to the operating system.
▪ This’s where we apply the demand paging technique.
▪ The demand paging technique involves six steps:

©Topperworl d
Operating System

• The first step is to handle the page faults.


• 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.
• Hence, the operating system must handle this page fault and load the
required page from secondary storage into memory.
Advantages

✓ Large virtual memory.


✓ More efficient use of memory.
✓ There is no limit on degree of multiprogramming.
Disadvantages

✓ Number of tables and the amount of processor overhead for


handling page interrupts are greater than in the case of the simple
paged management techniques.

©Topperworl d

You might also like