Memory Management
Memory Management
Memory Management
MANAGEMENT
TOPICS COVERED
Introduction
Memory Management Techniques
Contiguous Techniques
Single Contiguous Memory Management
Fixed Partitioning
Variable Partitioning
Non-Contiguous Techniques
Paging
Segmentation
Non-contiguous Techniques
a method which allocates the memory space present in different locations to the
process as per it’s requirements
SINGLE CONTIGUOUS
MEMORY ALLOCATION
Simple allocation scheme
No multiprogramming
Entire available memory is allocated to a single
process
Main memory is divided into 2 contiguous regions:
One portion permanently allocated to OS
Remaining portion of memory is allocated to single
user process
Some part of memory gets wasted
SINGLE CONTIGUOUS
MEMORY ALLOCATION
Advantages:
Fast access time
Requires less memory
Easy to implement and use
Disadvantages:
No multi user facility
Memory is not fully utilised
Processor is also not fully utilised
User program is being limited to the size available in main memory
FIXED PARTITIONING
Number of partitions in memory are fixed but size of each partition may
or may not be same.
As it is contiguous allocation, hence no spanning is allowed.
Partition are made before execution or during system configure
simplest technique used to put more than one processes in the main
memory
FIXED PARTIONING
Advantages:
Easy to implement
Little OS overhead
Disadvantages:
Internal Fragmentation
External Fragmentation
Limited process size
Limitation on Degree of
Multiprogramming
INTERNAL FRAGMENTATION
Internal fragmentation happens when
the memory is split into mounted-sized
blocks.
Whenever process is requested for the
memory, the mounted-sized block is
allotted to it
In the case where the memory allotted
to the process is somewhat larger than
the memory requested, then the
difference between allotted and
requested memory is called internal
fragmentation
EXTERNAL FRAGMENTATION
External fragmentation happens
when there’s a sufficient quantity of
area within the memory to satisfy
the memory request of a process.
However, the process’s memory
request cannot be fulfilled because
the memory offered is in a non-
contiguous manner.
VARIABLE PARTITIONING
Initially main memory is empty and partitions are made during the run-
time according to process’s need instead of partitioning during system
configure
The size of partition will be equal to incoming process
Internal fragmentation can be avoided to ensure efficient utilisation of
memory
Number of partitions are not fixed and depends on the number of incoming
process and Main Memory’s size
VARIABLE PARTITIONING
Advantages of Variable
Partitioning –
No Internal Fragmentation
No restriction on Degree of
Multiprogramming
External Fragmentation
NON CONTIGUOUS MEMORY MANAGEMENT
In non-contiguous memory allocation, different parts of a process is allocated
different places in Main Memory
Spanning is allowed
In non-contiguous allocation, Operating system needs to maintain the table
for each process which contains the starting address of the each block
which is acquired by the process in memory space
Two ways which allows non-contiguous way of memory allocation:
Paging
Segmentation
PAGING
Paging is a mechanism used to retrieve processes from the secondary
storage into the main memory in the form of pages.
In this technique, each process is divided in the form of PAGES
The main memory will also be divided in the form of FRAMES
One page of the process is to be stored in one of the frames of the memory.
Pages of the process are brought into the main memory only when they are
required otherwise they reside in the secondary storage.
Considering the fact that the pages are mapped to the frames , PAGE SIZE
NEEDS TO BE AS SAME AS FRAME SIZE.
PAGING-EXAMPLE
Main memory size 16 Kb
Frame size is 1 KB
Main memory will be divided into
16 frames of 1 KB each
There are 4 processes in the system
that is P1, P2, P3 and P4 of 4 KB
each
Each process is divided into pages
of 1 KB each
WHY SEGMENTATION IS
REQUIRED
Paging is more close to Operating system rather than the User.
Operating system doesn't care about the User's view of the process. It may
divide the same function into different pages and those pages may or may
not be loaded at the same time into the memory.
It is better to have segmentation which divides the process into the
segments. Each segment contain same type of functions such as main
function can be included in one segment and the library functions can be
included in the other segment
SEGMENTATION
Pages are physical in nature and Segments are logical divisions of a process
Segments are variable in size
Each program is divided into logical parts-SEGMENTS
The details about each segment are stored in a table called as segment table
VIRTUAL MEMORY
Virtual Memory is a storage scheme that provides user an illusion of having
a very big main memory. This is done by treating a part of secondary
memory as the main memory
Instead of loading one big process in the main memory, the Operating
System loads the different parts of more than one process in the main
memory
Virtual memory concept can be implemented using Paging, segmentation
or combined techniques
Degree of multiprogramming will be increased and therefore, the CPU
utilization will also be increased
TERMS RELATED TO VIRTUAL MEMORY
Page fault:
A page fault is trap that occurs when the requested page is
not loaded into the memory
When a program tries to access a chunk of memory that does
not exist in physical memory (main memory) causes a page
fault.
Page replacement policy:
Page replacement occurs due to page faults.
Page replacement is referred to a scenario in which a page
from the main memory should be replaced by a page from
secondary memory
The various page replacement algorithms like FIFO, Optimal
page replacement, LRU help the operating system to decide
which page to replace.
FIFO
FIFO algorithm is the simplest of all the page replacement
algorithms.
In this, we maintain a queue of all the pages that are in the
memory currently.
Whenever a page fault occurs, the operating system looks at
the front-end of the queue to know the page to be replaced by
the newly requested page.
It also adds this newly requested page at the rear-end and
removes the oldest page from the front-end of the queue.
FIFO-EXAMPLE
Consider the page reference string as 3, 1, 2, 1, 6, 5, 1, 3 with 3-page
frames. Find the number of page faults:
LRU(LEAST RECENTLY USED)
The least recently used page replacement algorithm keeps the
track of usage of pages over a period of time.
This algorithm works on the basis of the principle of locality
of a reference which states that a program has a tendency to
access the same set of memory locations repetitively over a
short period of time. So pages that have been used heavily in
the past are most likely to be used heavily in the future also.
In this algorithm, when a page fault occurs, then the page
that has not been used for the longest duration of time
is replaced by the newly requested page.
LRU
Let’s see the performance of the LRU on the same reference string of 3, 1,
2, 1, 6, 5, 1, 3 with 3-page frames:
OPTIMAL
Optimal page replacement is the best page replacement
algorithm as this algorithm results in the least number of page
faults.
In this algorithm, the pages are replaced with the ones that
will not be used for the longest duration of time in the future.
In simple terms, the pages that will be referred farthest in the
future are replaced in this algorithm.
OPTIMAL-ALGORITHM
Let’s take the same page reference string 3, 1, 2, 1, 6, 5, 1, 3 with 3-page
frames :
EXAMPLES
FREE SPACE MANAGEMENT
TECHNIQUES
Free space management is a critical aspect of operating systems as it
involves managing the available storage space on the hard disk or other
secondary storage devices.
The operating system uses various techniques to manage free space and
optimize the use of storage devices
The system keeps tracks of the free disk blocks for allocating space to files
when they are created.
To reuse the space released from deleting the files, free space
management becomes crucial.
BITMAP OR BIT VECTOR
A Bitmap or Bit Vector is series or collection of bits where each bit
corresponds to a disk block.
The bit can take two values: 0 and 1: 0 indicates that the block is free and
1 indicates an allocatedblock.
The given instance of disk blocks on the disk can be represented by a
bitmap of 16 bits as: 1111000111111001.
Advantages:
Simple to understand.
Finding the first free block is efficient. It requires scanning the words (a
group of 8 bits) in a bitmap for a non-zero word. (A 0-valued word has all
bits 0). The first free block is then found by scanning for the first 1 bit in
the non-zero word.
Disadvantages:
For finding a free block, Operating System needs to iterate all the blocks
which is time consuming.
The efficiency of this method reduces as the disk size increases.
LINKED LIST
In this approach, the free disk blocks are linked together i.e. a free block
contains a pointer to the next free block.
The block number of the very first disk block is stored at a separate
location on disk and is also cached in memory.
The last free block would contain a null pointer indicating the end of free
list.
Advantages:
The total available space is used efficiently using this method.
Dynamic allocation in Linked List is easy, thus can add the space as per the
requirement dynamically.
Disadvantages:
When the size of Linked List increases, managing the pointers becomes
tedious