edited by
43,374 views
91 91 votes

A computer uses $46\text{-bit}$ virtual address, $32\text{-bit}$ physical address, and a three–level paged page table organization. The page table base register stores the base address of the first-level table $\text{(T1)},$ which occupies exactly one page. Each entry of $\text{T1}$ stores the base address of a page of the second-level table $\text{(T2)}.$ Each entry of $\text{T2}$ stores the base address of a page of the third-level table $\text{(T3)}.$ Each entry of $\text{T3}$ stores a page table entry $\text{(PTE)}.$ The $\text{PTE}$ is $32\;\text{bits}$ in size. The processor used in the computer has a $1\;\textsf{MB}\; 16$ way set associative virtually indexed physically tagged cache. The cache block size is $64$ bytes.


What is the minimum number of page colours needed to guarantee that no two synonyms map to different sets in the processor cache of this computer?

  1. $2$
  2. $4$
  3. $8$
  4. $16$

9 Answers

Best answer
88 88 votes

Let the page size be $x$.

Since virtual address is $46$ bits, we have total number of pages $ = \frac{2^{46}}{x}$

We should have an entry for each page in last level page table which here is $T3$. So,

Number of entries in $T3$ (sum of entries across all possible $T3$ tables) $ = \frac{2^{46}}{x}$

Each entry takes $32$ bits $= 4$ bytes. So, total size of $T3$ tables $= \frac{2^{46}}{x} \times 4 = \frac{2^{48}}{x}$ bytes

Now, no. of $T3$ tables will be Total size of $T3$ tables/page table size  and for each of these page tables, we must have a $T2$ entry. Taking $T3$ size as page size, no. of entries across all $T2$ tables
$= \frac{\frac{2^{48}}{x}}{x} = \frac{2^{48}}{x^2} $

Now, no. of $T2$ tables (assuming $T2$ size as pagesize) $= \frac{2^{48}}{x^2}  \times 4$ bytes = $\frac{\frac{2^{50}}{x^2}} {x}  = \frac{2^{50}}{x^3}$.

Now, for each of these page table, we must have an entry in $T1$. So, number of entries in $T1$

$=\frac{2^{50}}{x^3}$

And size of $T1 =\frac{2^{50}}{x^3} \times 4  =\frac{2^{52}}{x^3} $

Given in question, size of $T1$ is page size which we took as $x$. So,

$x = \frac{2^{52}}{x^3}$

$\implies x^4 =2^{52}$

$\implies x = 2^{13} = 8\;\textsf{KB}$

Min. no. of page color bits $=$ No. of set index bits $+$ no. of offset bits $-$ no. of page index bits (This ensures no synonym maps to different sets in the cache)

We have $1\;\textsf{MB}$ cache and $64\;\textsf{B}$ cache block size. So,

number of sets $= 1\;\textsf{MB}/(64\;\textsf{B} \times$ Number of blocks in each set$) = 16\;\textsf{K}/16 (16$ way set associative) $= 1\;\textsf{K} = 2^{10}.$

So, we need $10$ index bits. Now, each block being $64 (2^6)$ bytes means we need $6$ offset bits. 

And we already found page size $= 8\;\textsf{KB} = 2^{13}$, so $13$ bits to index a page

Thus, no. of page color bits $= 10 + 6 - 13 = 3. $

With $3$ page color bits we need to have $2^3 = 8$ different page colors

More Explanation: 

A synonym is a physical page having multiple virtual addresses referring to it. So, what we want is no two synonym virtual addresses to map to two different sets, which would mean a physical page could be in two different cache sets. This problem never occurs in a physically indexed cache as indexing happens via physical address bits and so one physical page can never go to two different sets in cache. In virtually indexed cache, we can avoid this problem by ensuring that the bits used for locating a cache block (index+offset) of the virtual and physical addresses are the same. 

In our case we have $6$ offset bits $+ 10$ bits for indexing. So, we want to make these $16$ bits same for both physical and virtual address. One thing is that the page offset bits $- 13$ bits for $8\;\textsf{KB}$ page, is always the same for physical and virtual addresses as they are never translated. So, we don't need to make these $13$ bits same. We have to only make the remaining $10 + 6 - 13 = 3$ bits same. Page coloring is a way to do this. Here, all the physical pages are colored and a physical page of one color is mapped to a virtual address by OS in such a way that a set in cache always gets pages of the same color. So, in order to make the $3$ bits same, we take all combinations of it $(2^3 = 8)$ and colors the physical pages with $8$ colors and a cache set always gets a page of one color only. (In page coloring, it is the job of OS to ensure that the $3$ bits are the same).   

Correct Answer: $C$

edited by
10 10 votes

Hope this helps

https://www.cse.iitk.ac.in/users/biswap/CS422/L19-VC.pdf

 

The second image is what has happened in our solution

The index + offset bits which is 10+6 i.e. 16 exceeded the Block offset (13) by exactly 3 bits

so we have to borrow these 3 bits from the Virtual page number of the Virtual Memory

That is why the answer to this is 3 bits.

