Chapter 5 Memory
Chapter 5 Memory
Memory
6.1 Introduction
2
6.2 Types of Memory
3
6.2 Types of Memory
5
6.3 The Memory Hierarchy
6
6.3 The Memory Hierarchy
7
6.3 The Memory Hierarchy
8
6.3 The Memory Hierarchy
9
6.3 The Memory Hierarchy
10
6.4 Cache Memory
11
6.4 .1 Cache Memory
Mapping
• The “content” that is addressed in content
addressable cache memory is a subset of the bits of
a main memory address called a field.
• The fields into which a memory address is divided
provide a many-to-one mapping between larger
main memory and the smaller cache memory.
• Many blocks of main memory map to a single block
of cache. A tag field in the cache block
distinguishes one cached memory block from
another.
12
6.4.1 Cache Memory
mapping
• The simplest cache mapping scheme is direct
mapped cache.
• In a direct mapped cache consisting of N blocks of
cache, block X of main memory maps to cache block
Y = X mod N.
• Thus, if we have 10 blocks of cache, block 7 of cache
may hold blocks 7, 17, 27, 37, . . . of main memory.
• Once a block of memory is copied into its slot in
cache, a valid bit is set for the cache block to let the
system know that the block contains valid data.
What could happen if there were no valid bit?
13
6.4.1 Cache Memory
mapping
• The diagram below is a schematic of what cache
looks like.
14
6.4.1 Cache Memory
mapping
• The size of each field into which a memory address
is divided depends on the size of the cache.
• Suppose our memory consists of 214 words, cache
has 16 = 24 blocks, and each block holds 8 words.
– Thus memory is divided into 214 / 2 8 = 211 blocks.
• For our field sizes, we know we need 4 bits for the
block, 3 bits for the word, and the tag is what’s left
over:
15
6.4.1 Cache Memory
mapping
• As an example, suppose a program generates the
address 1AA. In 14-bit binary, this number is:
00000110101010.
• The first 7 bits of this address go in the tag field, the
next 4 bits go in the block field, and the final 3 bits
indicate the word within the block.
16
6.4 Cache Memory
19
6.4 Cache Memory
21
6.4 Cache Memory
23
6.4 Cache Memory
24
6.4 Cache Memory
25
6.4 Cache Memory
26
6.4 Cache Memory
27
6.4 Cache Memory
28
6.4 Cache Memory
29
6.4 Cache Memory
30
6.4 Cache Memory
31
6.4 Cache Memory
32
6.4 Cache Memory
33
6.4 Cache Memory
34
6.4 Cache Memory
35
6.4 Cache Memory
36
6.4 Cache Memory
37
6.5 Virtual Memory
39
6.5 Virtual Memory
41
6.5 Virtual Memory
42
6.5 Virtual Memory
• If the valid bit is zero in the page table entry for the
logical address, this means that the page is not in
memory and must be fetched from disk.
– This is a page fault.
– If necessary, a page is evicted from memory and is replaced
by the page retrieved from disk, and the valid bit is set to 1.
• If the valid bit is 1, the virtual page number is replaced
by the physical frame number.
• The data is then accessed by adding the offset to the
physical frame number.
43
6.5 Virtual Memory
44
6.5 Virtual Memory
45
6.5 Virtual Memory
46
6.5 Virtual Memory
47
6.5 Virtual Memory
48
6.5 Virtual Memory
The next slide shows how all the pieces fit together.
49
6.5 Virtual Memory
50
6.5 Virtual Memory
52
6.5 Virtual Memory
55
Chapter 6 Conclusion
57
End of Chapter 6
58