3. History
virtual memory was developed in
approximately 1959 – 1962, at the University
of Manchester for the Atlas Computer,
completed in 1962.
In 1961, Burroughs released the B5000, the
first commercial computer with virtual memory.
4. Virtual Memory
OS and hardware produce illusion of a disk as fast as main memory
Virtual memory as an alternate set of memory addresses.
Programs use these virtual addresses rather than real addresses to store instructions and
data.
When the program is actually executed, the virtual addresses are converted into real
memory addresses.
Process runs when not all pages are loaded in memory
Only keep referenced pages in main memory
Keep unreferenced pages on slower, cheaper backing store (disk)
Bring pages from disk to memory when necessary.
Virtual memory is imaginary memory: it gives you the
illusion of a memory arrangement that’s not physically
there.
The simple tactic of breaking a process up into pages led to
the development of important concept : Virtual memory
5. Virtual Memory ……(cont’d)
The basic idea of Virtual Memory is to keep only those
parts of the program currently in use in the memory and
the rest on the disk drive.
For example: a 16M program can run on a 4M machine by
carefully choosing which 4M to keep in memory at each
instant, with pieces of the program being swapped
between disk and memory as needed.
It can work in a Multiprogramming system, with bits and
pieces of many programs brought to the memory at once
by the Operating System. While a program is waiting for
part of itself to be brought in, it is waiting for I/O and
cannot run, so the CPU can be given to another process,
the same way as for any other multiprogramming
system.
6. Advantages
You can run more applications at once.
Allows you to fit many large programs into a relatively small RAM.
You don't have to buy more memory RAM
VM supports Swapping.
Common data or code may be shared to save memory.
Process need not be in memory as a whole , Only part of a program
needs to be loaded into memory.
Process may even be larger than all of physical memory.
Data / code can be read from disk as needed.
Code can be placed anywhere in physical memory without
relocation.
More processes can be maintained in Main Memory which increases
effective use of CPU.
Don't need to break program into fragments to accommodate
memory limitations
7. Why is it needed….
Before the development of the virtual memory
technique, programmers in the 1940s and 1950s
had to manage directly two-level storage such as
main memory or ram and secondary memory in
the form of hard disks or earlier, magnetic drums.
Enlarge the address space, the set of addresses a
program can utilize.
Virtual memory might contain twice as many
addresses as main memory.
8. How does it work…
To facilitate copying virtual memory into real
memory, the operating system divides virtual
memory into pages, each of which contains a
fixed number of addresses.
Each page is stored on a disk until it is
needed.
When the page is needed, the operating
system copies it from disk to main memory,
translating the virtual addresses into real
addresses.
9. Paging
• Extends partition idea by dividing up both memory and
processes into equal size pieces
• Split memory into equal sized, small chunks – called page
frames
• Split programs (processes) into equal sized small chunks -
called pages
• Allocate the required number page frames to a process
• Operating System maintains list of free frames
• A process does not require contiguous page frames
• Each process has a list of frames that it is using, called a page
table, stored in the PCB
• Paging Use page table to keep track
12. Demand paging
• Fetch Policy Determines when a page should be brought
into main memory. One of common policies is Demand
paging
• Refines paging by demand paging - each page of a
process is brought in only when needed, that is, on
demand
• Demand paging
– Do not require all pages of a process in memory
– Bring in pages as required
– Less I/O needed
– Less memory needed
– Faster response
– More users „
13. Page fault
If a page is needed which is not in memory, a page fault is
triggered, which requires an I/O operation
• Page fault
– Required page is not in memory
– Operating System must swap in required page
– May need to swap out a page to make space
14. Page fault……(cont’d)
An interrupt to the software raised by the hardware
when a program accesses a page that is not mapped in
physical memory.
when a program accesses a memory location in its
memory and the page corresponding to that memory is
not loaded
when a program accesses a memory location in its
memory and the program does not have privileges to
access the page corresponding to that memory.
15. Problems faced with Virtual Memory implementation:
Thrashing
Possibly large page table
Solution:
Use multilevel page tables.
Use TLB (Translation Lookaside Buffer) or some ti
mes called ‘Associative Memory’.
Page fault rates can be reduced by using a Wo
rking Set Model’ approach or a ‘Prepaging’ app
roach.
Increase RAM!
16. Thrashing
Pages currently in memory may have to be replaced. In some
situations this can lead to thrashing, where the processor
spends too much time swapping the same pages in and out
Thrashing
Swapping out a piece of a process just before that piece is
needed
The processor spends most of its time swapping pieces rather
than executing user instructions
Too many processes in too little memory
Operating System spends all its time swapping
Little or no real work is done
Disk light is on all the time
Solutions
Good page replacement algorithms
Reduce number of processes running
Fit more memory
17. Page Table Structure
Each process has a list of frames that it is using, called a page table, stored in the
PCB
Page Table Structure is a Basic mechanism for reading a word from memory
involves using a page table to translate :
• a virtual address - page number and offset
into
• a physical address - frame number and offset
Page tables may be very large
• they cannot be stored in registers
• they are often stored in virtual memory (so are subject to paging!)
• sometimes a page directory is used to organize many pages of page tables
,Pentium uses such a two-level structure
• sometimes an inverted page table structure is used to map a virtual address
to a real address using a hash on the page number of the virtual address
AS/400 and PowerPC use this idea.
18. 18
Page Table Structure
Page tables are variable in length (depends
on process size)
then must be in main memory instead of
registers
A single register holds the starting
physical address of the page table of the
currently running process
21. Translation Lookaside Buffer )TLB)
• Each virtual memory reference can causes two
physical memory access
One to fetch the appropriate page table entry
One to fetch the desired data
• To overcome this problem a high-speed cache is set
up for page table entries
– Called a Translation Lookaside Buffer (TLB)
• TLB is a special cache, just for page table entries
• Contains page table entries that have been most
recently used
22. Translation Lookaside Buffer
• Given a virtual address, processor examines
the TLB
• If page table entry is present (TLB hit), the
frame number is retrieved and the real
address is formed
• If page table entry is not found in the TLB
(TLB miss), the page number is used to index
the process page table
23. Translation Lookaside Buffer
• First checks if page is already in main
memory
– If not in main memory a page fault is issued
• The TLB is updated to include the new page
entry
26. Segmentation
• Another way in which addressable memory can
be subdivided, known as Segmentation
• May be unequal, dynamic size
• Paging is not (usually) visible to the programmer
• Segmentation is visible to the programmer
• Usually different segments allocated to program
and data
• May be a number of program and data segments
27. Advantages of Segmentation
• Simplifies handling of growing data
structures
• Allows programs to be altered and
recompiled independently, without re-linking
and re-loading
• Lends itself to sharing data among processes
• Lends itself to protection
• Some systems combine segmentation with
paging
28. Combined Paging and Segmentation
• Paging is transparent to the programmer
• Segmentation is visible to the programmer
• Each segment is broken into fixed-size pages.