8. Memory Hierarchy Flashcards

1
Q

Define spatial locality.

A

Memory locations close to a recently accessed location are likely to be accessed again in the near future.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define temporal locality.

A

Recently accessed memory locations are likely to be accessed again in the near future.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why does locality exist in programs?

A

Instruction reuse: loops, functions.
Data working sets: arrays, objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the common memory hierarchy in a computer.

A

Registers (100s of bytes, ~1ns)
Cache (SRAM, 1KB-10MB, 1-10ns)
Main Memory (DRAM, 1-64GB, ~100ns)
Disk/SSD (100s GB SSD/1-2TB disk, ~100μs - 10ms)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does memory hierarchy take advantage of temporal locality and spatial locality?

A

Temporal locality:
- If accessing data from slower memory, move it to faster memory.
- If data in faster memory unused recently, move it to slower memory.

Spatial locality:
- If need to move a word from slower to faster memory, move adjacent words at same time.
- Gives rise to blocks and pages: units of storage within the memory hierarchy composed of multiple contiguous words.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Between which memories does the software move the data, and which the hardware?

A

The software transfers between the registers and cache. (compiler)
The hardware transfers between the cache and main memory.
The software transfers between the main memory and disk. (operating system)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How are hardware-managed transfers performed?

A

Data moved between levels automatically in response to the program’s memory accesses.

Memory always has a copy of cached data, but data in the cache may be more recent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In terms of caches, define block.

A

A block is the unit of data stored in the cache (normally in the range of 32-128 bytes). The block size is larger than a word to help exploit spatial locality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In terms of caches, define miss.

A

A miss is where the data is not found. The search needs to be performed in the next level of hierarchy (maybe another cache, or maybe main memory). Once the data is located, it is copied to the memory level where the miss happened.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In terms of caches, define hit.

A

A hit is where data is found (so is completed quickly).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In terms of caches, define hit rate.

A

The proportion of memory accesses that are hits at a given level of the memory hierarchy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In terms of caches, define miss rate.

A

The proportion of memory accesses that are misses at a given level of the memory hierarchy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In terms of caches, define allocation.

A

Placement of a new block into the caches, usually evicting another block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In terms of caches, define eviction.

A

Displacement of a block from the cache, which occurs when a new block is allocated in its place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Compare LRU and FIFO policies.

A

LRU (Least Recently Used) evicts the cache block that hasn’t been accessed for the longest.

FIFO (First In, First Out) replaces in the same order as filled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the three categories of cache?

A

Direct-mapped (each memory location is mapped to one location in the cache.)
Set-associative (each memory location can be placed in a set of locations in the cache.)
Fully-associative (each memory location can be placed anywhere in the cache.)

17
Q

In a direct-mapped cache, what is the most common mapping?

A

Cache address = (block address) mod (no. blocks in cache).

18
Q

What cache address will a memory address of 01101 take in an 8-block direct-mapped cache, with each block being a byte?

A

101

{01101 = 13 mod 8 = 5 -> 101}

19
Q

Each cache memory block has a tag associated with it. What is the purpose of the tag?

A

The tag identifies the block present at the address in the cache.

20
Q

What is the purpose of a valid bit?

A

To identify if the block is a valid address.

21
Q

A direct-mapped cache holds 16 KiB of data and 4-word blocks. Assume 32-bit addresses. How many bits are required in total?

A

16 KiB = 4096 = 212 words.
With a block size of 4 words, we have 210 blocks.

Therefore, we have a index of 10 bits.
We have an offset of 4 bits (2 to specify the block, and two to specify the byte)
We therefore have a tag size of 18 bits.

16KiB for data, and (1 + 18)*210 bits for rest.

Thus, 16 + 2.375 = 18.375 KiB

22
Q

Consider a cache with 64 blocks and a block size of 16 bytes. To what block number does byte address 1200 map?

A

Byte address 1200 will fall in the block numbered 1200/16 = 75.

75 mod 64 = 11

23
Q

Given a 4 KB, 4-way set associative cache with 4-byte blocks and 32-bit addresses, how many tag, index and offset bits does the address decompose into?

A

There are 4000 B of data, and as each block is 4B, there are 1000 blocks. These are grouped into sets of 4, so there are 250 sets.

Thus, we need 8 bits for the index.

We also need 2 bits for the offset, so the tag is (32 - (8 + 2)) = 22 bits.

24
Q

What is the write-through and write-back policy?

A

Write-through is when a hit occurs, the data is written to the cache, and then to memory.

Write-back is when a hit occurs, just the cache is updated. Each block has a dirty bit, set if the block has been written to. When a dirty is replaced, it is written to memory.

25
Q

Give an advantage and disadvantage of write-through over write-back.

A

Adv: Data in memory is always up-to-date.
Dis: Writes are slow.

26
Q

What are the write-allocate and write no-allocate policies?

A

Write-allocate: On a miss, bring the block into the cache and write to it.

Write-no-allocate: Do not bring the block into the cache; only modify data in memory.