Title: CS544 / 03-memory
Tags: cs544-memory

Q: Before a CPU can add two values in RAM, what must it do?
A: Load those values to CPU registers

Q: Which CPU cache level is fastest, of L1, L2, L3?
A: L1

Q: Which CPU cache level is biggest, of L1, L2, L3?
A: L3

Q: When data in a cache is too old and no longer valid, we say it is _______
A: stale

Q: What does FIFO stand for?
A: First In First Out

Q: What does LRU stand for?
A: Least Recently Used

Q: How are FIFO and LRU similar?  How are they different?
A: They are the same for a miss: the data is added to the cache, in the "newest" position.
They are different for a hit: FIFO does not change how it prioritizes the item, but LRU resets it to the "newest" position.

Q: What do you call it when you find an item in a cache?
A: "hit"

Q: What do you call it when you CANNOT find an item in a cache?
A: "miss"

Q: What is a pattern where a random eviction policy would beat LRU and FIFO?
A: A common pattern is that the data is too big to fit completely in cache, and the program loops, repeatedly reading over the dataset in the same order.  LRU and FIFO will have a 0% hit rate, but random will at least get some hits.

Q: What is the name for a piece of data loaded to CPU cache?
A: cache line

Q: What is the most common cache line size for modern CPUs?
A: 64 bytes is common (other sizes like 128 used to be more common; new Macs haved started using 128 again)

Q: If you want to sum over column in a numpy matrix in a cache friendly way, how should you create the array?
A: First create an array where each column is actually stored as a row in the matrix.  Then transpose it.  This will get you columns that are contiguous in memory, resulting in fewer cache lines being loaded as the data is scanned.

Q: How does PyArrow indicate which strings/ints/etc are null/None in an array?
A: validity bitmap: 1 means valid, 0 means null/None

Q: How can you add a region to your virtual address space that is not backed by a file?
A: anonymous mmap

Q: How can you map a file into your virtual address space?
A: Open the file, get the f.fileno(), and pass it to mmap.

Q: If you want to be able to evict pages in anonymously mmap'd regions, what do you need to do?
A: enable a swap file in Linux