0% found this document useful (0 votes)
26 views16 pages

Virtual Memory and Demanding Pages

The document discusses virtual memory and demand paging. Virtual memory allows programs to access more memory than physically installed by using disk as auxiliary memory. Demand paging loads pages into memory on demand when they are accessed for the first time.

Uploaded by

poojadorey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views16 pages

Virtual Memory and Demanding Pages

The document discusses virtual memory and demand paging. Virtual memory allows programs to access more memory than physically installed by using disk as auxiliary memory. Demand paging loads pages into memory on demand when they are accessed for the first time.

Uploaded by

poojadorey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

VIRTUAL MEMORY AND

DEMANDING PAGES
Group Members

1. Anjali Bhagwate
2. Akash Patil
3. Pooja Bhalekar
4. Vaibhav Baravkar
VIRTUAL MEMORY
• The term virtual memory refers to something which appears to be present but actually it is
not.
• Virtual Memory allows users to use more memory for a program than the real memory of a
computer.
• So, Virtual memory is the concept that gives the illusion to the programmer that a process
whose size is larger than the size of Main memory can also be executed.
• Virtual memory is an imaginary memory area supported by some operating systems in
conjunction with the hardware.
• A computer can address more memory than the amount physically installed on the system.
This extra memory is actually called virtual memory.
• The main advantage virtual memory concept is that programs can be larger than physical
memory. Virtual memory serves two purposes. First, it allows us to extend the use of
physical memory by using disk. Second, it allows us to have memory protection, because
each virtual address is translated to a physical address.
PURPOSE OF VIRTUAL MEMORY
There is conceptual separation of user logical memory from physical memory. Thus we can have
large virtual memory on a small physical memory. The purpose of virtual memory is to enlarge the
address space, i.e. the set of addresses a program can utilize.
For example, virtual memory might contain twice as many addresses as main memory. A program
using all of virtual memory addresses therefore would not be able to fit in main memory all at once.
The computer could not execute such a program by copying into main memory, those portions of the
program which is needed at any given point of time during execution.
To facilitate copying virtual memory into real memory, the operating system divides virtual memory
into pages, each of which contains a fixed number of addresses. Each page is stored on a disk until it
is needed. When the page is needed, the operating system copies it from disk to main memory,
translating the virtual addresses into real addresses.
MAPPING
• The process of translating virtual addresses(addresses generated by CPU) into real addresses is called
Mapping. The copying of virtual pages from disk to main memory is known as paging or swapping.

• All modern general-purpose computer operating systems use virtual memory techniques for ordinary
applications, such as word processors, spreadsheets, multimedia players, accounting, etc.

• Older operating systems, such as DOS and Microsoft Windows of the 1980s, or those for the
mainframes of the 1960s, generally had no virtual memory functionality - but being the Atlas, B5000
and Apple Computer's Lisa are exceptions.
USE OF VIRTUAL MEMORY

• Virtual memory is used to simulate a larger memory space than physically exists in a
computer system, allowing for efficient and flexible management of memory resources.
Here's how virtual memory is used in practice:
1. Memory Management : Virtual memory helps the operating system manage memory
efficiently by breaking it into smaller units, typically called "pages.“
2. Paging : Virtual memory uses a process called "paging" to manage the movement of data
between physical memory and disk.
3. Address Space Isolation : Virtual memory creates a separate address space for each
process.
4. Memory Mapping : Virtual memory supports memory mapping, where a file on disk is
mapped into the address space of a process.
5. Working Set Management : The operating system maintains a "working set" for each
process, representing the set of pages currently in use.
WHAT IS DEMAND PAGING ?

• It is a common technique used to implement the virtual memory. In this technique , a page is
brought into the main memory for its execution only when it is needed.
• Combination of swapping and paging.
• Instead of swapping the entire process into main memory , the pages or the lazy swapper is
used
• A lazy swapper brings only the necessary pages into the memory
• It suggests keeping all pages of the frames in the secondary memory until they are required.
In other words, it says that do not load any page in the main memory until it is required.
• Whenever any page is referred for the first time in the main memory, then that page will be
found in the secondary memory.
WORKING OF DEMAND PAGING
• Suppose we want to run a process P which have four pages P0, P1, P2, and P3. Currently, in
the page table, we have pages P1 and P3.
Therefore, the operating system‘s demand paging mechanism follows a few steps in its
operation :
• Program Execution: Upon launching a program, the operating system allocates a certain
amount of memory to the program and establishes a process for it.
• Creating page tables: To keep track of which program pages are currently in memory and
which are on disk, the operating system makes page tables for each process.
• Handling Page Fault: When a program tries to access a page that isn’t in memory at the
moment, a page fault happens. In order to determine whether the necessary page is on disk,
the operating system pauses the application and consults the page tables.
• Page Fetch: The operating system loads the necessary page into memory by retrieving it
from the disk if it is there.
• The page’s new location in memory is then reflected in the page table.
• Resuming the program: The operating system picks up where it left off when the necessary
pages are loaded into memory.

• Page replacement: If there is not enough free memory to hold all the pages a program
needs, the operating system may need to replace one or more pages currently in memory
with pages currently in memory. on the disk. The page replacement algorithm used by the
operating system determines which pages are selected for replacement.

• Page cleanup: When a process terminates, the operating system frees the memory allocated
to the process and cleans up the corresponding entries in the page tables.
ADVANTAGES
• Faster program start :
Because only part of a program is initially loaded into memory, programs can start faster than
if the entire program were loaded at once.

• Efficient use of physical memory :


paging allows for more efficient use because only the necessary pages are loaded into memory
at any given time.

• Reduce memory usage :


Query paging can help reduce the amount of memory a program needs, which can improve
system performance by reducing the amount of disk I/O required.
VALID AND INVALID BITS

• The valid-invalid bit in an operating system is associated with each page table entry, indicating
whether the page is in memory (valid) or not (invalid) .

• Initially valid-invalid bit is set to I on all entries.

• But for the pages that are not currently in the memory, the page table is either simply marked
as invalid or it contains the address of the page on the disk.
The above figure is to indicates the page table when some pages are not in the main memory
ADVANTAGES
• Efficient Memory Usage : Valid and invalid bits help in efficient memory usage by
indicating whether a particular data entry or cache line contains valid information or not.
This allows systems to avoid accessing or updating stale or irrelevant data.

• Improved Performance : By quickly determining the validity of data, processors can avoid
unnecessary accesses to memory or cache, leading to faster data retrieval and processing.
This can significantly enhance system performance, especially in time-critical applications.

• Cache Coherency : In multi-core or multi-processor systems, valid and invalid bits play a
crucial role in maintaining cache coherency. They help in ensuring that all cores or
processors have consistent views of shared data, reducing the risk of data corruption or
inconsistencies.
DISADVANTAGES
• Overhead : Adding valid and invalid bits to data structures or cache lines increases their
overhead in terms of memory usage and processing complexity. While these bits are essential for
efficient operation, they consume additional memory and may require extra processing cycles for
their management.

• Complexity : Managing valid and invalid bits adds complexity to the design and implementation
of systems, especially in large-scale or distributed environments. Developers need to ensure
proper synchronization and consistency to prevent issues such as data corruption or race
conditions.

• Potential for Bugs : Introducing valid and invalid bits introduces the possibility of bugs related
to their management. Incorrect handling of these bits can lead to data corruption, inconsistencies,
or performance degradation. Thorough testing and validation are required to ensure correct
operation.

You might also like