Os Virtual Memory
Os Virtual Memory
A computer can address more memory than the amount physically installed on the system. This extra memory is actually
called virtual memory and it is a section of a hard that's set up to emulate the computer's RAM.
The main visible advantage of this scheme 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.
Following are the 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 occured in the data or computation.
Many tables are assigned a fixed amount of address space even though only a small amount of the table is actually
used.
The ability to execute a program that is only partially in memory would counter many benefits.
Less number of I/O would be needed to load or swap each user program into memory.
A program would no longer be constrained by the amount of physical memory that is available.
Each user program could take less physical memory, more programs could be run the same time, with a
corresponding increase in CPU utilization and throughput.
Modern microprocessors intended for general-purpose use, a memory management unit, or MMU, is built into the
hardware. The MMU's job is to translate virtual addresses into physical addresses. A basic example is given below:
Virtual memory is commonly implemented by demand paging. It can also be implemented in a segmentation system.
Demand segmentation can also be used to provide virtual memory.
Demand Paging
A demand paging system is quite similar to a paging system with swapping where processes reside in secondary memory
and pages are loaded only on demand, not in advance. When a context switch occurs, the operating system does not copy
any of the old programs pages out to the disk or any of the new programs pages into the main memory Instead, it just
begins executing the new program after lading the first page and fetches that programs pages as they are referenced.
While executing a program, if program reference a page which is not available in the main memory because it was swapped
out a little ago, the processor treats this invalid memory reference as a page fault and transfers control from the program
to the operating system to demand the page back into the memory.
Advantages
Following are the advantages of Demand Paging
Disadvantages
Following are the disadvantages of Demand Paging
Number of tables and amount of processor overhead for handling page interrupts are greater than in the case of the
simple paged management techniques.
When the page that was selected for replacement and was paged out, is referenced again then it has to read in from disk,
and this requires for I/O completion. This process determines the quality of the page replacement algorithm: the lesser the
time waiting for page-ins, the better is the algorithm. A page replacement algorithm looks at the limited information about
accessing the pages provided by hardware, and tries to select which pages should be replaced to minimize the total number
of page misses, while balancing it with the costs of primary storage and processor time of the algorithm itself. There are
many different page replacement algorithms. We evaluate an algorithm by running it on a particular string of memory
reference and computing the number of page faults.
Reference String
The string of memory references is called reference string. Reference strings are generated artificially or by tracing a given
system and recording the address of each memory reference. The latter choice produces a large number of data, where we
note two things.
For a given page size we need to consider only the page number, not the entire address.
If we have a reference to a page p, then any immediately following references to page p will never cause a page
fault. Page p will be in memory after the first reference; the immediately following references will not fault.
Easy to implement, keep a list, replace pages from the tail and add new pages at the head.
Easy to implement, keep a list, replace pages by looking back into time.
Write new page in the frame of free pool, mark the page table and restart the process.
Now write the dirty page out of disk and place the frame holding replaced page in free pool.