Beruflich Dokumente
Kultur Dokumente
Memory Organization
CS 147
Presented by:
Duong Pham
Introduction
• In chapter IV we look at two simple computers consisting of a
CPU, I/O subsystem, and a memory subsystem.
• The memory of these computers was build using only ROM and
RAM.
• This memory subsystem is fine for computers that perform a
specific task:
– examples: controlling a microwave oven
– controlling a dishwasher, etc..
• However, a complex computers cannot run on a memory
subsystem consisting only of such physical memory because it
would be relatively slow and somewhat limited.
Overview
• Hierarchy of Memory System
• Cache Memory
– Associative Memory
– Cache Memory with Associative Mapping
– Cache Memory with Direct Mapping
– Cache Memory with Set-Associative Mapping
– Replacing Data in the Cache
– Writing Data to the Cache
– Cache Performance
Hierarchy of Memory System
• A computer system is not constructed using a single type of memory.
• In fact, several types of memory are used.
– For examples: Level 1 cache (L1 cache)
– Level 2 cache (L2 cache)
– Physical Memory
– Virtual Memory
• The most well known element of the memory subsystem is the physical memory,
which is constructed using DRAM chips.
• There is also a cache controller which copies data from the physical memory to cache
memory before or when the CPU needs it.
• In general, the closer a component is to the processor, the faster it is and the more
expensive it is.
• Therefore, memory system tend to increase in size as they move away from the CPU.
Virtual
Virtual
CPUwith
CPU with L2
L2 Physical
Physical memory
memory
L1cache
L1 cache cache
cache memory
memory storage
storage
Valid
address bits( index) select on specific R.S. CPU Tag Data
location in the cache. 10
• As in associative cache, it contains a (A[9…0])
valid bit to denote whether or not the
location has valid data.
• In addition, a tag field contains the
high-order bits of the original address
000000 10101010 1
that were not a part of the index.
Therefore, the six high-order bits are
stored in the tag field.
• Last, the cached data value is stored as
the value. Output Register
Cache Memory with Direct Mapping cont.
• For example, consider location 0000 0011 1111 1111 of
physical memory, which contains data 1010 1010.
• This data can only be stored in one location in the cache. The
location that has the same 10 low-order address bits as the
original address, or 11 1111 1111.
• However, any address of the form xxxx xx11 1111 1111 would
map to this same cache location.
• This is the purpose of the tag field.
• In the previous picture, the tag value for this location is 00 0000.
• This means that the data stored at location 11 1111 1111 is
actually the data from physical memory location 0000 0011
1111 1111, which is 1010 1010.
• Also, in the previous picture, we see a 1 in the valid section, if
the bit was 0, none of this would be considered because the data
in that location is not valid.
Cache Memory with Direct Mapping cont.
• Although direct-mapped cache is much less expensive than the associative
cache, it is also much less flexible.
• In associative cache any word of physical memory can occupy any word of
cache.
• However, in direct-mapped cache, each word of physical memory can be
mapped to only one specific location.
• This is a problems for certain of programs.
• A good compiler will allocate the cod so this does not happen.
• However, it does illustrate a problem that can occur due to inflexibility of
direct mapping.
• Set-associative mapping seeks to alleviate this problem while taking advantage
of the strengths of direct-cache mapping method.
• This brings us to the next topic.
Cache Memory with Set-Associative Mapping
Count/valid
Count/valid
From
Data
Data
Tag
Tag
F
R.S. CPU
9(A[8….0])
• Write-back:
– In write-back, the value written to the cache is not always written to
physical memory.
– The value is written to physical memory only once, when the data is
removed from the cache.
– This saves time used by write-through caches to copy their data to physical
memory, but also introduces a time frame during which physical memory
holds invalid data.
Writing Data to the Cache cont.
• Example:
– Let consider a simple program loop:
– for I = 1 to 1000 do
– x = x + I;
– During the loop, the CPU would write a value to x 1000
times.
– If we use the write-back method, this loop would only
write the result to physical memory one time instead of
1000 times if we were to used write-through method.
– Therefore, write-back offers a significant time savings.
Writing Data to the Cache cont.
• However, performance is not the only consideration.
• Sometimes the currency of data also takes precedence.
• Another situation that must be addressed is how to write data to locations
not currently loaded into the cache.
• This is called a write-miss.
• One possibility is to load the location into cache and then write the new
value to cache using either write-back or write-through method.
• This is called write-allocate policy.
• Then there is the write-no allocate policy.
• This process updates the value in physical memory without loading it into
the cache.
Cache Performance
• The primary reason for including cache memory in a computer is to
improve system performance by reducing the time needed to access
memory.
• The two primary components of cache performance are cache hits and
cache misses.
• Cache hits:
– Every time the CPU accesses memory, it checks the cache.
– If the requested data is in the cache, the CPU accesses the data in
the cache, rather than physical memory
• Cache misses:
– If the requested data is not in the cache, the CPU accesses the data
from main memory (and usually writes the data into the cache as
well.)
Cache Performance cont.
• Hit ratio is the percentage of memory
accesses that are served from the cache, h Tm
rather than from physical memory. 0 60 ns
0.1 55 ns
• The higher the hit ratio, the more times
0.2 50 ns
the CPU accesses the relatively fast 0.3 45 ns
cache memory and the better the system 0.4 40 ns
performance. 0.5 35 ns
• The average memory access time(Tm) is 0.6 30 ns
0.7 25 ns
the weighted average of the cache access
0.8 20 ns
time, Tc, plus the access time for 0.9 15 ns
physical memory, Tp. 1.0 10 ns
• The weighing factor is the hit ratio h.
• Therefore, Tm can be expressed as:
* This is the table for the hit ratios
– Tm = h Tc + (1 - h) Tp and average memory access times
Cache Performance cont.
• The rest of section 9.2 (pages 393-395) show the different methods of
cache activity using all those method that I’ve been discussing so far.
• It uses the average memory access time (Tm) equation to generate
results (hit ratio and average memory access time (Tm)) for each
different methods.
• If you want to take a look at those examples to see how they were
process and generate those results, take a look at those pages I’ve
mention above.
• This concluded my presentation.
• Thank you.
Any questions?