Download presentation
Presentation is loading. Please wait.
1
Day 20 Virtual Memory
2
Assumptions An entire process resides in main memory.
A process resides in main memory as one contiguous block. With the help of page tables/segment tables, a process can be split up into portions (page/segment).
3
Hardware allows us to place and then re-locate a process anywhere in memory.
Also, hardware makes it possible to place the process portions in non-contiguous locations.
4
Assumption An entire process need not be held in memory.
Portions of the process that are needed will be placed in memory. Portions are brought in as they are needed.
5
What happens when a new portion is needed?
The resident set(i.e. the pieces of the program that currently reside in main memory) must consist of the first address to be accessed and the first data to be accessed. The first instruction’s execution takes place. Address translations are performed using the page/segment table. At some point, the instruction to be accessed or the data to be accessed will not be available in main memory. The hardware will issue an interrupt. The OS will take over. The current process will get blocked. The OS will issue a disk request on behalf of the process. When the disk read is complete, the block is moved from secondary memory to main memory and another interrupt is now issued by the disk indicating that the service has been performed. Process will be moved back to the Ready queue. When process gets scheduled to run, it will continue.
6
Advantages More processes in main memory.
Better utilization of the processor. A process larger than main memory can also be run, with no intervention from the user. Only the size of secondary memory limits the user.
7
Real memory/Virtual memory
Real memory – the main memory space. Virtual memory – the space perceived by the user includes secondary storage
8
Locality of reference Data and instruction references tend to cluster
So, at any given time, only some part of the process has to reside in main memory.
9
Which block to replace when main memory is full?
If incorrect decisions are made, then the blocks swapped out will have to be brought back again The OS will spend a large amount of time swapping blocks in and out of main memory – Thrashing Must make intelligent choices about which block to swap out to minimize thrashing.
10
Virtual memory works because:
The OS can make intelligent guesses about which blocks must be swapped out. Hardware can keep track of which portions of a process are in main memory and also where they are in main memory.
11
Virtual memory with paging
Page table per process. Page table entry includes present bit frame number modify bit flags for protection and sharing. Page tables can be huge an entry per page of the process large processes (larger than main memory). Page table itself is placed in virtual memory.
12
For a program to execute, the relevant portion of the page table and the starting instructions and data of the process must be present in main memory. A register holds the address of the page table in main memory.
13
Also in main memory Simple indexing
15
Two-level scheme to support large tables
Consider a process as described here: Logical address space is 4-GiB (232 bytes) Size of a page is 4KiB (212 bytes) There are ___ pages in the process. This implies we need ____ page table entries. If each page table entry occupies 4-bytes, then need ______ byte large page table The page table will occupy __________ pages. Root table will consist of ____ entries – one for each page that holds part of the page table. Root table will occupy 212 bytes i.e 4KiB of space and will be kept in main memory permanently. A page access could require two disk accesses.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.