Docsity

Cache and Virtual Memory: LRU, Locality, and Cache Performance, Assignments of Computer Architecture and Organization

Toggle sidebar
bg1
Cache Memory and Virtual Memory
1. Briefly (1 or 2 sentences) describe the LRU replacement algorithm.
The Least Recently Used (LRU) replacement algorithm describes which virtual memory page or cache
block should be replaced when a new page or cache block needs to be brought into main memory or the
cache. LRU replacement means that the page or block that was least recently used should be replaced.
Cache Memory
1. Name and describe the two types of locality of reference. Include examples.
Temporal Locality - data/instructions that have been used recently are likely to be used again. For
example: instructions in a loop, data used in a loop.
Spatial Locality - data/instructions near data/instructions that have been used are likely to be used
s
oon. For example: linear execution of instructions, stepping through an array.
2. Briefly (1 or 2 sentences) describe why locality of reference is an important concept with regard to
caching.
L
ocality of reference allows the cache to operate efficiently because it describes the principles that data
that was recently used will probably be used again, and data that is close to data that has been used will
p
robably be used soon.
Virtual Memory
1. Briefly (1 or 2 sentences) describe the working set of a running program.
The working set is the data, instructions, and stack that is currently being used by a running program.
2. Briefly (1 or 2 sentences) describe thrashing.
Thrashing occurs when the computer is spending more time accessing memory (to swap pages in and
out of main memory) than it spend actually processing.
3. Describe the purpose of the TLB.
The Translation Lookaside Buffer (TLB) acts as a cache for the page table. It contains translations of
virtual addresses to ph
y
sical addresses.
CEG 320/520: Computer Organization and Assembly Language Programming
Fall, 2004
Homework: Memory updated: 3-nov-04
pf3
pf4

Partial preview of the text

Download Cache and Virtual Memory: LRU, Locality, and Cache Performance and more Assignments Computer Architecture and Organization in PDF only on Docsity!

Cache Memory and Virtual Memory

  1. Briefly (1 or 2 sentences) describe the LRU replacement algorithm.

The Least Recently Used (LRU) replacement algorithm describes which virtual memory page or cache block should be replaced when a new page or cache block needs to be brought into main memory or the cache. LRU replacement means that the page or block that was least recently used should be replaced.

Cache Memory

  1. Name and describe the two types of locality of reference. Include examples.

Temporal Locality - data/instructions that have been used recently are likely to be used again. For example: instructions in a loop, data used in a loop.

Spatial Locality - data/instructions near data/instructions that have been used are likely to be used soon. For example: linear execution of instructions, stepping through an array.

  1. Briefly (1 or 2 sentences) describe why locality of reference is an important concept with regard to caching.

Locality of reference allows the cache to operate efficiently because it describes the principles that data that was recently used will probably be used again, and data that is close to data that has been used will probably be used soon.

Virtual Memory

  1. Briefly (1 or 2 sentences) describe the working set of a running program.

The working set is the data, instructions, and stack that is currently being used by a running program.

  1. Briefly (1 or 2 sentences) describe thrashing.

Thrashing occurs when the computer is spending more time accessing memory (to swap pages in and out of main memory) than it spend actually processing.

  1. Describe the purpose of the TLB.

The Translation Lookaside Buffer (TLB) acts as a cache for the page table. It contains translations of virtual addresses to physical addresses.

CEG 320/520: Computer Organization and Assembly Language Programming

Fall, 2004 Homework: Memory updated: 3-nov-

Cache Performance Calculation

z hn = hit rate in level n cache z Cn = time to fetch a word from level n cache z M = time to access a word from main memory.

  1. Single Cache

1a. Without looking at your notes, try to derive the formula for determining the average access time for a word in a system with a single cache. Think about it!

t = h 1 C 1 + (1 - h 1 )M

1b. Assume the following values for a theoretical system containing an L1 cache.

Determine the average access time for a memory word in the described system.

  1. Three Caches

2a. Without looking at your notes, try to derive the formula for determining the average access time for a word in a system with three caches. Think about it!

t = h 1 C 1 + (1 - h 1 )(h 2 C 2 + (1 - h 2 )(h 3 C 3 + (1 - h 3 )M))

2b. Assume the following values for a theoretical system containing an L1, L2, and L3 cache.

Determine the average access time for a memory word in the described system.

Location Latency Hit Rate

L1 (on-chip) C^1 = 5ns^ h 1 = 50%

Main Memory M = 100ns h 3 = 100%

Location Latency Hit Rate

L1 (on-chip) C^1 = 5ns^ h 1 = 50%

L2 (on-chip) C^2 = 10ns^ h 2 = 75%

L3 (off-chip) C^3 = 35ns^ h 3 = 90%

Main Memory M = 100ns hM = 100%

3a. Suppose the system has a 2-way set associative cache. Now how is the address broken up? How many main memory blocks maps to each cache set?

A set-associative cache works almost the same as a direct-mapped cache. The only difference is that the “Block” field becomes the “set” field. In this case, we have 1024 cache lines/blocks. Because we are

using a 2-way set-associative cache, there are two lines per set, for a total of 512 sets (2 9 sets). This means we need 9 bits to determine which set a particular address would belong to, so our address is broken up as follows:

Tag = 4 bits Set = 9 bits Word = 6 bits

Each set holds two blocks, so twice as many main memory blocks can map to each set. This is reflected in the fact that the tag field now includes 4 bits, indicating that 16 different main memory blocks can map to each set. The 4-bit tag indicates which of the 16 memory blocks that could occupy that block in the set is actually occupying it.

3b. Describe how the system will check if a given word is currently in the cache. How many compares between the address and the tag field will be necessary?

To check if the word we want is in the cache, we use the 9 bits of the set field to determine which of the 512 cache sets our word could be stored in. Then we check the first 4 bits of the address against each tag in that set. Because there are two lines in each set (2-way set associative) we must make two compares. If we find a tag that matches our address, our word is in the cache and we use the last 6 bits of the address to select it from the cache line. Otherwise, we get a new block from main memory and replace one of the two lines in our cache set.