CS 105

Cache Practice Question

A Software Cache for a Hash Table

Suppose we have a machine with a 64 KB L1 data cache.

Our program uses a large hash table that maps 64-bit integer keys to float values. The table is much larger than the L1 cache, and we are worried that hash-table lookups will have poor locality.

Someone proposes building a small software-based cache for hash-table lookups. The cache should:

  • use at most 32 KB of memory total,
  • be 2-way set associative,
  • use a 64-bit hash value to decide where an entry goes,
  • store enough information to tell whether a lookup is a hit,
  • store a cached copy of the corresponding float value.

For this question, assume:

  • uint64_t is 8 bytes,
  • float is 4 bytes,
  • a simple cache entry will be padded/aligned to 16 bytes if it contains a uint64_t tag/hash and a float,
  • each set has 2 entries.

One possible entry type is:

typedef struct cache_entry {
    uint64_t tag;
    float value;
    uint8_t valid;
    // padding inserted by compiler
} cache_entry_t;

Assume sizeof(cache_entry_t) == 16.

How many total entries can this software cache contain while staying within the 32 KB budget?

Since the cache is 2-way set associative, how many sets does it have?

If the cache has 1024 sets, how many bits of the 64-bit hash should be used as the set index?

Suppose we use the low 10 bits of the hash as the set index. What information should we store in each cache entry so that we can tell whether a lookup is really a hit?

Assume this software cache uses:

  • the low 10 bits of the hash as the set index,
  • the full 64-bit hash as the stored tag,
  • two entries per set,
  • and a simple replacement policy where, on a miss, one of the two entries is overwritten.

Describe the steps for performing a lookup.

This software cache turns out to be of little or no practical help. Why?

Check all that apply.

(When logged in, completion status appears here.)