Virtual Memory in Operating System - GeeksforGeeks
Virtual Memory in Operating System - GeeksforGeeks
The size of virtual storage is limited by the addressing scheme of the computer system
and the amount of secondary memory available not by the actual number of main
storage locations.
If these characteristics are present then, it is not necessary that all the pages or
segments are present in the main memory during execution. This means that the
required pages need to be loaded into memory whenever required. Virtual memory is
implemented using Demand Paging or Demand Segmentation.
Demand Paging
The process of loading the page into memory on demand (whenever a page fault
occurs) is known as demand paging. The process includes the following steps are as
follows:
Demand Paging
1. If the CPU tries to refer to a page that is currently not available in the main memory,
it generates an interrupt indicating a memory access fault.
2. The OS puts the interrupted process in a blocking state. For the execution to
proceed the OS must bring the required page into the memory.
3. The OS will search for the required page in the logical address space.
4. The required page will be brought from logical address space to physical address
space. The page replacement algorithms are used for the decision-making of
replacing the page in physical address space.
5. The page table will be updated accordingly.
6. The signal will be sent to the CPU to continue the program execution and it will
place the process back into the ready state.
Hence whenever a page fault occurs these steps are followed by the operating system
and the required page is brought into memory.
Page Fault Service Time: The time taken to service the page fault is called page fault
service time. The page fault service time includes the time taken to perform all the
above six steps.
Swapping
Swapping is a process out means removing all of its pages from memory, or marking
them so that they will be removed by the normal page replacement process.
Suspending a process ensures that it is not runnable while it is swapped out. At some
later time, the system swaps back the process from the secondary storage to the main
memory. When a process is busy swapping pages in and out then this situation is
called thrashing.
Swappinghierar
Thrashing
At any given time, only a few pages of any process are in the main memory, and
therefore more processes can be maintained in memory. Furthermore, time is saved
because unused pages are not swapped in and out of memory. However, the OS must
be clever about how it manages this scheme. In the steady state practically, all of the
main memory will be occupied with process pages, so that the processor and OS have
direct access to as many processes as possible. Thus when the OS brings one page in,
it must throw another out. If it throws out a page just before it is used, then it will just
have to get that page again almost immediately. Too much of this leads to a condition
called Thrashing. The system spends most of its time swapping pages rather than
executing instructions. So a good page replacement algorithm is required.
Causes of Thrashing
For example:
Let free frames = 400
Case 1: Number of processes = 100
Then, each process will get 4 frames.
2. Lacks of Frames: If a process has fewer frames then fewer pages of that process
will be able to reside in memory and hence more frequent swapping in and out will be
required. This may lead to thrashing. Hence a sufficient amount of frames must be
allocated to each process in order to prevent thrashing.
Recovery of Thrashing
Do not allow the system to go into thrashing by instructing the long-term scheduler
not to bring the processes into memory after the threshold.
If the system is already thrashing then instruct the mid-term scheduler to suspend
some of the processes so that we can recover the system from thrashing.
Frame Allocation
A number of frames allocated to each process in either static or dynamic.
Paging Policies
Fetch Policy: It decides when a page should be loaded into memory.
Replacement Policy: It decides which page in memory should be replaced.
Placement Policy: It decides where in memory should a page be loaded.
Answer:
Virtual memory works by dividing the virtual address space used by a program
into smaller units called pages. The operating system manages a mapping
between virtual addresses used by the program and physical addresses in the
actual RAM or disk. When a program accesses a virtual address that is not
currently in physical memory, a page fault occurs. The operating system then
retrieves the required page from disk and brings it into RAM, evicting other pages
if necessary.
Answer:
Answer:
A page fault occurs when a program references a virtual memory page that is not
currently resident in physical memory. This happens when the required page has
been paged out to disk or has not been accessed yet. When a page fault occurs,
the operating system handles it by fetching the required page from disk and
updating the page tables to reflect the new mapping.
Suggest improvement
Previous Next
Similar Reads
Difference between Virtual memory and Operating System - Difference Between
Cache memory Distributed System and Parallel System
GeeksforGeeks
Company Explore
About Us Hack-A-Thons
Contact Us Master CP
Languages DSA
Java Algorithms
Tutorials Archive
Django Tutorial
GCP Top 50 DP
OOAD NodeJS
Puzzles Biology
English Grammar
World GK
SAP C++
Linux CS Subjects
Excel