Professional Documents
Culture Documents
Chapter 6: Memory: - CPU Accesses Memory at Least Once Per Fetch-Execute Cycle: - Memory Is Organized Into A Hierarchy
Chapter 6: Memory: - CPU Accesses Memory at Least Once Per Fetch-Execute Cycle: - Memory Is Organized Into A Hierarchy
We will explore
memory here
RAM, ROM, Cache,
Virtual Memory
Types of Memory
RAM
stands for random access
memory because you
access into memory by
supplying the address
it should be called readwrite memory (Cache
and ROMs are also
random access
memories)
Actually known as
DRAM (dynamic RAM)
and is built out of
capacitors
Capacitors lose their
charge, so must be
recharged often (every
couple of milliseconds)
and have destructive
reads, so must be
recharged after a read
Cache
SRAM (static RAM) made up of flip-flops
(like Registers)
Slower than registers because of added
circuits to find the proper cache location,
but much faster than RAM
DRAM is 10-100 times slower than SRAM
ROM
Read-only memory contents of memory
are fused into place
Variations:
PROM programmable (comes blank and
the user can program it once)
EPROM erasable PROM, where the
contents of all of PROM can be erased by
using ultraviolet light
EEPROM electrical fields can alter parts
of the contents, so it is selectively erasable,
a newer variation, flash memory, provides
greater speed
Locality of Reference
The better the hit rate for level 0, the better off we are
Similarly, if we use 2 caches, we want the hit rate of level 1 to
be as high as possible
We want to implement the memory hierarchy to follow
Locality of Reference
accesses to memory will generally be near recent memory accesses
and those in the near future will be around this current access
Cache
Cache is fast memory
Used to store instructions and data
It is hoped that what is needed will be in cache and what isnt needed
will be moved out of cache back to memory
Issues:
What size cache? How many caches?
How do you access what you need?
since cache only stores part of what is in memory, we need a
mechanism to map from the memory address to the location in cache
this is known as the caches mapping function
The cache has the same organization but there are far fewer line
numbers (say 1024 lines of 4 words each)
So the remainder of the address becomes the tag
The tag is used to make sure that the line we want is the line we found
The valid bit is used to determine
if the given line has been
modified or not (is the line in
memory still valid or outdated?)
Types of Cache
The mapping function is based on the type of cache
Direct-mapped each entry in memory has 1 specific place
where it can be placed in cache
this is a cheap and easy cache to implement (and also fast), but since
there is no need for a replacement strategy it has the poorest hit rate
Tag s-r
8
Line or Slot r
14
Word w
2
Associative Cache
Any line in memory can be placed in any line in cache
No line number portion of the address, just a tag and a word within the
line
Because the tag is longer, more tag storage space is needed in the cache,
so these caches need more space and so are more costly
Tag 22 bit
Word
2 bit
Tag s-r
9
Line or Slot r
13
Word w
2
If we are to write a
datum to cache, what
about writing it to
memory?
Write-through write to
both cache and memory
at the same time
if we write to several
data in the same line
though, this becomes
inefficient
Virtual Memory
Just as DRAM acts as a backup for cache, hard disk
(known as the swap space) acts as a backup for DRAM
This is known as virtual memory
Virtual memory is necessary because most programs are too
large to store entirely in memory
Also, there are parts of a program that are not used very often, so
why waste the time loading those parts into memory if they wont be
used?
We have to translate the page # into the frame # (that is, where
is that particular page currently be stored in memory or is it
even in memory?)
Thus, the mapping process for paging means finding the frame # and
replacing the page # with it
Example of Paging
A More
Complete
Example
Virtual address
mapped to physical
address
Address 1010 is
page 101, item 0
Page 101 (5) is
located in frame 11
(3) so the item 1010
is found at 110
Logical and physical memory for our program
Page Faults
Just as cache is limited in size, so is main memory a
process is usually given a limited number of frames
What if a referenced page is not currently in memory?
The memory reference causes a page fault
The page fault requires that the OS handle the problem
The OS locates the requested page on disk and loads it into the
appropriate frame in memory
The page table is modified to reflect the change
Page faults are time consuming because of the disk access this causes
our effective memory access time to deteriorate badly!
Here, we have 13 bits for our addresses even though main memory is only 4K = 2 12
The Full
Paging
Process
A Variation: Segmentation
One flaw of paging is that, because a page is fixed in size, a
chunk of code might be divided into two or more pages
So page faults can occur any time
Consider, as an example, a loop which crosses 2 pages
If the OS must remove one of the two pages to load the other, then the
OS generates 2 page faults for each loop iteration!
Example:
On chip cache hit rate is 90%, hit time is 5 ns, off chip cache hit rate is
96%, hit time is 10 ns, main memory hit rate is 99.8%, hit time is 60 ns,
memory miss penalty is 10 ms = 10,000 ns
memory miss penalty is the same as the disk hit time, or disk access time
Memory Organization