You are on page 1of 15

OPERATING SYSTEM ASSIGNMENT # 01

Memory Allocation
Problem:

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

[AUTHOR NAME] 1
OPERATING SYSTEM ASSIGNMENT # 01

Part A:
Available Memory Partitions:
100 KB, 500 KB, 200 KB, 300 KB, 400 KB, 500KB, 600KB, 700KB, 800KB, 900 KB and 1000KB

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)

[AUTHOR NAME] 2
OPERATING SYSTEM ASSIGNMENT # 01

900 KB 900 KB (P6)


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)

[AUTHOR NAME] 3
OPERATING SYSTEM ASSIGNMENT # 01

78KB,176KB,200KB,300KB,400KB,83KB,174KB,188KB,35KB,0KB,1000KB

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

[AUTHOR NAME] 4
OPERATING SYSTEM ASSIGNMENT # 01

Explanation
212KB is put in the Memory 300KB (Which is smallest available hole). (300 KB – 212KB = 88KB).

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

[AUTHOR NAME] 5
OPERATING SYSTEM ASSIGNMENT # 01

Worst Fit:

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).

[AUTHOR NAME] 6
OPERATING SYSTEM ASSIGNMENT # 01

100KB,500KB,200KB,300KB,400KB,500KB,600KB,700KB,688KB,483KB,788KB

426 KB is put in the Memory 782KB (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

900 KB Must wait!

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

765 KB Must Wait!

1 KB is put in the Memory 666KB. (Which is the largest available hole). (666KB – 1 KB = 666 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:

[AUTHOR NAME] 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).

12KB,456KB,200KB,300KB,400KB,500KB,600KB,700KB,800KB,900KB,1000KB

[AUTHOR NAME] 8
OPERATING SYSTEM ASSIGNMENT # 01

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:

[AUTHOR NAME] 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)
Explanation
300 KB 100 KB (P5)
44KB is put in the Memory 100KB
200 KB (Hole)
(Which is smallest 400 KB 400 KB (P6) available hole).

(100 KB – 44KB = 500 KB 400 KB (P8) 56KB).


100 KB (Hole)
56KB,500KB,200K B,300KB,400KB,5
600 KB
00KB,600KB,700K 700 KB B,800KB,900KB,1

000KB 800 KB
900 KB
44KB is put in the 1000 KB Memory 56KB

(Which is smallest available hole).

(56KB – 44 KB =12 KB).

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).

[AUTHOR NAME] 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:

[AUTHOR NAME] 11
OPERATING SYSTEM ASSIGNMENT # 01

MEMORY PROCESS
100 KB
Explanation
500 KB
44KB is put in the Memory 1000KB

(Which is the 200 KB largest available

hole). (1000 KB – 44KB = 956KB).


300 KB

400 KB
500 KB
600 KB
700 KB
800 KB 400 KB (P6)
400 KB (Hole)
900 KB 100 KB (P4)
400 KB (P7)
400 KB (Hole)
1000 KB 44 KB (P1)
44 KB (P2)
44 KB (P3)
100 KB (P5)
400 KB (P8)
368 KB (Hole)

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

[AUTHOR NAME] 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.

[AUTHOR NAME] 13

END!
OPERATING SYSTEM ASSIGNMENT # 01

[AUTHOR NAME] 14
OPERATING SYSTEM ASSIGNMENT # 01

[AUTHOR NAME] 15

You might also like