Unit II - Storage management
Logical address
Logical Address is generated by CPU while a
program is running.
The logical address is virtual address as it does
not exist physically, therefore, it is also known
as Virtual Address.
This address is used as a reference to access
the physical memory location by CPU.
The term Logical Address Space is used for the
set of all logical addresses generated by a
program’s perspective.
The hardware device called Memory-
Management Unit is used for mapping logical
address to its corresponding physical address.
Physical Address
It identifies a physical location of required
data in a memory.
The user never directly deals with the
physical address but can access by its
corresponding logical address.
The program needs physical memory for its
execution, therefore, the logical address
must be mapped to the physical address by
MMU before they are used.
Parameter LOGICAL ADDRESS PHYSICAL ADDRESS
location in a memory
Basic generated by CPU
unit
User can never view
User can view the logical
Visibility physical address of
address of a program.
program.
Generation generated by the CPU Computed by MMU
The user can use the logical The user can indirectly
Access address to access the physical access physical
address. address but not directly.
Physical address will
Editable Logical address can be change.
not change.
Also called virtual address. real address.
Swapping
Swapping is a memory management
scheme in which any process can be
temporarily swapped from main
memory to secondary memory so that
the main memory can be made
available for other processes.
It is used to improve main memory
utilization.
In secondary memory, the place where
the swapped-out process is stored is
called swap space.
The purpose of the swapping in operating system
is to access the data present in the hard disk and
bring it to RAM so that the application programs
can use it.
The concept of swapping has divided into two
more concepts: Swap-in and Swap-out.
Swap-out is a method of removing a process
from RAM and adding it to the hard disk.
Swap-in is a method of removing a program
from a hard disk and putting it back into the main
memory or RAM.
Advantages
It helps the CPU to manage multiple
processes within a single main memory.
It helps to create and use virtual memory.
Swapping allows the CPU to perform multiple
tasks simultaneously.
It improves the main memory utilization.
Disadvantages
If the computer system loses power, the user
may lose all information related to the program
in case of substantial swapping activity.
Contiguous Memory Allocation
It is the type of memory allocation
method. When a process requests the
memory, a single contiguous section of
memory blocks is allotted depending on
its requirements.
It is completed by partitioning the
memory into fixed-sized partitions and
assigning every partition to a single
process.
Fixed-size Partition Scheme
In this type of contiguous memory allocation
technique, each process is allotted a fixed size
continuous block in the main memory.
That means there will be continuous blocks of
fixed size into which the complete memory will
be divided, and each time a process comes in,
it will be allotted one of the free blocks.
This technique is also called static partitioning.
Variable-size Partition
In this type of contiguous memory allocation
technique, no fixed blocks or partitions are
made in the memory.
Instead, each process is allotted a variable-
sized block depending upon its requirements.
That means, whenever a new process wants
some space in the memory, if available, this
amount of space is allotted to it.
Hence, the size of each block depends on the
size and requirements of the process which
occupies it.
Paging
In Operating Systems, Paging is a storage
mechanism used to retrieve processes from
the secondary storage into the main memory
in the form of pages.
The main idea behind the paging is to divide
each process 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.
Paging is a fixed size partitioning scheme.
In paging, secondary memory and main
memory are divided into equal fixed size
partitions.
The partitions of secondary memory are
called as pages.
The partitions of main memory are called
as frames.
Advantages of using Paging method:
Easy to use memory management algorithm
Swapping is easy between equal-sized
pages and page frames.
Disadvantages of Paging
Page tables consume additional memory.
Multi-level paging may lead to memory
reference overhead.
Paging Hardware
Address generated by CPU is divided into:
◦ Page number (p) - used as an index into a page
table which contains base address of each
page in physical memory.
◦ Page offset (d) - combined with base address
to define the physical memory address that is
sent to the memory unit. It refers to the number
of bits necessary to represent a certain word on
a page, For ex: 10 bits
Paging Hardware
Segmentation
Segmentation method works almost
similarly to paging, only difference
between the two is that segments are
of variable-length whereas, in the
paging method, pages are always of
fixed size.
A program segment includes the program’s
main function, data structures, utility
functions, etc.
The OS maintains a segment map table for all
the processes.
It also includes a list of free memory blocks
along with its size, segment numbers, and
it’s memory locations in the main memory
or virtual memory.
Segment table contains mainly two
information about segment:
Base: It is the base address of the
segment
Limit: It is the length of the segment.
Example of Segmentation in OS
Consider that a user program has been
divided into five segments and they are
numbered from segment 0 to segment 4, as
you can see them in the logical address
space.
You also have a segment table which has
entries for these segment with their base
address in physical memory and their limit.
With the help of segment map tables and
hardware assistance, the operating system can
easily translate a logical address into physical
address on execution of a program.
Advantages of Segmentation
Offer protection within the segments
You can achieve sharing by segments
referencing multiple processes.
Segment tables use lesser memory than
paging
Disadvantages of Segmentation
In segmentation method, processes are
loaded/ removed from the main memory.
Therefore, the free memory space is separated
into small pieces which may create a problem
of external fragmentation
Costly memory management algorithm
virtual memory
Virtual memory is a memory
management technique where
secondary memory can be used as if it
were a part of the main memory.
Virtual memory is a common technique
used in a computer's operating system
(OS).
A computer can address more memory than
the amount physically installed on the system.
This extra memory is actually called virtual
memory
Following are the situations, when entire
program is not required to be loaded fully in
main memory.
User written error handling routines are used
only when an error occurred in the data or
computation.
Certain options and features of a program
may be used rarely.
Less number of I/O would be needed to load
or swap each user program into memory.
Advantages of Virtual Memory
The degree of Multiprogramming will be
increased.
User can run large application with less real
RAM.
There is no need to buy more memory RAMs.
Disadvantages of Virtual Memory
The system becomes slower since swapping
takes time.
It takes more time in switching between
applications.
The user will have the lesser hard disk space
Demand Paging
Demand paging is a memory
management scheme employed by
modern operating systems to
manage physical memory
resources.
Demand paging is a process in which data is
moved from secondary memory to RAM on a
demand basis, which means all data is not
stored in the main memory because the space
is limited in RAM.
So if the CPU demands the process, if that
page is not in RAM, then swapping is needed.
This means shifting the existing page from
RAM and putting back in secondary memory
and putting the new page in RAM.
Demand Paging is a method in which a
page is only brought into main memory
when the CPU requests it.
At first, just those pages are loaded
directly required by the operation.
Pages that are never accessed are thus
never loaded into physical memory.
Why Demand Paging?
There are a lot of pages in one particular
process. But to put all the pages of that
particular process in the memory will only
consume the memory.
Now for this problem, the concept of
demand paging came into execution.
Demand Paging is a method in which a page
is only brought into main memory when the
CPU requests it.
Advantages
Memory can be put to better use.
If we use demand paging, then we can have
a large virtual memory.
By using demand paging, we can run
programs that are larger than physical
memory.
In demand paging, the sharing of pages is
easy.
Disadvantages
It takes longer to access memory (page
table lookup).
Memory requirements
Inverted page tables
Page Replacement Algorithms
In an operating system that uses paging for
memory management, a page replacement
algorithm is needed to decide which page
needs to be replaced when a new page
comes in.
Page Replacement Algorithms:
Page fault/ Miss: If the searching page is not
in memory
Page Hit: If the searching page that was
available in memory.
First In First Out (FIFO):
This is the simplest page replacement
algorithm.
In this algorithm, the operating system
keeps track of all pages in the memory
in a queue, the oldest page is in the
front of the queue.
When a page needs to be replaced
page in the front of the queue is
selected for removal.
Example 1: Consider page reference string
1, 3, 0, 3, 5, 6, 3 with 3 page frames. Find the
number of page faults.
Advantages
This algorithm is simple and easy to use.
FIFO does not cause more overhead.
Disadvantages
This algorithm does not make the use of the
frequency of last used time rather it just
replaces the Oldest Page.
There is an increase in page faults as page
frames increases.
The performance of this algorithm is the worst.
Optimal Page replacement
In this algorithm, pages are replaced which
would not be used for the longest duration of
time in the future
Advantages of OPR
This algorithm is easy to use.
This algorithm provides excellent efficiency and
is less complex.
For the best result, the implementation of data
structures is very easy
Disadvantages of OPR
Practical Implementation is not possible
because the operating system is unable to
track the future request
Example-2: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3,
0, 3, 2, 3 with 4 page frame. Find number of page fault.
Least Recently Used
In this algorithm, page will be replaced which
is least recently used.
The page that has not been used for the
longest time in the main memory will be
selected for replacement.
This algorithm is easy to implement.
Example-3: Consider the page reference string
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page
frames. Find number of page faults.
Advantages of LRU
It is an efficient technique.
With this algorithm, it becomes easy to identify
the faulty pages that are not needed for a long
time.
It helps in Full analysis.
Disadvantages of LRU
It is expensive and has more complexity.
There is a need for an additional data structure.
Most Recently Used (MRU) / LIFO
In this algorithm, page will be replaced which
has been used recently.
This is the Last in First Out algorithm and
works on LIFO principles.
In this algorithm, the newest page is
replaced by the requested page.
Example: Let’s see how the LIFO performs for
our example string of 3, 1, 2, 1, 6, 5, 1, 3 with 3-
page frames:
Advantages
Simple implementation:
Low overhead:
Disadvantages
Poor performance:
May result in page thrashing: LIFO page
replacement algorithm can result in a situation
known as page thrashing, where the pages are
frequently swapped in and out of memory,
leading to high page fault rates and poor system
performance.