You are on page 1of 7

Operating system (CS -204)

Assignment # 04
Topic Main Memory

Course Instructor: Rao Wakeel Ahmad


Issue Date: 14-July-2020
Submission Date: 19-July-2020

Registration# Name
Submitted by:
18-CS-47 Naeem Hussain

Department of Computer Science, University of Engineering


and Technology (UET) Taxila
Question 1: Name two differences between logical and physical addresses?

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.

Question 2: Why are page sizes always powers of 2?

Ans: Recall that paging is implemented by breaking up an address into a page


and offset number. It is most efficient to break the address into X page bits and Y
offset bits, rather than perform arithmetic on the address to calculate the page
number and offset. Because each bit position represents a power of 2, splitting an
address between bits results in a page size that is a power of 2.

Question 3: Consider a logical address space of 64 pages of 1,024 words each,


mapped onto a physical memory of 32 frames.

a. How many bits are there in the logical address?

b. How many bits are there in the physical address?

Ans: a. Logical address: 16 bits

b. Physical address: 15 bits

Question 4: Explain the difference between internal and external


fragmentation?

Ans: The Difference between them is shown in the following table:

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:

• M1=300 KB M2=600 KB M3=350 KB M4=200 KB M5=750 KB M6=125 KB

• P1=115 KB P2=500 KB P3=358 KB P4=200 KB P5=375 KB

First-fit:

– P1 = 115 M1=300 M2=600 M3=350 M4=200 M5=750 M6=125

– P2 = 500 M1=185 M2=600 M3=350 M4=200 M5=750 M6=125

– P3 = 358 M1=185 M2=100 M3=350 M4=200 M5=750 M6=125

– P4 = 200 M1=185 M2=100 M3=350 M4=200 M5=392 M6=125

– P5 = 375 M1=185 M2=100 M3=150 M4=200 M5=392 M6=125

Best-fit :

– P1 = 115 M1=300 M2=600 M3=350 M4=200 M5=750 M6=125

– P2 = 500 M1=300 M2=600 M3=350 M4=200 M5=750 M6=10

3|Page
– P3 = 358 M1=300 M2=100 M3=350 M4=200 M5=750 M6=10

– P4 = 200 M1=300 M2=100 M3=350 M4=200 M5=392 M6=10

– P5 = 375 M1=300 M2=100 M3=350 M4=000 M5=392 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.

a. If a memory reference takes 50 nanoseconds, how long does a paged


memory reference take?
b. If we add TLBs, and 75 percent of all page-table references are found in
the TLBs, what is the effective memory reference time? (Assume that
finding a page-table entry in the TLBs takes 2 nanoseconds, if the entry is
present.)

Ans:

a. 50 x 2 = 100 seconds
b. Effective Time = 0.75 x (50ns+2ns) + 0.25 x (100ns+2ns)
=64.5ns

Question 8: Consider the reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3,


2, 1, 2, 3, 6 Simulate the operation of each page replacement algorithm assuming
5 frames.

Ans: Summary - FIFO algorithm

 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%

Summary - LRU algorithm

 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

You might also like