Professional Documents
Culture Documents
Assignment # 04
Topic Main Memory
Registration# Name
Submitted by:
18-CS-47 Naeem Hussain
Ans: A logical address does not refer to an actual existing address; rather, it
refers to an abstract address in an abstract address space. Contrast this with a
physical address that refers to an actual physical address in memory. A logical
address is generated by the CPU and is translated into a physical address by the
memory management unit(MMU). Therefore, physical addresses are generated by
the MMU.
2|Page
Question 5: Given six memory partitions of 300 KB, 600 KB, 350 KB, 200
KB, 750 KB, and 125 KB (in order), how would the first-fit, best-fit, and worst-fit
algorithms place processes of size 115 KB, 500 KB, 358 KB, 200 KB, and 375
KB (in order)? Rank the algorithms in terms of how efficiently they use memory.
Ans:
First-fit:
Best-fit :
3|Page
– P3 = 358 M1=300 M2=100 M3=350 M4=200 M5=750 M6=10
Question 6: Assuming a 1-KB page size, what are the page numbers and
offsets for the following address references (provided as decimal numbers):
a. 3085
b. 42095
c. 215201
d. 650000
e. 2000001
Ans:
a. 3085 as decimal
i. Binary no. = 110000001101
ii. Page no. = 011 = 3
iii. Page offset = 0000001101 = 13
b. 42095 as decimal
i. Binary no. = 1010010001101111
ii. Page no. = 101001 = 41
iii. Page offset = 00011011111 = 111
c. 215201 as decimal
i. Binary no. = 110100100010100001
ii. Page no. = 110110010 = 210
iii. Page offset = 0010100001 = 161
d. 650000 as decimal
i. Binary no. = 10011110101100010000
ii. Page no. = 1001111010 = 634
iii. Page Offset = 1100010000 = 784
4|Page
e. 2000001 as decimal
i. Binary no. = 111101000010010000001
ii. Page no. = 11110100001 = 1953
iii. Page offset = 0010000001 = 129
Question 7: Consider a paging system with the page table stored in memory.
Ans:
a. 50 x 2 = 100 seconds
b. Effective Time = 0.75 x (50ns+2ns) + 0.25 x (100ns+2ns)
=64.5ns
Total frames: 5
Algorithm: FIFO
Reference string length: 20 references
String: 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Solution visualization
t 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
ref 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
f 1 2 3 4 4 4 5 6 6 1 2 3 7 7 7 7 7 7 7 7
f 1 2 3 3 3 4 5 5 6 1 2 3 3 3 3 3 3 3 3
f 1 2 2 2 3 4 4 5 6 1 2 2 2 2 2 2 2 2
f 1 1 1 2 3 3 4 5 6 1 1 1 1 1 1 1 1
f 1 2 2 3 4 5 6 6 6 6 6 6 6 6
5|Page
hit ✗ ✗ ✗ ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓ ✓ ✓ ✓ ✓ ✓ ✓
v 1 2 3 4 5
Total references: 20
Total distinct references: 7
Hits: 10
Faults: 10
Hit rate: 10/20 = 50%
Fault rate: 10/20 = 50%
Total frames: 5
Algorithm: LRU
Reference string length: 20 references
String: 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Solution visualization
t 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
ref 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
f 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
f 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3
f 1 2 3 4 2 1 5 6 6 1 2 3 7 6 3 3 1 2
f 1 1 3 4 2 1 5 5 6 1 2 2 7 6 6 6 1
f 3 4 4 4 4 5 6 1 1 1 7 7 7 7
hit ✗ ✗ ✗ ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✓ ✓ ✓ ✓ ✓ ✓
v 3 4 5
Total references: 20
Total distinct references: 7
Hits: 12
Faults: 8
Hit rate: 12/20 = 60%
Fault rate: 8/20 = 40%
6|Page
Summary - OPT algorithm
Total frames: 5
Algorithm: OPT
Reference string length: 20 references
String: 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
Solution visualization
t 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
ref 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
f 1 2 3 4 4 4 5 6 6 6 6 6 7 7 7 7 7 7 7 7
f 1 2 3 3 3 4 4 4 4 4 4 6 6 6 6 6 6 6 6
f 1 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3
f 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2
f 1 1 1 1 1 1 1 1 1 1 1 1 1 1
hit ✗ ✗ ✗ ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓ ✓ ✗ ✓ ✓ ✓ ✓ ✓ ✓ ✓
v 5 4
Total references: 20
Total distinct references: 7
Hits: 13
Faults: 7
Hit rate: 13/20 = 65%
Fault rate: 7/20 = 35%
7|Page