2. Background
Instructions being executed must be in physical memory.
Need to place entire logical address space into main memory.
Limits the size of the program to size of the physical memory.
But in many cases the entire program is not needed.
3. situations, when entire program is not required to be loaded fully in main memory.
User written error handling routines are used only when an error occurred in the
data or computation.
Certain options and features of a program may be used rarely.
Many tables are assigned a fixed amount of address space even though only a
small amount of the table is actually used.
4. Benefits of execute program that is only partially in memory
1. Program would be no longer constrained by amount of physical memory that is
available.
2. Each program would take less physical memory more programs could be run at
same time. Which causes increase in CPU throughput and utilization.
3. Less IO would be needed to load or swap user programs into memory. So each
user program run faster.
5. Virtual Memory
Virtual Memory is a storage mechanism which offers user an illusion of having a
very big main memory.
It is done by treating a part of secondary memory as the main memory. In Virtual
memory, the user can store processes with a bigger size than the available main
memory.
Virtual Memory allows execution of process that is not completely in memory.
Advantage is that programs can be larger than physical memory.
6. Virtual memory involves the separation of logical memory from physical memory.
This separation allows an extremely large virtual memory to be provided for
programmers when only smaller physical memory is available.
Makes task of programming easier, because programmer need not to worry about
amount of physical memory available.
7. Virtual address space of process refers to logical view of how process is stored in
memory
8. Demand Paging
Executable program loaded from disk into memory.
Load entire program in physical memory.
Suppose we may need entire program in memory initially.
Strategy is to load pages only as they are needed. This technique is known as
demand paging and used in virtual memory systems.
Pages are only loaded when they are demanded at execution.
Demand paging is paging system with swapping. Where processes reside usually in
secondary memory(disk).
When we want to execute a process we swap into memory.
Rather than swapping entire process into memory pager swaps needed pages into
memory for execution.
10. Basic concept
Pager is responsible to swap pages between disk and memory.
Pager guess which pages will be used for execution before process is swapped out
again.
Here we need some hardware which will decide which page is in memory and
which is on disk
Valid-invalid bit is used here.
Valid: page is legal and in memory
Invalid: either it is illegal or on disk
12. Page Fault
Access to page that is marked as invalid causes page fault.
Paging hardware which translating address through page table will notice that invalid
bite is set causes an trap to operating system.
Trap is the OS failure to bring desired page into memory.
The procedure for handling page fault
1. We check internal table for this process to check reference is valid or invalid.
2. If invalid we terminate the process. If valid we bring page in memory.
3. We find free frame (frame free frame list)
4. We schedule a disk operation read the desired page into newly allocated frame.
5. When disk read compete, we modify internal table kept with process and page table to
indicate that page is now in memory.
6. We restart the instruction that was interrupted by trap. Process can access page as it had
always in memory
Pure demand paging
14. Locality of reference
Program access several new pages of memory with each instruction execution.
Causes multiple faults per instruction‘.
Causes unacceptable system performance.
Programs tends to locality of reference.
15. Hardware support
Same as paging
1. Page table :protection bits
2. Secondary memory: holds pages that are not in memory