os exp8 b03
os exp8 b03
PART A
(PART A: TO BE REFFERED BY STUDENTS)
A-2 Prerequisite
Knowledge about C/C++ programming language. A.3
Outcome
A.4 Theory:
a. Concept of MVT and MFT memory management techniques
MFT (Multiprogramming with a Fixed number of Tasks) is one of the old memory management
techniques in which the memory is partitioned into fixed size partitions and each job is assigned
to a partition. The memory assigned to a partition does not change.
MVT (Multiprogramming with a Variable number of Tasks) is the memory management technique
in which each job gets just the amount of memory it needs. That is, the partitioning of memory is
dynamic and changes as jobs enter and leave the system. MVT is a more ``efficient'' user of
resources. MFT suffers with the problem of internal fragmentation and MVT suffers with external
fragmentation.
b. Concept of dynamic partitioning placement algorithms i.e. Best Fit, First Fit, Worst-Fit
etc.
First Fit:
In dynamic memory management, First Fit algorithm states that main memory (RAM) is
divided into many partitions of unequal sizes. When processes are generated in system,
they need to be placed in different partitions of memory. In this method while placing a
process, the first partition which is large enough to accommodate the process is selected.
Hence first free and sufficient size partition is used to place the process.
1. It is fast method since all partitions are not searched for placing a process.
2. Since first partition is selected there is increase in internal fragmentation.
2K 1
3K 2
3K 3
2K 4
.
Best Fit:
In dynamic memory management, Best Fit algorithm states that main memory (RAM) is
divided into many partitions of unequal sizes. When processes are generated in system,
they need to be placed in different partitions of memory. In this method while placing a
process, the first partition which is smallest of all which can to accommodate the process
is selected. Hence in all free and smallest size partition is used to place the process.
1. It is not faster method since all partitions are searched for placing a process.
2. Since smallest partition is selected there is great reduction in internal fragmentation.
.
2K 1
3K 2
3K 3
2K 4
Processes: P1 size 3K, P2 size 2K, P3 size 2K, P4 size 1K
Sequentially Placed in Partitions 2,1,4,3
Worst Fit:
In dynamic memory management, Worst Fit algorithm states that main memory (RAM) is
divided into many partitions of unequal sizes. When processes are generated in system,
they need to be placed in different partitions of memory. In this method while placing a
process, the first partition which is largest in all to is selected. Hence first free and largest
size partition is used to place the process.
3. It is not fast method since all partitions are searched for placing a process.
4. Since largest partition is selected there is increase in internal and external
fragmentation.
. 2K 1
3K 2
3K 3
2K 4
Processes: P1 size 3K, P2 size 2K, P3 size 2K, P4 size 1K
Sequentially Placed in Partitions 2,3,1,4
PART B
(PART B: TO BE COMPLETED BY STUDENTS)
#include <stdio.h>
#include <stdbool.h>
struct MemoryBlock {
int start;
int size; int
process;
};
MemoryBlock memory[MEMORY_SIZE];
void initializeMemory() {
memory[0].start = 0;
memory[0].size = MEMORY_SIZE;
memory[0].process = -1; // -1 indicates free memory }
void printMemory() {
printf("Memory:\n");
for (int i = 0; i < MEMORY_SIZE; i++) {
printf("[%d:%d] ", memory[i].start, memory[i].size);
}
printf("\n");
}
int main() {
initializeMemory();
printMemory();
return 0;
}
Dynamic Partitioning :
#include <stdio.h>
#include <stdlib.h>
struct MemoryBlock {
int start;
int size; int
process;
};
MemoryBlock memory[MEMORY_SIZE];
void initializeMemory() {
memory[0].start = 0;
memory[0].size = MEMORY_SIZE;
memory[0].process = -1; // -1 indicates free memory
}
void printMemory() {
printf("Memory:\n");
for (int i = 0; i < MEMORY_SIZE; i++) {
printf("[%d:%d] ", memory[i].start, memory[i].size);
}
printf("\n");
}
int findBestFitIndex(int size) {
int best_fit_index = -1; int min_size =
MEMORY_SIZE + 1; for (int i = 0; i <
MEMORY_SIZE; i++) {
if (memory[i].process == -1 && memory[i].size >= size && memory[i].size < min_size) {
best_fit_index = i; min_size = memory[i].size;
}
}
return best_fit_index;
}
int main() {
initializeMemory();
printMemory();
return 0;
}
B.2 Input and Output:
(input and output of the program)
B. Conclusion:
B. Question of Curiosity
(To be answered by student based on the practical performed and learning/observations)
1. Which is more optimized method from First Fit, Best Fit and Worst Fit?
Best fit is slower than first fit as it must search the entire list every time. It has also be shown that
best fit performs worse than first fit as it tends to leave lots of small gaps. Worst Fit : As best fit
leaves many small, useless holes it might be a good idea to always use the largest hole available.
Internal Fragmentation occurs when a process needs more space than the size of allotted memory
block or use less space. External Fragmentation occurs when a process is removed from the main
memory. Solution. Best Fit Block Search is the solution for internal fragmentation.
3. What are the memory partitioning methods?
Memory partitioning means dividing the main memory into chunks of the same or different sizes
so that they can be assigned to processes in the main memory. There are two types of memory
partitioning techniques: Fixed-sized memory partitioning. Variable-sized memory partitioning.
Both first-fit and best-fit strategies are good memory allocation strategies that allow the re-use of
memory. Both strategies have different strengths and weaknesses. Running Time: First-fit is
faster, allowing the searching for memory to stop immediately after finding a free-block of large
enough size.