Operating System Assignment
Operating System Assignment
Memory Allocation
Given ten memory partitions of 100 KB, 200 KB, 300 KB, 400 KB, 500KB, 600KB, 700KB, 800KB, 900 KB
and 1000KB (in order), how would the following algorithms
1. first-fit
2. best-fit,
3. worst-fit
place processes of
a. 212 KB, 417 KB, 112 KB, 426 KB, 512KB, 900KB, 22KB, 765KB and 1KB (in order).
b. 44 KB, 44 KB, 44 KB, 100 KB, 100 KB, 400 KB, 400 KB and 400KB (in order).
Draw the memory allocations for each of the above algorithms to show which algorithm is using efficient
memory for a & b.
Strategies
First fit
Best fit
Worst fit
First fit:
Allocating the first hole that is big enough
Searching the entire list of holes
Stop searching as soon as the large free hole is found
Best fit:
Allocating the smallest hole that is big enough
Searching the entire list
Stop searching as soon as the smallest leftover hole is found
Worst fit:
Allocating the largest hole
Searching the entire list
Produce the largest leftover hole
Part A:
SHOAIB TALIB 1
OPERATING SYSTEM ASSIGNMENT # 01
Set of Processes:
212 KB, 417 KB, 112 KB, 426 KB, 512KB, 900KB, 22KB, 765KB and 1KB
First Fit:
MEMORY PROCESS
22 KB (P7)
100 KB 1 KB (P9)
77 KB (Hole)
212 KB (P1)
500 KB 112 KB (P3)
176 KB (Hole)
200 KB
300 KB
400 KB
500 KB 417 KB (P2)
83 KB (Hole)
600 KB 426 KB (P4)
174 KB (Hole)
700 KB 512 KB (P5)
188 KB (Hole)
800 KB 765 KB (P8)
35 KB (Hole)
900 KB 900 KB (P6)
SHOAIB TALIB 2
OPERATING SYSTEM ASSIGNMENT # 01
1000 KB
Explanation
212KB is put in the Memory 500KB (Which is the first available big hole). (500 KB – 212KB = 288KB).
100KB,288KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
417KB is put in the Memory 500KB (Which is the first available big hole). (500KB – 417 KB =83 KB).
100KB,288KB,200KB,300KB,400KB,83KB,600KB,700KB,800KB,900KB,1000KB
112 KB is put in the Memory 288KB (Which is the first available big hole). (282KB – 112 KB = 176 KB).
100KB,176KB,200KB,300KB,400KB,83KB,600KB,700KB,800KB,900KB,1000KB
426 KB is put in the Memory 600KB (Which is first available hole). (600KB – 426 KB = 174 KB).
100KB,176KB,200KB,300KB,400KB,83KB,174KB,700KB,800KB,900KB,1000KB
512KB is put in the Memory 700KB. (Which is first available hole). (700KB – 512 KB = 188 KB).
100KB,176KB,200KB,300KB,400KB,83KB,174KB,188KB,800KB,900KB,1000KB
900 KB Is put in the Memory 900KB. (Which is first available hole). (900KB – 900 KB =0KB)
100KB,176KB,200KB,300KB,400KB,83KB,174KB,188KB,800KB, 0KB,1000KB
22KB is put in the Memory 100KB. (Which is first available hole). (100KB -22KB = 78KB).
78KB,176KB,200KB,300KB,400KB,83KB,174KB,188KB,800KB,0KB,1000KB
765 KB is put in the Memory 800KB (Which is first available hole). (800KB – 765KB = 35KB)
78KB,176KB,200KB,300KB,400KB,83KB,174KB,188KB,35KB,0KB,1000KB
SHOAIB TALIB 3
OPERATING SYSTEM ASSIGNMENT # 01
1KB is put in the Memory 78KB (Which is first available hole). (78KB – 1 KB =77 KB)
77KB,176KB,200KB,300KB,400KB,83KB,174KB,188KB,35KB,0KB,1000KB
Best Fit:
MEMORY PROCESS
100 KB
500 KB 417 KB (P2)
83 KB (Hole)
200 KB 112 KB (P3)
88 KB (Hole)
300 KB 212 KB(P1)
88KB(Hole)
400KB
500 KB 426 KB (P4)
22 KB (P7)
52 KB (Hole)
600 KB 512 KB (P5)
88 KB (Hole)
700 KB
800 KB 765 KB (P8)
1 KB (P9)
34 KB (Hole)
900 KB 900 KB (P6)
1000 KB
Explanation
212KB is put in the Memory 300KB (Which is smallest available hole). (300 KB – 212KB = 88KB).
SHOAIB TALIB 4
OPERATING SYSTEM ASSIGNMENT # 01
100KB,500KB,200KB,88KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
417KB is put in the Memory 500KB (Which is smallest available hole). (500KB – 417 KB =83 KB).
100KB,83KB,200KB,88KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
112 KB is put in the Memory 200KB (Which is smallest available hole). (200KB – 112 KB = 88 KB).
100KB,83KB,88KB,88KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
426 KB is put in the Memory 500KB (Which is smallest available hole). (500KB – 426 KB = 74 KB).
100KB,83KB,88KB,88KB,400KB,74KB,600KB,700KB,800KB,900KB,1000KB
512KB is put in the Memory 600KB. (Which is smallest available hole). (600KB – 512 KB = 88 KB).
100KB,83KB,88KB,88KB,400KB,74KB,88KB,700KB,800KB,900KB,1000KB
900 KB Is put in the Memory 900KB. (Which is smallest available hole). (900KB – 900 KB =0KB)
100KB,83KB,88KB,88KB,400KB,74KB,88KB,700KB,800KB,0KB,1000KB
22KB is put in the Memory 74KB. (Which is smallest available hole). (74KB -22KB = 52KB).
100KB,83KB,88KB,88KB,400KB,52KB,88KB,700KB,800KB,0KB,1000KB
765 KB is put in the Memory 800KB (Which is smallest available hole). (800KB – 765KB = 35KB)
100KB,83KB,88KB,88KB,400KB,52KB,88KB,700KB,35KB,0KB,1000KB
1KB is put in the Memory 35KB (Which is first available hole). (35KB – 1 KB =34 KB)
100KB,83KB,88KB,88KB,400KB,52KB,88KB,700KB,34KB,0KB,1000KB
Worst Fit:
SHOAIB TALIB 5
OPERATING SYSTEM ASSIGNMENT # 01
MEMORY PROCESS
100 KB
500 KB
200 KB
300 KB
400 KB
500 KB
600 KB
700 KB 512 KB (P5)
188 KB (Hole)
800 KB 112 KB (P3)
22 KB (P7)
1 KB (P9)
665 KB (Hole)
900 KB 417 KB (P2)
483 KB (Hole)
1000 KB 212 KB (P1)
426 KB (P4)
362 KB (Hole)
Explanation
212KB is put in the Memory 1000KB (Which is the largest available hole). (1000 KB – 212KB = 788KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,788KB
417KB is put in the Memory 900KB (Which is the largest available hole). (900KB – 417 KB =483 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,483KB,788KB
112 KB is put in the Memory 800KB (Which is the largest available hole). (800KB – 112 KB = 688 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,688KB,483KB,788KB
SHOAIB TALIB 6
OPERATING SYSTEM ASSIGNMENT # 01
426 KB is put in the Memory 788KB (Which is the largest available hole). (788KB – 426 KB = 362 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,688KB,483KB,362KB
512KB is put in the Memory 700KB. (Which is the largest available hole). (700KB – 512 KB = 188 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,188KB,688KB,483KB,362KB
22KB is put in the Memory 688KB. (Which is the largest available hole). (688KB – 22 KB = 666 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,188KB,666KB,483KB,362KB
1 KB is put in the Memory 666KB. (Which is the largest available hole). (666KB – 1 KB = 665 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,188KB,665KB,483KB,362KB
Part B:
Available Memory Partitions:
100 KB, 500 KB, 200 KB, 300 KB, 400 KB, 500KB, 600KB, 700KB, 800KB, 900 KB and 1000KB
Set of Processes:
44 KB, 44 KB, 44 KB, 100 KB, 100 KB, 400 KB, 400 KB and 400KB
First Fit:
SHOAIB TALIB 7
OPERATING SYSTEM ASSIGNMENT # 01
MEMORY PROCESS
100 KB 44 KB (P1)
44 KB (P2)
12 KB (Hole)
500 KB 44 KB (P3)
100 KB (P4)
100 KB (P5)
256 KB (hole)
200 KB
300 KB
400 KB 400 KB (P6)
500 KB 400 KB (P7)
100 KB (Hole)
600 KB 400 KB (P8)
200 KB (Hole)
700 KB
800 KB
900 KB
1000 KB
Explanation
44KB is put in the Memory 100KB (Which is the first available big hole). (100 KB – 44KB = 56KB).
56KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
44KB is put in the Memory 56KB (Which is the first available big hole). (56KB – 44 KB =12 KB).
12KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
44 KB is put in the Memory 500KB (Which is the first available big hole). (500KB – 44 KB = 456 KB).
SHOAIB TALIB 8
OPERATING SYSTEM ASSIGNMENT # 01
12KB,456KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
100 KB is put in the Memory 456KB (Which is first available hole). (456KB – 100 KB = 356 KB).
12KB,356KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
100 KB is put in the Memory 356KB (Which is first available hole). (356KB – 100 KB = 256 KB).
12KB,256KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
400 KB is put in the Memory 400KB (Which is first available hole). 400KB – 400 KB=0KB).
12KB,256KB,200KB,300KB, 0KB,500KB,600KB,700KB,800KB,900KB,1000KB
400KB is put in the Memory 500KB. (Which is first available hole). (500KB -400KB = 100KB).
12KB,256KB,200KB,300KB, 0KB,100KB,600KB,700KB,800KB,900KB,1000KB
400KB is put in the Memory 600KB. (Which is first available hole). (600KB -400KB = 200KB).
12KB,256KB,200KB,300KB, 0KB,100KB,200KB,700KB,800KB,900KB,1000KB
Best Fit:
SHOAIB TALIB 9
OPERATING SYSTEM ASSIGNMENT # 01
MEMORY PROCESS
100 KB 44 KB (P1)
44 KB (P2)
12 KB (Hole)
500 KB 400 KB (P7)
100 KB (Hole)
200 KB 44 KB (P3)
100 KB (P4)
56 KB (Hole)
300 KB 100 KB (P5)
Explanation 200 KB (Hole)
44KB is put in the 400 KB 400 KB (P6) Memory 100KB
(100 KB – 44KB =
100 KB (Hole) 56KB).
600 KB
56KB,500KB,200K 700 KB B,300KB,400KB,5
12KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
44 KB is put in the Memory 200KB (Which is smallest available hole). (200KB – 44 KB = 156 KB).
12KB,500KB,156KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
100 KB is put in the Memory 156KB (Which is smallest available hole). (156KB – 100 KB = 56 KB).
SHOAIB TALIB 10
OPERATING SYSTEM ASSIGNMENT # 01
12KB,500KB,56KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
100 KB is put in the Memory 300KB (Which is smallest available hole). (300KB – 100 KB = 200 KB).
12KB,500KB,56KB,200KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB
400 KB is put in the Memory 400KB (Which is smallest available hole). 400KB – 400 KB=0KB).
12KB,500KB,56KB,200KB,0KB,500KB,600KB,700KB,800KB,900KB,1000KB
400KB is put in the Memory 500KB. (Which is smallest available hole). (500KB -400KB = 100KB).
12KB,500KB,56KB,200KB, 0KB,100KB,600KB,700KB,800KB,900KB,1000KB
400KB is put in the Memory 500KB. (Which is first available hole). (500KB -400KB = 100KB).
12KB,100KB,56KB,200KB, 0KB,100KB,600KB,700KB,800KB,900KB,1000KB
Worst Fit:
SHOAIB TALIB 11
OPERATING SYSTEM ASSIGNMENT # 01
MEMORY PROCESS
100 KB
500 KB
Explanation 200 KB
44KB is put in the Memory 1000KB
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,956KB
44KB is put in the Memory 956KB (Which is the largest available hole). (956KB – 44 KB =912 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,912KB
SHOAIB TALIB 12
OPERATING SYSTEM ASSIGNMENT # 01
44 KB is put in the Memory 912KB (Which is the largest available hole). (912KB – 44 KB = 868 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,868KB
100 KB is put in the Memory 900KB (Which is the largest available hole). (900KB – 100 KB = 800 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,800KB,868KB
100 KB is put in the Memory 868KB (Which is the largest available hole). (868KB – 100 KB = 768 KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,800KB,768KB
400 KB is put in the Memory 800KB (Which is the largest available hole). (800KB – 400 KB=400KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,400KB,800KB,768KB
400KB is put in the Memory 800KB. (Which is the largest available hole). (800KB -400KB = 400KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,400KB,400KB,768KB
400KB is put in the Memory 768KB. (Which is the largest available hole). (768KB -400KB = 368KB).
100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,400KB,400KB,368KB
Conclusion:
In all the three algorithms, BEST FIT is most efficient. At first sight it looks like the First fit is most
efficient which is the fastest among all the three algorithms, but it is not actually not efficient in the
memory usage! Rather than comparing to the all the holes it allocates the nearest larger hole to the
process. Here starvation could possible for the process who are larger in size. On the other hand, the
Worst fit Is the least or not efficient method. Here due to the improper usage of the memory causes the
starvation for the processes like in the example A for the process 900 KB,765 KB are in waiting state.
Whereas the Best Fit compares the process to the all available holes and assign the smallest hole which
THE
ensures the proper usage of the memory.
SHOAIB TALIB 13
END!
OPERATING SYSTEM ASSIGNMENT # 01
SHOAIB TALIB 14
OPERATING SYSTEM ASSIGNMENT # 01
SHOAIB TALIB 15