Cache Memory Mapping
Cache Memory Mapping
words inserted o n e : t
deleted and new a
If unwanted words have to be between active and
to distinguish d
time, there is a need for a special register would have
sometimes called
a lag register, as
inactive words. This register, For every active word stored in
there a r e words in the memory.
m a n v bits as is set to I. A word is deleted
bit in the tag register
m e m o r v , the corresponding
Words a r e stored in memory by
by clearing its tag bit to 0.
from e n c o u n t e r e d . This gives the first
m e m o r y
that
executed, the CPU repeatedly refers to the set of instructions in memory
constitute the loop. Every time a given subroutine is called, its set of instruc
tions are fetched from memory. Thus loops and subroutines tend to localize
the references to memory for fetching instructions. To a lesser degree, mem-
ory references to data also tend to be localized. Table-lookup procedures repeat-
edly refer to that portion in memory where the table is stored. Iterative
procedures refer to common memory locations and array of numbers are con
fined within a local portion of memory. The result of all these observations
is the locality of reference property, which states that over a short interva
of time, the addresses generated by a typical program refer to a few localized
areas of memory repeatedly, while the remainder of memory is accessed
relatively infrequently.
If the active portions of the program and data are placed in a fast smal
memory, the average memory access time can be reduced, thus reducing the
total execution time of the program. Such a fast small memory is referred
as a cache memory. It is placed between the CPU and main memory as illus
trated in Fig. 12-1. The cache memory access time is less than the access ume
of main memory by a lactor of 5 to 10. 'The cache is the fastest component in
access
asic
property
operation of the of
programs.
ca
procedures we wil a
sppe
discussion of
these three mapping
shown in Fie 19.10se
To help in the organiZaion as
iscano
of a memory each. The cache stor
cific example words of
12 bits
stored in cache g
store 32K every
word
can time. r o r
memory
words at any given
512 of these
Main memory
32Kx 12
CPU
Cache memory
512 12
a duplicate copy in main memory. The CPU communicates with both mem
ories. It first sends a 15-bit address to cache. If there is a hit, the CPU accents
the 12-bit data from cache. If there is a miss, the CPU reads the word from
main memory and the word is then transferred to cache.
Associative Mapping
The fastest and most flexible cache organization uses an associative memory.
This organization is illustrated in Fig. 12-11. The associative memory stores
both the address and content (data) of the memory word. This permits any
location in cache to store any word from main memory. The diagram shows
three words presently stored in the cache. The address value of l5 bits is
shown as a five-digit octal number and its corresponding 12-bit word is shown
as a four-digit octal number. A CPU address of 15 bits is placed in the argu-
ment register and the associative memory is searched for a matching address.
in octal).
Figure 12-11 Associative mapping cache (all numbers
CPU address (15 bits)
Argument register
2
- Data-
-Address-
01000 3 450
02777 67 10
22345 1234
If the SECTIO ON 12-5
address is Cache Mernory 46
the CPU. If no found, the
e
address-data pair is
corresponding
match occurs, corTesponding
the main
12-bit data
12.bit is read
reao and sent
cache is
full,then
an
memory
transferred to the
i The
that is needed address- data pair must
be associat to
iative cache mory. If the
and not displaced make ro for a pair
replaced is determinedpresently
from the
in the cache.
The decision as t air isis
chooses for the
cache. A simple replacement algorithm that designer
round-robin order procedure is to
whenever a new word is replace cells ot tneche
cach in
This constitutes
first in first out
a
requested from rmain tn ory
(FIFO) replacement policy.
Direct Mapping
Associauve memories are
because of the added expensive compared to random-access memories
logic associated with each cell. The
random-access memory for the cache possibility of usin8
is investigated in Fig. 12-12. The CFu
address of 15 bits is divided into two fields. The nine least
agficld stitute the index field and the significant bits con
shows that main
remaining six bits form the tag field. The
figure
memory needs an address that includes both the tag and the
index bits. The number of bits in the index field is equal to the number of
address bits required
to access the memory. cache
In the general case, there are 2" words in cache memory and 2" words in
main memory. The n-bit memory address is divided into two fields: k bits for
the index field andn - k bits for the tag field. The direct mapping cache
organization the n-bit address to access the main memory and the k-bit
uses
cache
index to access the cache. The internal organization of the words in the
Each word in cache consists of the data
memory is as shown in Fig. 12-13(b).
n e w word is first brought into the cache.
word and its associated tag. When a
stored the data bits. When the CPU generates a
alongside
the tag bits are
6 bits 9 bits
Index
Tag
000 512 12
32K x 12
00, 000 Octal Cache memory
address Address = 9 bits
Main memory
Data = 12 bits
Octal =
15 bits
Address
address D a t a = 12 bits
77 777 L
Memory Index
address Memory data address
Tag Data
00000 1220 000 00
1220
O0777 2340
01000 3 4 50
01777 4 560
02000 56 70
777
02 67 10
02777 6710
from main
no
match, there is a miss and the required word is read
memory. It is then stored in the cache
replacing the together with the new tag
previous value. The
disadvantage of direct
drop considerably if two or more words whosemapping
is that
hit ratio can tne
same index but addresses have thne
different tags are accessed
ity is minimized by the fact that such words repeatedly. However, this posS1
are relatively far
address range apart in the
lo see
(multiples
how the
of 512 locations in this example).
direct-mapping organization operates, consider
numerical example shown in Fig. 12-13. The word at is address
stored in the cache
(index presen
zero
770 02
Block 63
777 02 67 10
Set-Associative Mapping
at the disadvantage of direct mapping is that
It mentioned previously
was
same index
in their address but with different values tag
two words with the the same ume. A third type of cache organ-
cache memory at
cannot reside in mprovement over the direct
set-associaave mapping, 1S an
ization, called each word
in that
of cache can store two or more wor
organization Each data word is stored together
mapping same index address.
under the items in word of cache is said to
of memory -data one
of tag-data f
organization for a s e t size
number
and the
with its tag ol a set-assOCiaive cache data
example refers to two and
form a set. An 12-15. Each
index address
its and each data word has l2 bits,
shown in Fig. requires six
bits
two is Each tag ress o
index address of nine bits can
a s s o c i a t e d tags. 3o bits. An
their t 12) = x 36. I can
word length is 2(6 Thus the size: of cache memory is 512
s o the words.
since each word of cache contains
512
ain memory
of main
cache of set size k will
a c c o m m o d a t e
words acco
1024 a s s o ciative
iat
accommodate
a set
In general, each word
of cache
words. in
two data menory
words of main
date k
70 CHAPTER TWELVE Memory Organization
777 02 6710 00 23 40
memory alwayswrite-through
containsmethod. the word at
This
cache
the specified address. This is
spe
memory being
several times,
thecopy in main remains in the cache, does not matter
it
from the cache. Itmemory is out of
is only when date, since requests from the word are whetheT
filled
the word is
accurate copy need be displaced
rewritten into main memory.
from the cache
that an
that the number of
memory writes in a typical program Analytical results indicate
30 percent of the total ranges between 0 and
references to
memory.
Cache Initialization
One more aspect of cache organization that must be taken into consideration
is the problem of initialization. The cache is initialized when power is applied
to the computer or when the main memory is loaded with a complete set of
initialization the cache is considered
programs from auxiliary memory. After
nonvalid data. It is customary to
to be empty, but in effect it contains some
include with each word in cache a valid bit to indicate whether or not the word
contains valid data.
the valid bits to 0. The valid bit of
The cache is initialized by clearing alltime this word is loaded from main
first
word is set to I the
a particular cache the cache has
to be inmitialized again. The intro-
and stays set unless not replaced bv another
cache is
memory
m e a n s that
a word in
bit If the valid
duction of the valid and a
m i s m a t c h of tags occurs.
programs
and data main memory as they
into main
m e m o r
system, brought
are s o m e large
some large com-
hierarchy or
dala used in.
In aa m
In mem
emory
Portions
of a
program
memory
is a concept
programs
as though large
Virtual construct
memory. CPU. to
Iod by the i t
the user