That means different page colors are enough to solve the synonym problem,

Thanks

8 8 votes

1 MB 16-way set associative virtually indexed physically tagged cache(VIPT).
The cache block size is 64 bytes.

4 4 votes

Step 1: Determine the Page Size

Let the page size be $2^p$ bytes.

Since T1 occupies exactly one page and each entry is 4 bytes (32 bits), the number of entries in T1 is:

\[
\frac{2^p}{4} = 2^{p-2}
\]

Thus, the number of bits needed to index T1 is $ p - 2 $. Similarly, since T2 and T3 are also paged and use the same entry size, each level uses $ p - 2 $ bits of the virtual page number.

The virtual address is 46 bits. The page offset consumes $ p $ bits, leaving $ 46 - p $ bits for the virtual page number. Therefore:

\[
3(p - 2) = 46 - p
\]

Solving:

$$\displaylines{3p - 6 = 46 - p \\4p = 52 
p = 13}$$

Thus, the page size is $ 2^{13} $ bytes, or 8 KB.

 

Step 2: Cache Parameters

Cache size = $ 2^{20} $ bytes  

Block size = $ 2^6 $ bytes  

Number of blocks = $ \frac{2^{20}}{2^6} = 2^{14} $  

Associativity = 16 = $ 2^4 $  

Number of sets = $ \frac{2^{14}}{2^4} = 2^{10} = 1024 $

Hence, the cache requires 10 bits to select a set. Since the cache is virtually indexed, these 10 bits are derived from the virtual address.

 

Step 3: Virtual Address Bit Allocation

With page size $ 2^{13} $, the page offset is 13 bits.  

With block size $ 2^6 $, the block offset is 6 bits.  

Thus, the number of bits within the page used to select a cache block (i.e., block index within page) is:

\[
13 - 6 = 7 \text{ bits}
\]

 

In a virtually indexed cache, the 10 index bits are typically taken from virtual address bits [15:6], which includes:

Bits [12:6]: 7 bits from the page offset (same in physical address for synonyms) i.e safe bits ( meaning 6-12 bit no lie with boundary of page size of VA )

Bits [15:13]: 3 bits  from the virtual page number (may differ across synonyms) i.e dangerous bits

 

Step 4: Synonym Problem and Page Coloring

Two virtual addresses mapping to the same physical page are called synonyms. In a VIPT cache, if synonyms differ in the virtual address bits used for indexing, they may be directed to different cache sets, leading to coherence or performance issues.

To prevent this, page coloring is employed: physical pages are assigned colors corresponding to specific values of the dangerous bits. The operating system ensures that a physical page is mapped only to virtual pages whose virtual addresses have matching dangerous bits.

The number of distinct values for the dangerous bits determines the number of colors required.

 

Step 5 : Compute Minimum Number of Colors

The dangerous bits are bits [15:13] of the virtual address 3 bits in total.

Number of distinct patterns = $ 2^3 = 8 $

Thus, the minimum number of page colors required is 8.

 

Final Answer

\[
\boxed{8}
\]

 

0 0 votes

We need to find the size of one "Way" (also called the Direct-Mapped portion size) to see if it exceeds the Page Size.

Size of One way = Cache size / Associativity = 2^20/2^4= 2^16 = 64KB

Calculate the Number of Page Colors The synonym problem occurs when the cache index bits overlap with the Virtual Page Number (VPN). The number of "colors" required corresponds to how many times the Page Size fits into the Cache Way Size.

Number of colours = Size of One way / page size = 64KB/8KB = 8

 

Alternatively, using bits:

index bits needed = 10

Total bits for index+offset = 10 + 6 = 16 bits
Page offset provided 13 bits
overlap = 16-13 = 3bits
colours = 2^3 = 8

 

Answer:
Position:
Show:

Related questions

157 157 votes
7 answers 7 answers
57.5k
57.5k views
kanikool asked Sep 10, 2014
57,543 views
A computer uses $46\text{-bit}$ virtual address, $32\text{-bit}$ physical address, and a three–level paged page table organization. The page table base register stores th...
183 183 votes
11 answers 11 answers
47.5k
47.5k views
Arjun asked Sep 24, 2014
47,504 views
A certain computation generates two arrays a and b such that $a[i] = f(i)$ for $0 \leq i < n$ and $b[i] = g(a[i])$ for $0 \leq i < n$. Suppose this computation is decompo...
95 95 votes
10 answers 10 answers
38.2k
38.2k views
Arjun asked Sep 24, 2014
38,241 views
A shared variable $x$, initialized to zero, is operated on by four concurrent processes $W, X, Y, Z$ as follows. Each of the processes $W$ and $X$ reads $x$ from memory, ...
116 116 votes
11 answers 11 answers
48.8k
48.8k views
Arjun asked Sep 24, 2014
48,813 views
Consider a hard disk with $16$ recording surfaces $(0-15)$ having $16384$ cylinders $(0-16383)$ and each cylinder contains $64$ sectors $(0-63)$. Data storage capacity in...