I recently asked this question over at stackoverflow, but I was told by a user that it was off-topic, so I am posting it here since it's more of a hardware question.
I'm trying to study for an exam and I'm trying to answer the question below.
I'll be honest, I've asked this question on here before, but now that I have a better understanding of it, I felt I should make a new question to fine-tune my understanding, since my question is somewhat different now.
Consider a virtual memory system with the following properties:
- 35-bit virtual address
- 16 KB pages
- 32-bit physical address
Assume that this virtual memory system is implemented with an eight-way set associative TLB. The TLB has total of 256 TLB entries, with each TLB entry representing one virtual-to-physical page number translation.
A 64 KB data cache is a two-way set associative cache. The data cache’s block size is 128 Bytes.
Show the virtual to physical mapping with a figure drawn in a way similar to the figure below (but with all necessary changes required for the TLB and the data cache specified in this question).
Specify the width of all fields and signals coming in and out of (as well as the number of comparisons done by) the TLB and the data cache for each memory address.
So far, I've come up with the following: (Direct link here for larger image)
I've come up with this:
In case you're curious about the font, it's called Waltograph, a TTF I downloaded from the web, it was set as the default in paint, so I decided to enlighten my studying with some Disney magic.
Anyway, since the problem states that we have 16KB pages (\$2^4 \cdot 2^6 = 2^{\textbf{14}}\$ byte pages), we then need an offset of 14 bits as indicated in my schematic.
Then, since I have a total of 256 TLB entries and an 8-way associative TLB, we need an index of 5 bits wide (\$256/8 = 32 = 2^{\textbf{5}}\$). Then whatever is left over is used for the tag as indicated.
Then I have 8 comparators, as shown, which compare each tag at some index to the specified one. The result is put through an and gate with the valid bit to determine if we have a hit or not (I put the outputs of the and gate through an or gate to concatenate it into one signal)
Once we know we have a hit, we need to extract the data (physical address) from the TLB. I used a one-hot mux to select the physical address of the desired TLB entry. Then the output of the physical address is concatenated with the offset from the virtual address.
Now what I'm confused about is the cache part. I understand that the TLB is essentially a cache of most recently used physical addresses. However, I don't understand what's going on in the book's diagram. It suddenly splits up the physical address and uses it to index the cache, I guess. But why is it showing the cache and data separately? and why is the byte offset just left floating? I'm pretty sure the cache is supposed to store data as well. I don't think its sole purpose is to determine whether or not there's a hit or miss inside of it. I apologize for my ignorance in advance, but the book barely covers TLB's (it's like a little more than a page) and it doesn't do a very good job at explaining the relationship between a TLB and cache.
I'd appreciate if somebody could verify what I've done so far and explain what cache has to do with this to me. Thanks.