You are on page 1of 27

 Main memory is divided into 2 parts :one for the operating system and

the other part for user programs.


 In uniprogramming, there is OS in one part and the other part for the

program currently being executed.


 In a multi programming system, the user part of the memory must be

further subdivided to accommodate multiple processes.


 Degree of multiprogramming means the maximum number of

processes in the main memory.


 The memory management function of the OS:

1. Keeps track of which parts of memory are free and which are allocated.
2. It determines how memory is allocated among competing processes,
deciding who gets memory, and how much they are allowed.
3. When memory is allocated it determines which memory locations will
be assigned.
4. It tracks when memory is freed or unallocated and updates the status.
The basic memory management function of the OS is to bring
processes into main memory for execution by the processor.
1.Memory Partitioning :
Obsolete technique

a)Fixed Partitioning(Multiprogramming with fixed no. of tasks-MFT)


The user section of the MM is partitioned into regions of fixed sizes.

Two variations in fixed partitioning:

Equal Size Partitions:


The user memory is divided into partitions of fixed sizes.

Any process whose size is less than or equal to the partition size can

be loaded into any available partition.


If all partitions are full , the OS can swap a process out of any of the

partitions and load in any other process.


Fixed Partitioning of
a 64 MB memory
 Placement Algorithm:
As long as there are available partitions a process can be loaded in
any available partition.
Because all partitions are of equal size it does not matter which
partition is used.

 Drawbacks of fixed partitioning :


1. A program may be too big to fit into a partition.
2. Inefficient utilization of MM. A program can be small but occupies an
entire partition.
Eg: A program of 2 MB occupies an 8 MB partition.
Internal fragmentation – 6 MB
The wasted space internal to a partition due to the fact that the
block of data loaded is smaller than the partition is called internal
fragmentation.

Solution : Use unequal sized partitions


Unequal size partitions
 Placement algorithm with Unequal sized partitions :
Two possible ways :
1. Unequal size partitions, use of multiple
queues:
◦ assign each process to the smallest
partition within which it will fit.
◦ a queue exists for each partition size.
◦ tries to minimize internal fragmentation.
◦ problem: some queues might be empty
while some might be loaded.
Eg: There might be no processes with a
size between 12 and 16 M, hence that
partition remains unused.
For eg: Processes of size 11M,1M,9M
11M –Queue of partition of 12 M
1 M- Queue of partition of 2 M
9 M- Queue of partition of 10 M
2.
 Unequal-size partitions, use of a
single queue:

◦ when its time to load a process


into memory, the smallest
available partition that will hold
the process is selected.
◦ increases the level of
multiprogramming at the
expense of internal
fragmentation.
Eg : Queue contains
7M, 6M , 8M,1M ,9M,8M,5M
 Eg 7M, 6M , 8M,1M ,9M, 8M, 5M
Disadvantage of MFT :
 The number of active processes is limited by

the system
i.e. limited by the pre-determined number of
partitions
 A large number of very small process will not
use the space efficiently giving rise to internal
fragmentation.
◦ In either fixed or variable length partition methods
2. Dynamic Partitioning (Multprogramming with variable no. of tasks-MVT)
 Developed to overcome the difficulties with fixed Partitioning.
 Partitions are of variable length and number dictated by the size of
the process.
 A process is allocated exactly as much memory as required.
 Eg: 64 MB of MM. Initially MM is empty except for the OS
Memory Management Techniques
Eg Process 1 arrives of size 20 M.
•Next process 2 arrives of size 14 M.
•Next process 3 arrives of size 18 M
•Next process 4 arrives of size 8 M

Unused memory at the end of 4 M that is too small for process 4 of 8 M


•At some point later assume process 2 gets blocked.
•The OS swaps out process2 which leaves sufficient room for process4
Process 4 is loaded creating another small hole of 6 M
Memory Management Techniques
•Process 1 finishes execution on CPU.
•Hence OS swaps out Process 1
•Assume Process 2 gets unblocked.
•OS swaps in Process 2 creating another hole of 6 M
 MVT eventually leads to a situation in which there are
a lot of small holes in memory.
 This is called external fragmentation.
There are really two types of fragmentation:
1. Internal Fragmentation –
Allocated memory may be slightly larger than
requested memory; this size difference is memory
internal to a partition, but not being used.
2. External fragmentation – total memory space exists
to satisfy a request, but it is not contiguous; storage
is fragmented into a large number of small holes.
Note : MVT suffers from external fragmentation and
not internal fragmentation
From time to time the OS shifts the processes so that they are
contiguous and so that all the free memory is together in 1
block which may be sufficient to load an additional process.

Drawbacks of compaction:

 Time consuming due to relocation.

 Wastes the CPU time.


Dynamic Partitioning Placement Algorithm
 In Partition Allocation, when there is more than one partition

freely available to accommodate a process’s request, a


partition must be selected. To choose a particular partition, a
partition allocation method is needed. 
 i.e When a new process has to be brought in , the OS must

decide free block to allocate.


 Three placement algos for MVT :

1. Best fit

2. First fit

3. Next fit
1. Best fit
Chooses the block that is closest in size to the request.
It searches the entire list of holes to find the smallest
hole whose size is greater than or equal to the size of
the process. 
2.First fit
Scans memory form the beginning and chooses the
first available block that is large enough
3. Worst Fit Allocate the process to the partition which is the
largest sufficient among the freely available partitions available
in the main memory. It is opposite to the best-fit algorithm. It
searches the entire list of holes to find the largest hole and
allocate it to process.  
3. Next fit
Scans memory from the location of the last placement
Next fit is similar to the first fit but it will search for the first
sufficient partition from the last allocation point. 
Last block that was used was a 22 MB
block, from which 14 MB was used by
the process returning a hole of 8MB
Assuming now a program of size 16
MB had to be allocated memory.
 Performance of the three approaches :
1. Best fit
◦ Worst performer overall
◦ Since smallest block is found for process, the smallest amount of
fragmentation is left
◦ Memory compaction must be done more often

2. First fit
◦ Scans memory form the beginning and chooses the first available
block that is large enough
◦ Fastest
◦ May have many process loaded in the front end of memory that
must be searched over when trying to find a free block
3. Next fit
◦ Scans memory from the location of the last
placement
◦ More often allocate a block of memory at the end of
memory where the largest block is found

You might also like