Navi

Solve the Mapping Function Question


Solve the Mapping Function Question:
Question 1
A computer system has a memory architecture made up of a main memory of 128 MB and
cache of 128 KB. In order to perform an efficient mapping function, the main memory is
arranged in block of 8 bytes. Draw the address structure for the different mapping functions as
below. (Indicate the fields and the number of bits required for each field.)

-Direct Mapping 

From the question, we know that:

Main memory = 128 MB = (128 x 1024 ) KB = (128 x 1024 x 1024 ) Bytes
Cache capacity = 128 KB = (128 x 1024 ) Bytes
Block capacity = 8 Bytes

Step 1:
Using "log A(Bytes) / log 2" to convert bytes to bits.

Main Memory = log (128 x 1024 x 1024 ) / log 2 = 27 bits

Lines in Cache = Cache capacity / Block Capacity =( 128 x 1024 ) / 8 =( 16 x 1024 ) bytes.
Convert it into bits. 
Lines in Cache =  (16 x 1024 ) bytes = log ( 16 x 1024 ) / log 2 =14 bits.

Block Capacity(Size) = 8 Bytes = log (8) / log (2) = 3 bits.

Step 2:
Find the Line, Tag and Word.


r = lines in cache, w = block size(capacity), s = main memory address length - block size.

r = 14 bits 
w = 3 bits
s = 27- 3 = 24 bits

Tag = s - r = 24 - 14 = 10 bits.

Step 3:
Finish the address structure.



Step 4:
Check the total ( tag + line + word) =main memory address length.
10(tag)+14(line)+3(word)=27(main memory address length).
If yes, mean that you do it correctly.
If no, maybe your calculation in the previous steps got problems.




-Associative Mapping

Main memory = 128 MB = (128 x 1024 ) KB = (128 x 1024 x 1024 ) Bytes
Cache capacity = 128 KB = (128 x 1024 ) Bytes
Block capacity = 8 Bytes

Step 1:
Using "log A(Bytes) / log 2" to convert bytes to bits.
Main Memory = log (128 x 1024 x 1024 ) / log 2 = 27 bits
Lines in Cache = Undetermined
Block Capacity(Size) = 8 Bytes = log (8) / log (2) = 3 bits.

Step 2:
Find the value of address structure.



s (tag) = main memory address length - block size , w = block size.
w = 3
s = 27 -3
s = 24

Step 3:
Finish the address structure.


Step 4:
Check the total ( tag + word) =main memory address length.
24(tag)+3(word)=27(main memory address length).
If yes, mean that you do it correctly.
If no, maybe your calculation in the previous steps got problems.


-'K' Way Set Associative Mapping
Main memory = 128 MB = (128 x 1024 ) KB = (128 x 1024 x 1024 ) Bytes
Cache capacity = 128 KB = (128 x 1024 ) Bytes
Block capacity = 8 Bytes

Let's say this is the 4 way set associative mapping.
So, k = 4.


Step 1:
Using "log A(Bytes) / log 2" to convert bytes to bits.

Main Memory = log (128 x 1024 x 1024 ) / log 2 = 27 bits

Lines in Cache = Cache capacity / Block Capacity =( 128 x 1024 ) / 8 =( 16 x 1024 ) bytes.

As there is 4 way set associative.
So, number of lines in set (k) is 4 .

Number of sets = d
Number of lines in cache(r) = k * d
So, we want to find the number of sets.
r = k * v,
d = r / k.

Number of sets = ( 16 x 1024 ) bytes / 4  = (4 x 1024 ) bytes
Convert it into bits. 
Number of sets =  (16 x 1024 ) bytes = log ( 4 x 1024 ) / log 2 =12 bits.

Block Capacity(Size) = 8 Bytes = log (8) / log (2) = 3 bits.


Step 2:
Find the value of address structure.


d = number of sets, w = block size(capacity), s = main memory address length - block size.
d = 12 bits 
w = 3 bits
s = 27- 3 = 24 bits
Tag = s - r = 24 - 12 = 12 bits.
Step 3:
Finish the address structure.


Step 4:
Check the total ( tag +set + word) =main memory address length.
12(tag)+12(set)+3(word)=27(main memory address length).
If yes, mean that you do it correctly.
If no, maybe your calculation in the previous steps got problems.




That's the way to solve the mapping function question.
Hope your guys will understand my steps as well.
Thank you. =)


                                                                                                                                  Written by--®Ã¦Å‹










1 comment: