Memory Hierarchy
Memory Hierarchy
Memory Hierarchy
Observations-
The following observations can be made when going down in the
memory hierarchy-
The goals of memory hierarchy are-
5. To obtain the highest possible average access speed
6. To minimize the total cost of the entire memory system
Inclusion Property
if an information word is found in Mi, then copies of the same word can
be also found in all upper levels Mi+1, Mi+2, …, Mn. However, a word
stored in Mi+1 may not be found in Mi. A word miss in Mi implies that
it is also missing from all lower levels Mi-1, Mi-2, …, M1. The highest
level is the backup storage, where everything can be found.
Information transfer between the CPU and cache is in terms of words (4
or 8 bytes each depending on the word length of a machine. The cache
(M1) is divided into cache blocks, also called cache lines by some
authors. Each block is typically 32 bytes
(8 words). Blocks are the units of data transfer between the cache and
main memory.
The main memory (M2) is divided into pages, say, 4Kbytes each. Each
page contains 128 blocks. Pages are the units of information transferred
between disk and main memory.
Coherence Property
The coherence property requires that copies of the same information
item at successive memory levels be consistent. If a word is modified in
the cache, copies of that must be updated immediately or eventually at
all higher levels. The hierarchy
should be maintained as such. Frequently used information is often
found in the lower levels in order to minimize the effective access time
of the memory hierarchy. In general, there are two strategies for
maintaining the coherence in a memory hierarchy.
Write Through:
Hit: data is found at higher level – the ideal case – Operation performed
quickly §
Miss: data not found –
Must continue the search at the next level down
– After data is eventually located, it is copied at the memory level where
the miss happened
Hit rate (hit ratio): fraction of accesses that are hits at a given level of
the hierarchy
Hit time: Time required to access a level of the hierarchy, including
time to determine whether access is a hit or miss
Miss rate (miss ratio): fraction of accesses that are misses at a given
level (= 1 – hit rate)
§ Miss penalty: Extra time required to fetch a block into some level
from the next level down
Hit ratio = hit / (hit + miss) = no. of hits/total accesses
Let-
= H1 x T1 + (1 – H1) x H2 x T2
= H1 x T1 + (1 – H1) x 1 x T2
= H1 x T1 + (1 – H1) x T2
Important Note
In any memory organization,
The data item being searched will definitely be present in the last level.
Thus, hit rate for the last level is always 1.
Average Cost Per Byte-
= { C1 x S1 + C2 x S2 } / { S1 + S2 }
Example-02:
Let-
= { C1 x S1 + C2 x S2 + C3 x S3 } / { S1 + S2 + S3 }
Example-01:
Here, two levels of memory are connected to the CPU in a hierarchical fashion.
Let-
= { C1 x S1 + C2 x S2 } / { S1 + S2 }
Example-02:
Here, three levels of memory are connected to the CPU in a hierarchical fashion.
Let-
Problem-01:
What is the average memory access time for a machine with a cache hit rate of 80% and cache access
time of 5 ns and main memory access time of 100 ns when-
Solution-
= H1 x T1 + (1 – H1) x H2 x T2
= 4 ns + 0.2 x 100 ns
= 4 ns + 20 ns
= 24 ns
= 4 ns + 0.2 x 105 ns
= 4 ns + 21 ns
= 25 ns
Problem-02:
A computer has a cache, main memory and a disk used for virtual memory. An access to the cache takes
10 ns. An access to main memory takes 100 ns. An access to the disk takes 10,000 ns. Suppose the
cache hit ratio is 0.9 and the main memory hit ratio is 0.8. The effective access time required to access a
referenced word on the system is _______ when-
Solution-
= 9 ns + 8 ns + 200 ns
= 217 ns
= 0.9 x 10 ns + (1 – 0.9) x 0.8 x (10 ns + 100 ns) + (1 – 0.9) x (1 – 0.8) x 1 x (10 ns + 100 ns + 10000 ns)
= 9 ns + 8.8 ns + 202.2 ns
= 220 ns