Professional Documents
Culture Documents
address true
Address>= memory
CCPU fence
32 false
k
Memory
0
OS
40k
256 256
256 256
There are three algorithms for searching the list of free blocks for a specific amount of
memory.
First Fit : Allocate the first free block that is large enough for the new process. This is a
fast algorithm.
Best Fit : Allocate the smallest block among those that are large enough for the new
process. In this method, the OS has to search the entire list, or it can keep it sorted and
stop when it hits an entry which has a size larger than the size of new process. This
algorithm produces the smallest left over block. However, it requires more time for
searching all the list or sorting it.
Worst Fit : Allocate the largest block among those that are large enough for the new
process. Again a search of the entire list or sorting it is needed. This algorithm produces
the largest over block.
Example 3.1 Consider the following memory map and assume a new process P4 comes with a memory
requirement of 3 KB. Locate this process.
At this point, if a new process, P5 of 14K arrives, then it would wait if we used worst
fit algorithm, whereas it would be located in cases of the others.
Disadvantages of Fixed Partitioning
1. Internal Fragmentation
If the size of the process is lesser then the total size of the partition then some size of
the partition get wasted and remain unused. This is wastage of the memory and called
internal fragmentation.
As shown in the image below, the 4 MB partition is used to load only 3 MB process and
the remaining 1 MB got wasted.
2. External Fragmentation
The total unused space of various partitions cannot be used to load the processes
even though there is space available but not in the contiguous form.
As shown in the image below, the remaining 1 MB space of each partition cannot be
used as a unit to store a 4 MB process. Despite of the fact that the sufficient space is
available to load the process, process will not be loaded.
3. Limitation on the size of the process
If the process size is larger than the size of maximum sized partition then that process
cannot be loaded into the memory. Therefore, a limitation can be imposed on the
process size that is it cannot be larger than the size of the largest partition.
4. Degree of multiprogramming is less
Advantages of Dynamic Partitioning over fixed partitioning
1. No Internal Fragmentation
Given the fact that the partitions in dynamic partitioning are created according to the
need of the process, It is clear that there will not be any internal fragmentation because
there will not be any unused remaining space in the partition.
2. No Limitation on the size of the process
In Fixed partitioning, the process with the size greater than the size of the largest partition
could not be executed due to the lack of sufficient contiguous memory. Here, In Dynamic
partitioning, the process size can't be restricted since the partition size is decided
according to the process size.
3. Degree of multiprogramming is dynamic
Due to the absence of internal fragmentation, there will not be any unused space in the
partition hence more processes can be loaded in the memory at the same time.
Disadvantages of dynamic partitioning
External Fragmentation
Absence of internal fragmentation doesn't mean that there will not be external
fragmentation.
Complex Memory Allocation
In Fixed partitioning, the list of partitions is made once and will never change but in
dynamic partitioning, the allocation and deallocation is very complex since the partition
size will be varied every time when it is assigned to a new process. OS has to keep track
of all the partitions.
Due to the fact that the allocation and deallocation are done very frequently in
dynamic memory allocation and the partition size will be changed at each time, it is
going to be very difficult for OS to manage everything.
Compaction:
Compaction is a method to overcome the external fragmentation problem. All free blocks are brought
together as one large block of free space. Compaction requires dynamic relocation.
Certainly, compaction has a cost and selection of an optimal compaction strategy is difficult. One method
for compaction is swapping out those processes that are to be moved within the memory, and swapping
them into different memory locations.
Free Space Management Techniques
The memory space in the disk is limited. So we need to use the space of the deleted files for the allocation of
the new file.
The system maintains the free space list contains all the records of the free space disk block. These free blocks
are those which are not allocated to other file or directory.
When we create a file we first search for the free space in the memory and then check in the free space list for
the required amount of space that we require for our file.
If the free space is available then allocate this space to the new file. After that, the allocating space is deleted
from the free space list. Whenever we delete a file then its free memory space is added to the free space list.
The process of looking after and managing the free blocks of the disk is called free space
management. There are some methods or techniques to implement a free space list. These are as
follows:
•Bitmap
•Linked list
1. Bitmap
This technique is used to implement the free space management. When the free space is
implemented as the bitmap or bit vector then each block of the disk is represented by a bit. When
the block is free its bit is set to 1 and when the block is allocated the bit is set to 0.
The main advantage of the bitmap is it is relatively simple and efficient in finding the first free
block and also the consecutive free block in the disk. Many computers provide the bit
manipulation instruction which is used by the users.
For Example: Apple Macintosh operating system uses the bitmap method to allocate the disk
space.
Assume the following are free. Rest are allocated:
Advantages:
•This technique is relatively simple.
•This technique is very efficient to find the free space on the disk.
Disadvantages:
•This technique requires a special hardware support to find the first 1 in a word it is not 0.
•This technique is not useful for the larger disks.
2. Linked list
• This is another technique for free space management. In this linked list of all the
free block is maintained.
• In this, there is a head pointer which points the first free block of the list which
is kept in a special location on the disk.
• This block contains the pointer to the next block and the next block contain the
pointer of another next and this process is repeated.
• By using this disk it is not easy to search the free list. This technique is not
sufficient to traverse the list because we have to read each disk block that
requires I/O time.
Advantages:
•Whenever a file is to be allocated a free block, the operating system can
simply allocate the first block in free space list and move the head pointer to
the next free block in the list.
Disadvantages:
•Searching the free space list will be very time consuming; each block will have
to be read from the disk, which is read very slowly as compared to the main
memory.
•Not Efficient for faster access.