7.Module 2__Part 3
7.Module 2__Part 3
ARCHITECTURE
PCC-CS 402
Module 2 Part 3
Registers
Cache
Access Time
Capacity Memory
Cost
Main Memory
Virtual
Memory
Hard Disk
CD/DVD/Tape
Virtual Memory
• Hard Disk capacity is much more than Main Memory
• To increase effective size of the Main Memory, part of Hard Disk
memory can be utilized to behave similar to Main Memory
• Cache memory is an architectural arrangement which makes main
memory appear faster to the processor than it really is
• Virtual memory is an architectural arrangement which makes main
memory appear larger than it really is
Address Space
• Memory address space depends on the number of address bits in a
computer:
− For a computer using 32-bit addresses, address space is 4 Gigabytes
− For a 64-bit computer, address space is 16 Exabytes
• Physical main memory in a computer is generally not as large as the
entire addressable space
• Large programs that cannot fit completely into the main memory have
their parts stored on auxiliary storage devices
• Pieces of programs transferred to the main memory from secondary
storage before they can be executed
Virtual Memory
• When a new piece of a program is to be transferred to the main
memory, and if the main memory is full, some other piece in the main
memory must be replaced
• The portion of main memory moved out is stored in disk memory
• Operating system automatically transfers data between the main
memory and disk storage
• Application programmer need not be concerned with this transfer
• Also, application programmer does not need to be aware of the
limitations imposed by the available physical memory
Virtual Memory
• Virtual Memory techniques automatically move program and data
between main memory and disk storage
• Address used by Processor for instruction or data is called logical or
virtual addresses
• Virtual addresses are translated into physical addresses by a
combination of hardware and software subsystems
− If virtual address maps to an address in main memory, it is accessed
immediately
− If virtual address maps to an address currently not in the main memory,
it is first transferred to the main memory before it can be used
Memory Page
• Memory is broken down into fixed-length units called pages
• A page occupies contiguous locations in the main memory
• Page is a basic unit of information transferred between disk storage
and main memory
• Size of a page commonly ranges from 2K to 16K bytes
− Page size should not be too small, because it will require too many
access to disk, slowing down memory access
− Page size can not be too large, else a large portion of the page may
not be used, wasting valuable space in the main memory
VIRTUAL MEMORIES (CONTD..)
Processor
•Memory management unit (MMU) translates
virtual addresses into physical addresses.
Virtual address
•If the desired data or instructions are in the
Data MMU main memory they are fetched as described
previously.
Physical address •If the desired data or instructions are not in
the main memory, they must be transferred
Cache
from secondary storage to the main memory.
Data Physical address •MMU causes the operating system to bring
the data from the secondary storage into the
Main memory main memory.
DMA transfer
Disk storage
10
physical
pages
virtual
pages
Address Translation
• Each virtual or logical address generated by a processor contains the
virtual page number along with an offset that specifies the location of a
particular byte within that page
• Information about location of each page in is kept in a special table
called Page Table, which includes:
• Area of the main memory that can hold a page is called Page Frame
• Starting address of the page table is kept in Page Table Base Register
Address Translation
Virtual address from processor
Page table base register
Page table address Virtual page number Offset
+
PAGE TABLE
14
Page Table
• Page table maps each virtual page to a specific page frame in
memory
• The virtual address provided by processor contains virtual page
number along with offset of the desired location in the page
• Virtual page number, added with Page Table Base Register,
identifies the page in Page Table
• For each virtual page, its page frame starting address in memory
in stored in the Page Table
• The physical address of the memory location is arrived at by
combining starting address of the page frame along with the
offset
Page Table Control
• Page table entry also includes control information about the page
• Valid Bit indicates the validity of the page, set to ‘1’ if the page
frame is in memory, ‘0’ otherwise
• In case the page in not in main memory, accessing the page will
result in a page fault and it will be copied from disk storage
• Modified Bit indicates whether the page content has been
modified
• If Modified, the page must be written back to the disk when it is
removed from the main memory
• Similar consideration as the dirty or modified bit of cache
memory
Page Table Access
• Page Table is accessed frequently, for every read and write operation
in the memory
• Depending upon the total size of virtual memory, number of entries
Page Table can quite large
• Thus the Page table is kept in the main memory
• A small portion of the page table, containing recently accessed pages,
is kept in the cache memory to improve access time
• This copy of Page Table in cache is called Translation Lookaside
Buffer (TLB)
ADDRESS TRANSLATION (CONTD..)
A small cache called as Translation Lookaside Buffer (TLB) is
included in the MMU.
TLB holds page table entries of the most recently accessed pages.
Recall that cache memory holds most recently accessed blocks from
the main memory.
Operation of the TLB and page table in the main memory is similar to the operation of
the cache and main memory.
Page table entry for a page includes:
Address of the page frame where the page resides in the main memory.
Some control bits.
In addition to the above for each page, TLB must hold the virtual
page number for each page.
18
Translation Lookaside Buffer
• Translation Lookaside Buffer (TLB) is a fully associative cache that
holds page table entries
• Page table entry in TLB includes address of the page frame in the main
memory, along with its control information
• The mapping of an entry in TLB is done in the same way as Page Table
Address Translation
• To map a virtual page number in TLB, all entries of TLB are checked for
a match (fully associative cache)
• In case of a hit, entry from TLB is used to access page in memory
• In case of miss, the page entry is copied from Page Table before access
TLB frame
frame
frame
frame
We access the TLB on every reference instead of the page table. TLB must
therefore include the valid, dirty and the reference bits.
Every reference looks up the virtual
page # in TLB.
frame
frame
frame
frame TLB hit uses the physical page #
to form the address and turns on
the reference bit. Write turns on
the dirty bit too.
A TLB miss can be either a true page fault or just a TLB miss. If the
page exists in memory, the processor loads the translation from the page
table into the TLB and tries the reference again.
TLB
Virtual page Control Page frame in
number bits memory
No
=?
Miss
Yes
Hit
Page frame Offset
Page-replacement algorithm
Want lowest page-fault rate on both first access and re-access
Evaluate algorithm by running it on a particular string of memory
references (reference string) and computing the number of page faults on
that string
String is just page numbers, not full addresses
Repeated access to the same page does not cause a page fault
Results depend on number of frames available
15 page faults
multiprogramming
Another process added to the system