lec 9-1
lec 9-1
Memory Organization
1
Write Policy
An important aspect of cache
organization is concerned with
memory write requests.
When the CPU finds a word in cache
during a read operation, the main
memory is not involved in the transfer.
However, if the operation is a write,
there are two ways that the system
can proceed:
1. Write-through
2. Write-back
2
1. Write-through
The simplest and most commonly used
procedure.
Update main memory with every
memory write operation, with cache
memory being updated in parallel if it
contains the word at the specific
address.
This method has the advantages that
main memory always contains the
same data as cache.
3
1. Write-through
It ensures that the data residing
in main memory are valid at all
times so that an I/O device
would receive the most recent
updated data.
However, it has the
disadvantage of high memory
traffic and may create a
bottleneck.
4
2. Write-back
Only the cache location is updated
during a write operation.
The location is then marked by a flag
(called update bit or dirty bit) so that
later when the word is removed
(replaced) from the cache, it is copied
into main memory.
The reason for the write back method is
that during the time a word resides in
the cache, it may be updated several
times;
However, as long as the word remains
in the cache, it does not matter whether
the copy in main memory is out of date,
since requests from the word are filled5
6
Virtual Memory
Most modern computer systems use a hard
disk (also called a hard drive) as the lowest
level in the memory hierarchy.
Compared with the ideal large, fast, cheap
memory, a hard disk is large and cheap but
terribly slow. The disk provides a much larger
capacity than is possible with a cost-effective
main memory(DRAM).
Virtual Memory is a storage scheme that
provides user an illusion of having a very big
main memory. This is done by treating a part of
secondary memory as the main memory.
Chapter 8 <7>
Memory Hierarchy
Access Bandwidth
Technology Price / GB
Time (ns) (GB/s)
DRAM $10 10 - 50 10
Main Memory
Magnetic
Disks
Read/Write
Head
Chapter 8 <9>
Virtual Memory
Virtual addresses
Programs can access data anywhere in virtual
memory, so they must use virtual addresses that
specify the location in virtual memory.
The physical memory holds a subset of most
recently accessed virtual memory.
In this way, physical memory acts as a cache for
virtual memory.
CPU translates virtual addresses into physical
addresses (DRAM addresses)
The process of determining the physical address
from the virtual address is called address
translation.
Data not in DRAM fetched from hard drive.
Main memory (DRAM) acts as cache for hard disk
Chapter 8 <10>
Cache/Virtual Memory Analogues
Chapter 8 <11>
Virtual Memory Definitions
Page size: amount of memory
transferred from hard disk to DRAM
at once.
Address translation: determining
physical address from virtual
address
Page table: lookup table used to
translate virtual addresses to
physical addresses
Chapter 8 <12>
Virtual & Physical Addresses
Chapter 8 <13>
Address Translation
Chapter 8 <14>
Address Translation
Chapter 8 <15>
Virtual Memory Example
System:
Virtual memory size: 2 GB = 231
bytes
Physical memory size: 128 MB =
227 bytes
Page size: 4 KB = 212 bytes
Chapter 8 <16>
Virtual Memory Example
System:
Virtual memory size: 2 GB = 231 bytes
Physical memory size: 128 MB = 227
bytes
Page size: 4 KB = 212 bytes
Organization:
Virtual address: 31 bits
Physical address: 27 bits
Page offset: 12 bits
# Virtual pages = 231/212 = 219 (VPN =
19 bits)
# Physical pages = 227/212 = 215 (PPN =
Chapter 8 <17>
15 bits)
Virtual Memory Example
19-bit virtual page
numbers
15-bit physical page
numbers
Chapter 8 <18>
Virtual Memory Example
Chapter 8 <19>
Virtual Memory Example
What is the physical
address of virtual
address 0x247C?
VPN = 0x2
VPN 0x2 maps to PPN 0x7FFF
12-bit page offset: 0x47C
Physical address = 0x7FFF47C
Chapter 8 <20>
How to perform translation?
Page table
The processor uses a page table to
translate virtual addresses to
physical addresses.
The page table contains an entry for
each virtual page.
Entry fields:
Valid bit: 1 if page in physical memory,
Otherwise, the virtual page is found on
disk.
Physical page number: where the
page is located
Chapter 8 <21>
Page Table Example
Virtual Page
Page Number Offset
Virtual
0x00002 47C
Address
19 12
Physical
V Page Number
0
0
1 0x0000
VPN is index 1
0
0x7FFE
Page Table
into page table 0
0
0
1 0x0001
0
0
1 0x7FFF
0
0
15 12
Hit
Physical
0x7FFF 47C
Address
Chapter 8 <22>
Page Table Example 1
Page Table
0
0
0
1 0x0001
0
0
1 0x7FFF
0
0
Chapter 8 <23>
Page Table Example 1
Virtual Page
Page Number Offset
Virtual
0x00005 F20
Address
19 12
Page Table
VPN = 5 – 0
Physical
0x0001 F20
Address
Chapter 8 <24>
Page Table Example 2
Virtual Page
Page Number Offset
Virtual
0x00007 3E0
Address
19
Page Table
0
0x73E0?
0
0
1 0x0001
0
0
1 0x7FFF
0
0
15
Hit
Chapter 8 <25>
Page Table Example 2
Virtual Page
Page Number Offset
Virtual
0x00007 3E0
Address
19
Page Table
0
VPN = 7 –
Entry 7 is invalid – 0
0
Virtual page must – 1
0
0x0001
be paged into 0
1 0x7FFF
physical memory 0
0
from disk 15
Hit
Chapter 8 <26>
The Translation Lookaside Buffer
• The page table is usually so large that it is
located in physical memory. Hence, each load
or store involves two physical memory
accesses: a page table access, and a data
access.
• To speed up address translation, a translation
lookaside buffer (TLB) caches the most
commonly used page table entries.
• A TLB is organized as a fully associative cache
and typically holds16 to 512 entries.
Chapter 8 <27>
The Translation Lookaside Buffer
• Each TLB entry holds a virtual page number
and its corresponding physical page number.
The TLB is accessed using the virtual page
number.
• If the TLB hits, it returns the corresponding
physical page number.
• Otherwise, the processor must read the page
table in physical memory.
Chapter 8 <28>
Example 8.15 USING THE TLB TO PERFORM ADDRESS
TRANSLATION
Solution: Figure 8.25 shows the two-entry TLB with the request for
virtual address 0x247C. The TLB receives the virtual page number
of the incoming address, 0x2, and compares it to the virtual page
number of each entry. Entry 0 matches and is valid, so the request
hits. The translated physical address is the physical page number of
the matching entry, 0x7FFF, concatenated with the page offset of the
virtual address. As always, the page offset requires no translation.
The request for virtual address 0x5FB0 misses in the TLB. So, the
request is forwarded to the page table for translation.
Chapter 8 <29>
Chapter 8 <30>
Write and Replacement Policies