Every process is divided into number of segments of
potentially different sizes and loaded onto main memory by
creating dynamic partitions which need not be contagious.
Hence, Logical Address is now (segment number, offset)
This offers a solution with no internal fragmentation.
Simple Paging
Every process is divided into number of 'pages' of
equal size and loaded onto main memory which is itself
divided into partitions called 'frames'.
Size of a page is the same as size of a frame.
As a result, there is no internal fragmentation.
Hence, Logical Address is now (page number, offset)
Page table information is used to calculate (frame number, offset).
Virtual memory
Logical Addresses are dynamically translated to physical
addresses at runtime.
This means that a page can occupy different
areas of main memory at different times.
Process pages are not contagiously located in main memory.
Logical address to physical address translation is of utmost
importance at runtime using Page Table.
HENCE, It is NOT necessary that all the
pages are in main memory during process execution.
If, for the time being, the next
page/segment to be executed is in main memory,
then execution can proceed.
This is the idea of VIRTUAL MEMORY.
Working of Virtual memory
Resident Set
Resident Set is the portion of the process which is in main memory.
If processor encounters a logical address which is not in main memory:
It generates an interrupt which indicates a memory access fault.
Interrupted process is put in blocked state and
Operating System takes control.
Disk I/O request is issued to bring into main memory
the page whose logical address caused a fault.
Once disk I/O interrupt is issued, the OS takes control
and resumes the process which threw an interrupt.
Page Table Structure
Page Table becomes more complex than what
it is in Simple Paging.
Bit 'P' indicates the presence of the page in main memory.
If P is flagged as true, then frame number of that
page is also present.
Modify bit 'M' indicates whether contents of that page have been
altered since it was last loaded into main memory.
If M is flagged as false, then no need to write out the page
when it is replaced in the frame it is occupying in main memory
Translation Lookaside Buffer (TLB)
Each Virtual memory Reference can cause 2 physical address
lookups viz. the page table entry and the actual data.
TLB provides a solution to this by providing a high speed
cache storing page table entries.
Given a virtual address, the processor will first examine the TLB
If TLB contains the physical address, then page is loaded, else,
page is loaded from main memory and also stored in TLB for future use.
If page is not present in both TLB and main memory, then page fault occurs.
TLB contains both page number as well as complete page table entry.
Quiz
Size of virtual memory is
Larger than main memory
Smaller than main memory
Larger than both disk and main memory
None of the above
The process which runs immediately after a page fault occurs is
the interrupted process resumes
The operating system
the next process
None of the above
Answers
1. a; 2. b;
Credits
Referred to Notes by Professor Daniel Katz. (previously professor of Operating Systems at NYU Tandon School of Engineering)