MEMORY
MANAGEMENTOPERATING SYSTEM
INTRODUCTION
Memory management is the method or a functionality of an operating
system which handles or manages primary memory. It is the process of
controlling and coordinating computer memory, assigning portions called
blocks to various running programs to optimize overall system
performance.
The memory management function keeps track of the status of each
memory location, either allocated or free. It determines how memory is
allocated among competing processes, deciding which gets memory,
when they receive it, and how much they are allowed. When memory is
allocated it determines which memory locations will be assigned. It tracks
when memory is freed or unallocated and updates the status.
Goal – Efficient use of memory
MEMORY ALLOCATION TECHNIQUES
CONTIGUOUS MEMORY ALLOCATION
• Contiguous memory allocation is a memory allocation model that assigns a
process consecutive memory blocks (that is, memory blocks having
consecutive addresses).
• It one of the oldest memory allocation schemes. When a process needs to
execute, memory is requested by the process. The size of the process is
compared with the amount of contiguous main memory available to execute
the process. If sufficient contiguous memory is found, the process is allocated
memory to start its execution. Otherwise, it is added to a queue of waiting
processes until sufficient free contiguous memory is available.
BARE MACHINE
• So basically Bare machine is logical hardware which is used to execute the
program in the processor without using the operating system. as of now, we
have studied that we can’t execute any process without the Operating system.
But yes with the help of the Bare machine we can do that.
Initially, when the operating systems are not developed, the execution of an
instruction is done by directly on hardware without using any interfering
hardware, at that time the only drawback was that the Bare machines
accepting the instruction in only machine language, due to this those person
who has sufficient knowledge about Computer field are able to operate a
computer. so after the development of the operating system Bare machine is
referred to as inefficient.
Advantage of bare machine :-
*Flexible
*No hardware support is required
*No software is needed for OS
Disadvantage of bare machine :-
As OS has no control over the memory , it does not provide any
services and resources to user.
Such management method is used in user dedicated system
RESIDENT MONITOR
(single process monitor)
So basically, the Resident Monitor is a code that runs on Bare Machines.
The resident monitor works like an operating system that controls the
instructions and performs all necessary functions. It also works like job
sequencer because it also sequences the job and sends them to the
processor.
After scheduling the job Resident monitors loads the programs one by
one into the main memory according to their sequences. One most
important factor about the resident monitor is that when the program
execution occurred there us no gap between the program execution and
the processing is going to be faster.
The Resident monitors are
divided into 4 parts as:-
1. Control Language Interpreter
2. Loader
3. Device Driver
4. Interrupt Processing
*Control Language Interpreter:-
The first part of the Resident monitor is control language interpreter which is used to
read and carry out the instruction from one level to the next level.
*Loader:-
The second part of the Resident monitor which is the main part of the Resident
Monitor is Loader which Loads all the necessary system and application programs
into the main memory.
*Device Driver:-
The third part of the Resident monitor is Device Driver which is used to managing the
connecting input-output devices to the system. So basically it is the interface
between the user and the system. it works as an interface between the request and
response. request which user made, Device driver responds that the system produces
to fulfill these requests.
*Interrupt Processing:-
The fourth part as the name suggests, it processes the all occurred interrupt to the
system.
MULTIPROGRAMMING
*Multiprogramming increases CPU utilization by organizing jobs in
such a manner that CPU has always one job to execute.
*It is a technique to execute the number of programs
simultaneously by a single processor.
*In multiprogramming , a number of processes or more than one
process is in main memory which are ready to execute.
Advantages of multiprogramming :-
*High CPU utilization.
*Efficient memory utilization.
*Less waiting time & response time.
Disadvantage of multiprogramming :-
*Difficult scheduling.
*Memory fragmentation.
*Main memory management is required.
TYPES OF MULTIPROGRAMMING MEMORY ALLOCATION
• 1. Fixed size partition –
• It is also known as Static Partition. It was used long back around 1960.
• This is the oldest and simplest technique used to put more than one
processes in the main memory. In this partitioning, number of partitions
(non-overlapping) in RAM are fixed but size of each partition may or
may not be same.
• As it is contiguous allocation, hence no spanning is allowed. Here
partition are made before execution or during system configure.
EXAMPLE OF FIXED SIZE
PARTITION
• Fig. fixed size partition
As illustrated in the figure, first process is only consuming 1MB out of
4MB in the main memory.
Hence, Internal Fragmentation in first block is (4-1) = 3MB.
Sum of Internal Fragmentation in every block = (4-1)+(8-7)+(8-7)+(16-
14)= 3+1+1+2 = 7MB.
Suppose process P5 of size 7MB comes. But this process cannot be
accommodated inspite of available free space because of contiguous
allocation (as spanning is not allowed). Hence, 7MB becomes part of
External Fragmentation.
.
• Advantage of fixed partition –
• Easy to implement: -
• Algorithms needed to implement Fixed Partitioning are easy to
implement. It simply requires putting a process into certain
partition without focusing on the emergence of Internal and
External Fragmentation.
• Little OS overhead: -
• Processing of Fixed Partitioning require lesser excess and
indirect computational power.
.
• Disadvantages of Fixed Partitioning –
• Internal Fragmentation: -
• Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. This can cause
internal fragmentation.
• External Fragmentation:-
• The total unused space (as stated above) of various partitions cannot be used to load the processes even though
there is space available but not in the contiguous form (as spanning is not allowed).
• Limit process size:-
• Process of size greater than size of partition in Main Memory cannot be accommodated. Partition size cannot be
varied according to the size of incoming process’s size. Hence, process size of 32MB in above stated example is
invalid.
• Limitation on Degree of Multiprogramming:-
• Partition in Main Memory are made before execution or during system configure. Main Memory is divided into
fixed number of partition. Suppose if there are n1 partitions in RAM and n2 are the number of processes, then
n2 <= n1 condition must be fulfilled. Number of processes greater than number of partitions in RAM is invalid in
Fixed Partitioning.
2. Variable size Partitioning –
It is a part of Contiguous allocation technique. It is used to alleviate the
problem faced by Fixed Partitioning. In contrast with fixed partitioning,
partitions are not made before the execution or during system configure.
Features:-
*Initially RAM 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.
*The partition size varies according to the need of the process so that the
internal fragmentation can be avoided to ensure efficient utilisation of RAM.
*Number of partitions in RAM is not fixed and depends on the number of
incoming process and Main Memory’s size.
For example, suppose in above example- process
P1(2MB) and process P3(1MB) completed their
execution. Hence two spaces are left i.e. 2MB and 1MB.
Let’s suppose process P5 of size 3MB comes. The empty
space in memory cannot be allocated as no spanning is
allowed in contiguous allocation. The rule says that
process must be contiguously present in main memory
to get executed. Hence it results in External
Fragmentation.
Now P5 of size 3 MB cannot be accommodated
in spite of required available space because in
contiguous no spanning is allowed.
Advantages of Variable Partitioning –
No Internal Fragmentation:-
In variable Partitioning, space in main memory is allocated strictly according to the
need of process, hence there is no case of internal fragmentation. There will be no
unused space left in the partition.
No restriction on Degree of Multiprogramming:-
More number of processes can be accommodated due to absence of internal
fragmentation. A process can be loaded until the memory is empty.
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 loaded and process can not be divided as it is invalid in
contiguous allocation technique. Here, In variable partitioning, the process size can’t
be restricted since the partition size is decided according to the process size.
Disadvantages of Variable Partitioning –
Difficult Implementation:-
Implementing variable Partitioning is difficult as compared to Fixed
Partitioning as it involves allocation of memory during run-time
rather than during system configure.
External Fragmentation:
There will be external fragmentation inspite of absence of internal
fragmentation.
Below are the various partition algorithm :-
1. First Fit: In the first fit, the partition is allocated which is first sufficient block from the top of Main
Memory.
2. Best Fit Allocate the process to the partition which is the first smallest sufficient partition among the free
available partition.
3. Worst Fit Allocate the process to the partition which is the largest sufficient among the freely available
partitions available in the main memory.
4. Next Fit Next fit is similar to the first fit but it will search for the first sufficient partition from the last
allocation point.
Is Best-Fit really best?
Although best fit minimizes the wastage space, it consumes a lot of processor time for searching the block
which is close to the required size. Also, Best-fit may perform poorer than other algorithms in some cases.
For example, see below exercise.
NON-CONTIGUOUS MEMORY ALLOCATION
• In non-contiguous allocation, Operating system needs to maintain
the table which is called Page Table for each process which
contains the base address of the each block which is acquired by
the process in memory space.
• In non-contiguous memory allocation, different parts of a process
is allocated different places in Main Memory. Spanning is allowed
which is not possible in other techniques like Dynamic or Static
Contiguous memory allocation. That’s why paging is needed to
ensure effective memory allocation. Paging is done to remove
External Fragmentation.
*Paging and Segmentation are the two ways which allow a process’s
physical address space to be non-contiguous.
*It has advantage of reducing memory wastage but it increases the
overheads due to address translation. It slows the execution of the memory
because time is consumed in address translation.
*A table has to be maintained for each process that carries the base
addresses of each block which has been acquired by a process in memory.
*Divide the process into several blocks and place them in different parts
of the memory according to the availability of memory space available.*
*Non-contiguous memory allocation is of different types:-
Paging
Segmentation
Segmentation with paging
DIFFERENCE BETWEEN CONTIGUOUS AND NON-CONTIGUOUS
MEMORY ALLOCATION :
CONTIGUOUS MEMORY
ALLOCATION
• 1.Contiguous memory allocation allocates
consecutive blocks of memory to a file/process.
• 2.Faster in Execution.
• 3.It is easier for the OS to control.
• 4.Overhead is minimum as not much address
translations are there while executing a process.
• 5.Internal fragmentation occurs in Contiguous
memory allocation method.
• 6.It includes single partition allocation and
multi-partition allocation.
• 7.Wastage of memory is there.
NON-CONTIGUOUS MEMORY
ALLOCATION
• 1.Non-Contiguous memory allocation allocates
separate blocks of memory to a file/process.
• 2Slower in Execution.
• 3.It is difficult for the OS to control.
• 4.More Overheads are there as there are more
address translations.
• 5.External fragmentation occurs in Non-
Contiguous memory allocation method.
6.It includes paging and segmentation.
• 7.No memory wastage is there.
Working of non-contiguous(example):-
Here a process can be spanned across different spaces in
main memory in non-consecutive manner. Suppose process
P of size 4KB. Consider main memory have two empty slots
each of size 2KB. Hence total free space is, 2*2= 4 KB. In
contiguous memory allocation, process P cannot be
accommodated as spanning is not allowed.
In contiguous allocation, space in memory should be
allocated to whole process. If not, then that space remains
unallocated. But in Non-Contiguous allocation, process can
be divided into different parts and hence filling the space in
main memory. In this example, process P can be divided into
two parts of equal size – 2KB. Hence one part of process P
can be allocated to first 2KB space of main memory and
other part of process P can be allocated to second 2KB space
of main memory. Below diagram will explain in better way:
But, in what manner we divide a process to allocate them into main
memory is very important to understand. Process is divided after
analysing the number of empty spaces and their size in main
memory. Then only we divide our process. It is very time consuming
process. Their number as well as their sizes changing every time
due to execution of already present processes in main memory.
In order to avoid this time consuming process, we divide our
process in secondary memory in advance before reaching the
memory memory for its execution. Every process is divided into
various parts of equal size called Pages. We also divide our main
memory into different parts of equal size called Frames. It is
important to understand that:
Size of page in process
= Size of frame in memory
Although their numbers can be different. Below diagram will make
you understand in better way: consider empty main memory having
size of each frame is 2 KB, and two processes P1 and P2 are 2 KB
each.
Resolvent main memory,
In conclusion we can say that, Paging
allows memory address space of a
process to be non-contiguous. Paging is
more flexible as only pages of a process
are moved. It allows more processes to
reside in main memory than Contiguous
memory allocation.
TYPES OF NON-CONTIGUOUS MEMORY ALLOCATION
• 1. Paging
• A non-contiguous policy with a fixed size partition is called paging. A computer can
address more memory than the amount of physically installed on the system. This
extra memory is actually called virtual memory. Paging technique is very important in
implementing virtual memory. Secondary memory is divided into equal size partition
(fixed) called pages. Every process will have a separate page table. The entries in the
page table are the number of pages a process. At each entry either we have an invalid
pointer which means the page is not in main memory or we will get the corresponding
frame number. When the frame number is combined with instruction of set D than we
will get the corresponding physical address. Size of a page table is generally very large
so cannot be accommodated inside the PCB, therefore, PCB contains a register value
PTBR( page table base register) which leads to the page table.
ii) Segmentation
Segmentation is a programmer view of the memory where instead of dividing a process into
equal size partition we divided according to program into partition called segments. The
translation is the same as paging but paging segmentation is independent of internal
fragmentation but suffers from external fragmentation. Reason of external fragmentation is
program can be divided into segments but segment must be contiguous in nature.
iii) Segmentation with paging
In segmentation with paging, we take advantages of both segmentation as well as paging. It
is a kind of multilevel paging but in multilevel paging, we divide a page table into equal size
partition but here in segmentation with paging, we divide it according to segments. All the
properties are the same as that of paging because segments are divided into pages.
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. The pages can be stored at
the different locations of the memory but the priority is always to find the contiguous frames or holes.
Pages of the process are brought into the main memory only when they are required otherwise they
reside in the secondary storage.
Different operating system defines different frame sizes. The sizes of each frame must be equal.
Considering the fact that the pages are mapped to the frames in Paging, page size needs to be as same
as frame size.
Example of paging:-
Let us consider the main memory size 16
Kb and Frame size is 1 KB therefore the
main memory will be divided into the
collection of 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
so that one page can be stored in one
frame.
Initially, all the frames are empty therefore
pages of the processes will get stored in
the contiguous way.
Frames, pages and the mapping between
the two is shown in the image.
Let us consider that, P2 and P4 are
moved to waiting state after some
time. Now, 8 frames become empty
and therefore other pages can be
loaded in that empty place. The
process P5 of size 8 KB (8 pages) is
waiting inside the ready queue.
Given the fact that, we have 8 non
contiguous frames available in the
memory and paging provides the
flexibility of storing the process at the
different places. Therefore, we can load
the pages of process P5 in the place of
P2 and P4.
Example-2
Example of paging
Example-3
Example of paging
Example-4
Example of paging
Advantages of paging:-
*It allows to store parts of a single process in a non-
contiguous fashion.
*It solves the problem of external fragmentation.
Disadvantage of paging:-
*It suffers from internal fragmentation.
*There is an overhead of maintaining a page table
for each process.
*The time taken to fetch the instruction increases
since now two memory accesses are required.
So the conclusion is :-
*Paging reduces external fragmentation, but still suffer from internal
fragmentation.
*Paging is simple to implement and assumed as an efficient memory
management technique.
*Due to equal size of the pages and frames, swapping becomes very easy.
*Page table requires extra memory space, so may not be good for a system
having small RAM.
Why paging is used?
* Paging is a memory management technique in which the memory is
divided into fixed size pages. Paging is used for faster access to data. When
a program needs a page, it is available in the main memory as the OS copies
a certain number of pages from your storage device to main memory.
Paging allows the physical address space of a process to be noncontiguous.
* OS performs an operation for storing and retrieving data from secondary
storage devices for use in main memory. Paging is one of such memory
management scheme. Data is retrieved from storage media by OS, in the same
sized blocks called as pages. Paging allows the physical address space of the
process to be non contiguous. The whole program had to fit into storage
contiguously.
* Paging is to deal with external fragmentation problem. This is to allow the
logical address space of a process to be noncontiguous, which makes the process
to be allocated physical memory.
LOGICAL AND PHYSICAL 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.
*Logical Address or Virtual Address (represented in bits): An
address generated by the CPU
*Logical Address Space or Virtual Address Space( represented
in words or bytes): The set of all logical addresses generated by
a program
Example:
*If Logical Address = 31 bit, then Logical Address
Space = 231 words = 2 G words (1 G = 230)
*If Logical Address Space = 128 M words = 27 * 220
words, then Logical Address = log2 227 = 27 bits
Physical Address 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 user program generates the logical address and
thinks that the program is running in this logical address but 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. The term Physical Address Space
is used for all physical addresses corresponding to the logical addresses in a Logical
address space.
Example:
*If Physical Address = 22 bit, then Physical Address Space = 222
words = 4 M words (1 M = 220)
*If Physical Address Space = 16 M words = 24 * 220 words,
then Physical Address = log2 224 = 24 bits
Differences Between Logical and Physical Address in Operating System
*The basic difference between Logical and physical address is that Logical address is generated by
CPU in perspective of a program whereas the physical address is a location that exists in the
memory unit.
*Logical Address Space is the set of all logical addresses generated by CPU for a program whereas
the set of all physical address mapped to corresponding logical addresses is called Physical
Address Space.
*The logical address does not exist physically in the memory whereas physical address is a
location in the memory that can be accessed physically.
Identical logical addresses are generated by Compile-time and Load time address binding
methods whereas they differs from each other in run-time address binding method. Please refer
this for details.
*The logical address is generated by the CPU while the program is running whereas the physical
address is computed by the Memory Management Unit (MMU).
The process of Translation from logical to
physical addresses
*Every address generated by the CPU is divided into
two parts: a page number (p) and a page offset (d).
The page number is used as an index into a page
table.
*The page table contains the base address of each
page in physical memory. This base address is
combined with the page offset to define the physical
memory address that is sent to the memory unit.
*If the size of logical-address space is 2m and a page
size is 2n addressing units (bytes or words), then the
high-order (m – n) bits of a logical address designate
the page number and then low-order bits designate
the page offset.
Address generated by CPU is divided into
Page number(p): Number of bits required to represent the pages in Logical Address Space or Page
number
Page offset(d): Number of bits required to represent particular word in a page or page size of Logical
Address Space or word number of a page or page offset.
Physical Address is divided into
Frame number(f): Number of bits required to represent the frame of Physical Address Space or
Frame number.
Frame offset(d): Number of bits required to represent particular word in a frame or frame size of
Physical Address Space or word number of a frame or frame offset.
Let us consider an
example:
Physical Address = 12 bits,
then Physical Address Space
= 4 K words
Logical Address = 13 bits,
then Logical Address Space =
8 K words
Page size = frame size = 1 K
words (assumption)
HARDWARE SUPPORT FOR PAGING
(Translation Lookaside Buffer (TLB) in Paging)
or Paging hardware with TLB
To overcome the size issue, the entire page table was kept in main memory. but the
problem here is two main memory references are required:
To find the frame number
To go to the address specified by frame number
To overcome this problem a high-speed cache is set up for page table entries called a
Translation Lookaside Buffer (TLB)
Translation Lookaside Buffer (TLB) is nothing but a special cache used
to keep track of recently used transactions.
TLB contains page table entries that
have been most recently used.
Given a virtual address, the
processor examines the TLB if a
page table entry is present (TLB hit),
the frame number is retrieved and
the real address is formed. If a page
table entry is not found in the TLB
(TLB miss), the page number is used
to index the process page table. TLB
first checks if the page is already in
main memory, if not in main
memory a page fault is issued then
the TLB is updated to include the
new page entry.
Steps in TLB hit:
*CPU generates virtual address.
*It is checked in TLB (present).
*Corresponding frame number is retrieved, which now tells where in the main memory page lies.
Steps in Page miss:
*CPU generates virtual address.
*It is checked in TLB (not present).
*Now the page number is matched to page table residing in main memory (assuming page table contains all PTE).
*Corresponding frame number is retrieved, which now tells where in the main memory page lies.
*The TLB is updated with new PTE (if space is not there, one of the replacement technique comes into picture i.e.
either FIFU , LRU or MFU etc .
Effective memory access time(EMAT) :
TLB is used to reduce effective memory access time as it is a high speed associative cache.
EMAT = h*(c+m) + (1-h)*(c+2m)
where, h = hit ratio of TLB
m = Memory access time
c = TLB access time
Effective memory access time(EMAT) :
TLB is used to reduce effective memory access time as it is a high speed associative
cache.
EMAT = h*(c+m) + (1-h)*(c+2m)
where, h = hit ratio of TLB
m = Memory access time
c = TLB access time
TYPES OF PAGING
• Two Level Paging
The Pages are represented by the Virtual Address generated by the CPU. These
Pages are mapped to Physical Address by the MMU. So, to help in this mapping we
use the concept of Page Table. Just Like array, in page Table the indices represent
the Page Numbers and the contents contain the address of the Frame Number
where the the process is actually loaded in the main memory. Because the
virtual/Logical Address is relative to zero and should be mapped to actual physical
Address Space of Main Memory.
The size of the page table can be calculated from the fact that size of each of entry
of page table is given else if it is not given then we can find the number of bits
required to address each frame in the main memory (this is not correct but should
be used when nothing is given in question).
Page Table Size = No. of Page Table Entries(Total no. of Pages) * (size of each entry of
page table)
When the Size of page table is less than the size of one Frame then we need not worry because we can
directly put the page table in a frame of the main memory .Thus we can directly access the page table.
But if the size of the page table is larger than the size of Frame. Then the page table in return is to be
divided into several pages and these pages of the page table are to be stored in the main memory. Thus, a
Outer Page Table comes into the picture.
This Outer Page Table would contain the address of the Frames which contain the pages of Inner Page Table
(i.e., Page Table one pages) in the main memory.
The size of this Outer Page is also calculated in the same way as explained above and was used to calculate
the size of inner page Table. Now if the size of inner page Table is Less Than or Equal to size of a Frame then
we can stop here as we are able to keep the outer most table in a Single frame.
This is called as Two Level Paging.
TYPES OF PAGING:-
• Multilevel Paging in Operating System
Multilevel Paging is a paging scheme which consist of two or more levels of page
tables in a hierarchical manner. It is also known as hierarchical paging. The entries
of the level 1 page table are pointers to a level 2 page table and entries of the level
2 page tables are pointers to a level 3 page table and so on. The entries of the last
level page table are stores actual frame information. Level 1 contain single page
table and address of that table is stored in PTBR (Page Table Base Register).
In multilevel paging whatever may be levels of paging all the page tables will be
stored in main memory. So it requires more than one memory access to get the
physical address of page frame. One access for each level needed. Each page table
entry except the last level page table entry contains base address of the next level
page table.
Need of multilevel paging:–
*The need for multilevel paging arises when-
*The size of page table is greater than the frame size.
As a result, the page table can not be stored in a single frame in main memory.
Working of multilevel paging:-
In multilevel paging:-
*The page table having size greater than the frame size is divided into several parts.
*The size of each part is same as frame size except possibly the last part.
*The pages of page table are then stored in different frames of the main memory.
*To keep track of the frames storing the pages of the divided page table, another page table is
maintained.
*As a result, the hierarchy of page tables get generated.
*Multilevel paging is done till the level is reached where the entire page table can be stored in a single
frame.
SEGMENTATION
• In Operating Systems, Segmentation is a memory management
technique in which, the memory is divided into the variable size
parts. Each part is known as segment which can be allocated to a
process.
• A process is divided into Segments. The chunks that a program is
divided into which are not necessarily all of the same sizes are
called segments. Segmentation gives user’s view of the process
which paging does not give. Here the user’s view is mapped to
physical memory.
There are two types of segmentation:
Virtual memory segmentation –
Each process is divided into a number of segments, not all of which are
resident at any one point in time.
Simple segmentation –
Each process is divided into a number of segments, all of which are
loaded into memory at run time, though not necessarily contiguously.
*There is no simple relationship between logical addresses and physical
addresses in segmentation.
A table stores the information about all such segments and is called
Segment Table.
Segment Table – It maps two-dimensional Logical address into one-
dimensional Physical address. It’s each table entry has:
Base Address: It contains the starting physical address where the
segments reside in memory.
Limit: It specifies the length of the segment.
Example of
segmentation
Logical view of
segmentation
Translation of Two dimensional
Logical Address to one
dimensional Physical Address.
Address generated by the CPU
is divided into:
Segment number (s): Number of
bits required to represent the
segment.
Segment offset (d): Number of
bits required to represent the
size of the segment
TRANSLATION OF LOGICAL ADDRESS INTO PHYSICAL ADDRESS BY SEGMENT TABLE
Advantages of Segmentation –
*No Internal fragmentation.
*Segment Table consumes less space in comparison to Page table in paging.
*Average Segment Size is larger than the actual page size.
*Less overhead
*It is easier to relocate segments than entire address space.
*The segment table is of lesser size as compare to the page table in paging.
Disadvantage of Segmentation –
*As processes are loaded and removed from the memory, the free memory space
is broken into little pieces, causing External fragmentation.
*It is difficult to allocate contiguous memory to variable sized partition.
*Costly memory management algorithms.
Why Segmentation is required?
Till now, we were using Paging as our main memory management technique. Paging
is more close to Operating system rather than the User. It divides all the process
into the form of pages regardless of the fact that a process can have some relative
parts of functions which needs to be loaded in the same page.
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 decreases the efficiency of the system.
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,
Sr. No. Key pppPaging Segmentation
1
Memory Size In Paging, a process address space is broken into fixed
sized blocks called pages.
In Segmentation, a process address space is broken in
varying sized blocks called sections.
2
Accountability Operating System divides the memory into pages. Compiler is responsible to calculate the segment size, the
virtual address and actual address.
3
Size Page size is determined by available memory. Section size is determined by the user.
4 Speed Paging technique is faster in terms of memory access. Segmentation is slower than paging.
5
Fragmentation Paging can cause internal fragmentation as some pages
may go underutilized.
Segmentation can cause external fragmentation as some
memory block may not be used at all.
6
Logical
Address
During paging, a logical address is divided into page
number and page offset.
During segmentation, a logical address is divided into section
number and section offset.
7
Table During paging, a logical address is divided into page
number and page offset.
During segmentation, a logical address is divided into section
number and section offset.
8
Data Storage Page table stores the page data. Segmentation table stores the segmentation data.
DIFFERENCE BETWEEN PAGING AND SEGMENTATION
PAGING SEGMENTATION
THANKYOU
BY MANISHA JHA
B-TECH STUDENT
(CSE BRANCH)

Memory management ppt

  • 1.
  • 2.
    INTRODUCTION Memory management isthe method or a functionality of an operating system which handles or manages primary memory. It is the process of controlling and coordinating computer memory, assigning portions called blocks to various running programs to optimize overall system performance. The memory management function keeps track of the status of each memory location, either allocated or free. It determines how memory is allocated among competing processes, deciding which gets memory, when they receive it, and how much they are allowed. When memory is allocated it determines which memory locations will be assigned. It tracks when memory is freed or unallocated and updates the status. Goal – Efficient use of memory
  • 3.
  • 4.
    CONTIGUOUS MEMORY ALLOCATION •Contiguous memory allocation is a memory allocation model that assigns a process consecutive memory blocks (that is, memory blocks having consecutive addresses). • It one of the oldest memory allocation schemes. When a process needs to execute, memory is requested by the process. The size of the process is compared with the amount of contiguous main memory available to execute the process. If sufficient contiguous memory is found, the process is allocated memory to start its execution. Otherwise, it is added to a queue of waiting processes until sufficient free contiguous memory is available.
  • 5.
    BARE MACHINE • Sobasically Bare machine is logical hardware which is used to execute the program in the processor without using the operating system. as of now, we have studied that we can’t execute any process without the Operating system. But yes with the help of the Bare machine we can do that. Initially, when the operating systems are not developed, the execution of an instruction is done by directly on hardware without using any interfering hardware, at that time the only drawback was that the Bare machines accepting the instruction in only machine language, due to this those person who has sufficient knowledge about Computer field are able to operate a computer. so after the development of the operating system Bare machine is referred to as inefficient.
  • 6.
    Advantage of baremachine :- *Flexible *No hardware support is required *No software is needed for OS Disadvantage of bare machine :- As OS has no control over the memory , it does not provide any services and resources to user. Such management method is used in user dedicated system
  • 7.
    RESIDENT MONITOR (single processmonitor) So basically, the Resident Monitor is a code that runs on Bare Machines. The resident monitor works like an operating system that controls the instructions and performs all necessary functions. It also works like job sequencer because it also sequences the job and sends them to the processor. After scheduling the job Resident monitors loads the programs one by one into the main memory according to their sequences. One most important factor about the resident monitor is that when the program execution occurred there us no gap between the program execution and the processing is going to be faster.
  • 8.
    The Resident monitorsare divided into 4 parts as:- 1. Control Language Interpreter 2. Loader 3. Device Driver 4. Interrupt Processing
  • 9.
    *Control Language Interpreter:- Thefirst part of the Resident monitor is control language interpreter which is used to read and carry out the instruction from one level to the next level. *Loader:- The second part of the Resident monitor which is the main part of the Resident Monitor is Loader which Loads all the necessary system and application programs into the main memory. *Device Driver:- The third part of the Resident monitor is Device Driver which is used to managing the connecting input-output devices to the system. So basically it is the interface between the user and the system. it works as an interface between the request and response. request which user made, Device driver responds that the system produces to fulfill these requests. *Interrupt Processing:- The fourth part as the name suggests, it processes the all occurred interrupt to the system.
  • 10.
    MULTIPROGRAMMING *Multiprogramming increases CPUutilization by organizing jobs in such a manner that CPU has always one job to execute. *It is a technique to execute the number of programs simultaneously by a single processor. *In multiprogramming , a number of processes or more than one process is in main memory which are ready to execute.
  • 11.
    Advantages of multiprogramming:- *High CPU utilization. *Efficient memory utilization. *Less waiting time & response time. Disadvantage of multiprogramming :- *Difficult scheduling. *Memory fragmentation. *Main memory management is required.
  • 12.
    TYPES OF MULTIPROGRAMMINGMEMORY ALLOCATION • 1. Fixed size partition – • It is also known as Static Partition. It was used long back around 1960. • This is the oldest and simplest technique used to put more than one processes in the main memory. In this partitioning, number of partitions (non-overlapping) in RAM are fixed but size of each partition may or may not be same. • As it is contiguous allocation, hence no spanning is allowed. Here partition are made before execution or during system configure.
  • 13.
    EXAMPLE OF FIXEDSIZE PARTITION • Fig. fixed size partition As illustrated in the figure, first process is only consuming 1MB out of 4MB in the main memory. Hence, Internal Fragmentation in first block is (4-1) = 3MB. Sum of Internal Fragmentation in every block = (4-1)+(8-7)+(8-7)+(16- 14)= 3+1+1+2 = 7MB. Suppose process P5 of size 7MB comes. But this process cannot be accommodated inspite of available free space because of contiguous allocation (as spanning is not allowed). Hence, 7MB becomes part of External Fragmentation.
  • 14.
    . • Advantage offixed partition – • Easy to implement: - • Algorithms needed to implement Fixed Partitioning are easy to implement. It simply requires putting a process into certain partition without focusing on the emergence of Internal and External Fragmentation. • Little OS overhead: - • Processing of Fixed Partitioning require lesser excess and indirect computational power.
  • 15.
    . • Disadvantages ofFixed Partitioning – • Internal Fragmentation: - • Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. This can cause internal fragmentation. • External Fragmentation:- • The total unused space (as stated above) of various partitions cannot be used to load the processes even though there is space available but not in the contiguous form (as spanning is not allowed). • Limit process size:- • Process of size greater than size of partition in Main Memory cannot be accommodated. Partition size cannot be varied according to the size of incoming process’s size. Hence, process size of 32MB in above stated example is invalid. • Limitation on Degree of Multiprogramming:- • Partition in Main Memory are made before execution or during system configure. Main Memory is divided into fixed number of partition. Suppose if there are n1 partitions in RAM and n2 are the number of processes, then n2 <= n1 condition must be fulfilled. Number of processes greater than number of partitions in RAM is invalid in Fixed Partitioning.
  • 16.
    2. Variable sizePartitioning – It is a part of Contiguous allocation technique. It is used to alleviate the problem faced by Fixed Partitioning. In contrast with fixed partitioning, partitions are not made before the execution or during system configure. Features:- *Initially RAM 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. *The partition size varies according to the need of the process so that the internal fragmentation can be avoided to ensure efficient utilisation of RAM. *Number of partitions in RAM is not fixed and depends on the number of incoming process and Main Memory’s size.
  • 17.
    For example, supposein above example- process P1(2MB) and process P3(1MB) completed their execution. Hence two spaces are left i.e. 2MB and 1MB. Let’s suppose process P5 of size 3MB comes. The empty space in memory cannot be allocated as no spanning is allowed in contiguous allocation. The rule says that process must be contiguously present in main memory to get executed. Hence it results in External Fragmentation. Now P5 of size 3 MB cannot be accommodated in spite of required available space because in contiguous no spanning is allowed.
  • 18.
    Advantages of VariablePartitioning – No Internal Fragmentation:- In variable Partitioning, space in main memory is allocated strictly according to the need of process, hence there is no case of internal fragmentation. There will be no unused space left in the partition. No restriction on Degree of Multiprogramming:- More number of processes can be accommodated due to absence of internal fragmentation. A process can be loaded until the memory is empty. 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 loaded and process can not be divided as it is invalid in contiguous allocation technique. Here, In variable partitioning, the process size can’t be restricted since the partition size is decided according to the process size.
  • 19.
    Disadvantages of VariablePartitioning – Difficult Implementation:- Implementing variable Partitioning is difficult as compared to Fixed Partitioning as it involves allocation of memory during run-time rather than during system configure. External Fragmentation: There will be external fragmentation inspite of absence of internal fragmentation.
  • 20.
    Below are thevarious partition algorithm :- 1. First Fit: In the first fit, the partition is allocated which is first sufficient block from the top of Main Memory. 2. Best Fit Allocate the process to the partition which is the first smallest sufficient partition among the free available partition. 3. Worst Fit Allocate the process to the partition which is the largest sufficient among the freely available partitions available in the main memory. 4. Next Fit Next fit is similar to the first fit but it will search for the first sufficient partition from the last allocation point. Is Best-Fit really best? Although best fit minimizes the wastage space, it consumes a lot of processor time for searching the block which is close to the required size. Also, Best-fit may perform poorer than other algorithms in some cases. For example, see below exercise.
  • 21.
    NON-CONTIGUOUS MEMORY ALLOCATION •In non-contiguous allocation, Operating system needs to maintain the table which is called Page Table for each process which contains the base address of the each block which is acquired by the process in memory space. • In non-contiguous memory allocation, different parts of a process is allocated different places in Main Memory. Spanning is allowed which is not possible in other techniques like Dynamic or Static Contiguous memory allocation. That’s why paging is needed to ensure effective memory allocation. Paging is done to remove External Fragmentation.
  • 22.
    *Paging and Segmentationare the two ways which allow a process’s physical address space to be non-contiguous. *It has advantage of reducing memory wastage but it increases the overheads due to address translation. It slows the execution of the memory because time is consumed in address translation. *A table has to be maintained for each process that carries the base addresses of each block which has been acquired by a process in memory. *Divide the process into several blocks and place them in different parts of the memory according to the availability of memory space available.* *Non-contiguous memory allocation is of different types:- Paging Segmentation Segmentation with paging
  • 23.
    DIFFERENCE BETWEEN CONTIGUOUSAND NON-CONTIGUOUS MEMORY ALLOCATION : CONTIGUOUS MEMORY ALLOCATION • 1.Contiguous memory allocation allocates consecutive blocks of memory to a file/process. • 2.Faster in Execution. • 3.It is easier for the OS to control. • 4.Overhead is minimum as not much address translations are there while executing a process. • 5.Internal fragmentation occurs in Contiguous memory allocation method. • 6.It includes single partition allocation and multi-partition allocation. • 7.Wastage of memory is there. NON-CONTIGUOUS MEMORY ALLOCATION • 1.Non-Contiguous memory allocation allocates separate blocks of memory to a file/process. • 2Slower in Execution. • 3.It is difficult for the OS to control. • 4.More Overheads are there as there are more address translations. • 5.External fragmentation occurs in Non- Contiguous memory allocation method. 6.It includes paging and segmentation. • 7.No memory wastage is there.
  • 24.
    Working of non-contiguous(example):- Herea process can be spanned across different spaces in main memory in non-consecutive manner. Suppose process P of size 4KB. Consider main memory have two empty slots each of size 2KB. Hence total free space is, 2*2= 4 KB. In contiguous memory allocation, process P cannot be accommodated as spanning is not allowed. In contiguous allocation, space in memory should be allocated to whole process. If not, then that space remains unallocated. But in Non-Contiguous allocation, process can be divided into different parts and hence filling the space in main memory. In this example, process P can be divided into two parts of equal size – 2KB. Hence one part of process P can be allocated to first 2KB space of main memory and other part of process P can be allocated to second 2KB space of main memory. Below diagram will explain in better way:
  • 25.
    But, in whatmanner we divide a process to allocate them into main memory is very important to understand. Process is divided after analysing the number of empty spaces and their size in main memory. Then only we divide our process. It is very time consuming process. Their number as well as their sizes changing every time due to execution of already present processes in main memory. In order to avoid this time consuming process, we divide our process in secondary memory in advance before reaching the memory memory for its execution. Every process is divided into various parts of equal size called Pages. We also divide our main memory into different parts of equal size called Frames. It is important to understand that: Size of page in process = Size of frame in memory Although their numbers can be different. Below diagram will make you understand in better way: consider empty main memory having size of each frame is 2 KB, and two processes P1 and P2 are 2 KB each.
  • 26.
    Resolvent main memory, Inconclusion we can say that, Paging allows memory address space of a process to be non-contiguous. Paging is more flexible as only pages of a process are moved. It allows more processes to reside in main memory than Contiguous memory allocation.
  • 27.
    TYPES OF NON-CONTIGUOUSMEMORY ALLOCATION • 1. Paging • A non-contiguous policy with a fixed size partition is called paging. A computer can address more memory than the amount of physically installed on the system. This extra memory is actually called virtual memory. Paging technique is very important in implementing virtual memory. Secondary memory is divided into equal size partition (fixed) called pages. Every process will have a separate page table. The entries in the page table are the number of pages a process. At each entry either we have an invalid pointer which means the page is not in main memory or we will get the corresponding frame number. When the frame number is combined with instruction of set D than we will get the corresponding physical address. Size of a page table is generally very large so cannot be accommodated inside the PCB, therefore, PCB contains a register value PTBR( page table base register) which leads to the page table.
  • 28.
    ii) Segmentation Segmentation isa programmer view of the memory where instead of dividing a process into equal size partition we divided according to program into partition called segments. The translation is the same as paging but paging segmentation is independent of internal fragmentation but suffers from external fragmentation. Reason of external fragmentation is program can be divided into segments but segment must be contiguous in nature. iii) Segmentation with paging In segmentation with paging, we take advantages of both segmentation as well as paging. It is a kind of multilevel paging but in multilevel paging, we divide a page table into equal size partition but here in segmentation with paging, we divide it according to segments. All the properties are the same as that of paging because segments are divided into pages.
  • 29.
    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. The pages can be stored at the different locations of the memory but the priority is always to find the contiguous frames or holes. Pages of the process are brought into the main memory only when they are required otherwise they reside in the secondary storage. Different operating system defines different frame sizes. The sizes of each frame must be equal. Considering the fact that the pages are mapped to the frames in Paging, page size needs to be as same as frame size.
  • 31.
    Example of paging:- Letus consider the main memory size 16 Kb and Frame size is 1 KB therefore the main memory will be divided into the collection of 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 so that one page can be stored in one frame. Initially, all the frames are empty therefore pages of the processes will get stored in the contiguous way. Frames, pages and the mapping between the two is shown in the image.
  • 32.
    Let us considerthat, P2 and P4 are moved to waiting state after some time. Now, 8 frames become empty and therefore other pages can be loaded in that empty place. The process P5 of size 8 KB (8 pages) is waiting inside the ready queue. Given the fact that, we have 8 non contiguous frames available in the memory and paging provides the flexibility of storing the process at the different places. Therefore, we can load the pages of process P5 in the place of P2 and P4.
  • 33.
  • 34.
  • 35.
  • 36.
    Advantages of paging:- *Itallows to store parts of a single process in a non- contiguous fashion. *It solves the problem of external fragmentation. Disadvantage of paging:- *It suffers from internal fragmentation. *There is an overhead of maintaining a page table for each process. *The time taken to fetch the instruction increases since now two memory accesses are required.
  • 37.
    So the conclusionis :- *Paging reduces external fragmentation, but still suffer from internal fragmentation. *Paging is simple to implement and assumed as an efficient memory management technique. *Due to equal size of the pages and frames, swapping becomes very easy. *Page table requires extra memory space, so may not be good for a system having small RAM.
  • 38.
    Why paging isused? * Paging is a memory management technique in which the memory is divided into fixed size pages. Paging is used for faster access to data. When a program needs a page, it is available in the main memory as the OS copies a certain number of pages from your storage device to main memory. Paging allows the physical address space of a process to be noncontiguous. * OS performs an operation for storing and retrieving data from secondary storage devices for use in main memory. Paging is one of such memory management scheme. Data is retrieved from storage media by OS, in the same sized blocks called as pages. Paging allows the physical address space of the process to be non contiguous. The whole program had to fit into storage contiguously. * Paging is to deal with external fragmentation problem. This is to allow the logical address space of a process to be noncontiguous, which makes the process to be allocated physical memory.
  • 39.
    LOGICAL AND PHYSICALADDRESS • 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.
  • 40.
    *Logical Address orVirtual Address (represented in bits): An address generated by the CPU *Logical Address Space or Virtual Address Space( represented in words or bytes): The set of all logical addresses generated by a program Example: *If Logical Address = 31 bit, then Logical Address Space = 231 words = 2 G words (1 G = 230) *If Logical Address Space = 128 M words = 27 * 220 words, then Logical Address = log2 227 = 27 bits
  • 41.
    Physical Address identifiesa 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 user program generates the logical address and thinks that the program is running in this logical address but 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. The term Physical Address Space is used for all physical addresses corresponding to the logical addresses in a Logical address space. Example: *If Physical Address = 22 bit, then Physical Address Space = 222 words = 4 M words (1 M = 220) *If Physical Address Space = 16 M words = 24 * 220 words, then Physical Address = log2 224 = 24 bits
  • 42.
    Differences Between Logicaland Physical Address in Operating System *The basic difference between Logical and physical address is that Logical address is generated by CPU in perspective of a program whereas the physical address is a location that exists in the memory unit. *Logical Address Space is the set of all logical addresses generated by CPU for a program whereas the set of all physical address mapped to corresponding logical addresses is called Physical Address Space. *The logical address does not exist physically in the memory whereas physical address is a location in the memory that can be accessed physically. Identical logical addresses are generated by Compile-time and Load time address binding methods whereas they differs from each other in run-time address binding method. Please refer this for details. *The logical address is generated by the CPU while the program is running whereas the physical address is computed by the Memory Management Unit (MMU).
  • 43.
    The process ofTranslation from logical to physical addresses *Every address generated by the CPU is divided into two parts: a page number (p) and a page offset (d). The page number is used as an index into a page table. *The page table contains the base address of each page in physical memory. This base address is combined with the page offset to define the physical memory address that is sent to the memory unit. *If the size of logical-address space is 2m and a page size is 2n addressing units (bytes or words), then the high-order (m – n) bits of a logical address designate the page number and then low-order bits designate the page offset.
  • 44.
    Address generated byCPU is divided into Page number(p): Number of bits required to represent the pages in Logical Address Space or Page number Page offset(d): Number of bits required to represent particular word in a page or page size of Logical Address Space or word number of a page or page offset. Physical Address is divided into Frame number(f): Number of bits required to represent the frame of Physical Address Space or Frame number. Frame offset(d): Number of bits required to represent particular word in a frame or frame size of Physical Address Space or word number of a frame or frame offset.
  • 45.
    Let us consideran example: Physical Address = 12 bits, then Physical Address Space = 4 K words Logical Address = 13 bits, then Logical Address Space = 8 K words Page size = frame size = 1 K words (assumption)
  • 46.
    HARDWARE SUPPORT FORPAGING (Translation Lookaside Buffer (TLB) in Paging) or Paging hardware with TLB To overcome the size issue, the entire page table was kept in main memory. but the problem here is two main memory references are required: To find the frame number To go to the address specified by frame number To overcome this problem a high-speed cache is set up for page table entries called a Translation Lookaside Buffer (TLB) Translation Lookaside Buffer (TLB) is nothing but a special cache used to keep track of recently used transactions.
  • 47.
    TLB contains pagetable entries that have been most recently used. Given a virtual address, the processor examines the TLB if a page table entry is present (TLB hit), the frame number is retrieved and the real address is formed. If a page table entry is not found in the TLB (TLB miss), the page number is used to index the process page table. TLB first checks if the page is already in main memory, if not in main memory a page fault is issued then the TLB is updated to include the new page entry.
  • 48.
    Steps in TLBhit: *CPU generates virtual address. *It is checked in TLB (present). *Corresponding frame number is retrieved, which now tells where in the main memory page lies. Steps in Page miss: *CPU generates virtual address. *It is checked in TLB (not present). *Now the page number is matched to page table residing in main memory (assuming page table contains all PTE). *Corresponding frame number is retrieved, which now tells where in the main memory page lies. *The TLB is updated with new PTE (if space is not there, one of the replacement technique comes into picture i.e. either FIFU , LRU or MFU etc . Effective memory access time(EMAT) : TLB is used to reduce effective memory access time as it is a high speed associative cache. EMAT = h*(c+m) + (1-h)*(c+2m) where, h = hit ratio of TLB m = Memory access time c = TLB access time
  • 49.
    Effective memory accesstime(EMAT) : TLB is used to reduce effective memory access time as it is a high speed associative cache. EMAT = h*(c+m) + (1-h)*(c+2m) where, h = hit ratio of TLB m = Memory access time c = TLB access time
  • 50.
    TYPES OF PAGING •Two Level Paging The Pages are represented by the Virtual Address generated by the CPU. These Pages are mapped to Physical Address by the MMU. So, to help in this mapping we use the concept of Page Table. Just Like array, in page Table the indices represent the Page Numbers and the contents contain the address of the Frame Number where the the process is actually loaded in the main memory. Because the virtual/Logical Address is relative to zero and should be mapped to actual physical Address Space of Main Memory. The size of the page table can be calculated from the fact that size of each of entry of page table is given else if it is not given then we can find the number of bits required to address each frame in the main memory (this is not correct but should be used when nothing is given in question).
  • 51.
    Page Table Size= No. of Page Table Entries(Total no. of Pages) * (size of each entry of page table) When the Size of page table is less than the size of one Frame then we need not worry because we can directly put the page table in a frame of the main memory .Thus we can directly access the page table. But if the size of the page table is larger than the size of Frame. Then the page table in return is to be divided into several pages and these pages of the page table are to be stored in the main memory. Thus, a Outer Page Table comes into the picture. This Outer Page Table would contain the address of the Frames which contain the pages of Inner Page Table (i.e., Page Table one pages) in the main memory. The size of this Outer Page is also calculated in the same way as explained above and was used to calculate the size of inner page Table. Now if the size of inner page Table is Less Than or Equal to size of a Frame then we can stop here as we are able to keep the outer most table in a Single frame. This is called as Two Level Paging.
  • 52.
    TYPES OF PAGING:- •Multilevel Paging in Operating System Multilevel Paging is a paging scheme which consist of two or more levels of page tables in a hierarchical manner. It is also known as hierarchical paging. The entries of the level 1 page table are pointers to a level 2 page table and entries of the level 2 page tables are pointers to a level 3 page table and so on. The entries of the last level page table are stores actual frame information. Level 1 contain single page table and address of that table is stored in PTBR (Page Table Base Register). In multilevel paging whatever may be levels of paging all the page tables will be stored in main memory. So it requires more than one memory access to get the physical address of page frame. One access for each level needed. Each page table entry except the last level page table entry contains base address of the next level page table.
  • 54.
    Need of multilevelpaging:– *The need for multilevel paging arises when- *The size of page table is greater than the frame size. As a result, the page table can not be stored in a single frame in main memory. Working of multilevel paging:- In multilevel paging:- *The page table having size greater than the frame size is divided into several parts. *The size of each part is same as frame size except possibly the last part. *The pages of page table are then stored in different frames of the main memory. *To keep track of the frames storing the pages of the divided page table, another page table is maintained. *As a result, the hierarchy of page tables get generated. *Multilevel paging is done till the level is reached where the entire page table can be stored in a single frame.
  • 55.
    SEGMENTATION • In OperatingSystems, Segmentation is a memory management technique in which, the memory is divided into the variable size parts. Each part is known as segment which can be allocated to a process. • A process is divided into Segments. The chunks that a program is divided into which are not necessarily all of the same sizes are called segments. Segmentation gives user’s view of the process which paging does not give. Here the user’s view is mapped to physical memory.
  • 56.
    There are twotypes of segmentation: Virtual memory segmentation – Each process is divided into a number of segments, not all of which are resident at any one point in time. Simple segmentation – Each process is divided into a number of segments, all of which are loaded into memory at run time, though not necessarily contiguously. *There is no simple relationship between logical addresses and physical addresses in segmentation.
  • 57.
    A table storesthe information about all such segments and is called Segment Table. Segment Table – It maps two-dimensional Logical address into one- dimensional Physical address. It’s each table entry has: Base Address: It contains the starting physical address where the segments reside in memory. Limit: It specifies the length of the segment.
  • 58.
  • 59.
    Translation of Twodimensional Logical Address to one dimensional Physical Address. Address generated by the CPU is divided into: Segment number (s): Number of bits required to represent the segment. Segment offset (d): Number of bits required to represent the size of the segment
  • 60.
    TRANSLATION OF LOGICALADDRESS INTO PHYSICAL ADDRESS BY SEGMENT TABLE
  • 61.
    Advantages of Segmentation– *No Internal fragmentation. *Segment Table consumes less space in comparison to Page table in paging. *Average Segment Size is larger than the actual page size. *Less overhead *It is easier to relocate segments than entire address space. *The segment table is of lesser size as compare to the page table in paging. Disadvantage of Segmentation – *As processes are loaded and removed from the memory, the free memory space is broken into little pieces, causing External fragmentation. *It is difficult to allocate contiguous memory to variable sized partition. *Costly memory management algorithms.
  • 62.
    Why Segmentation isrequired? Till now, we were using Paging as our main memory management technique. Paging is more close to Operating system rather than the User. It divides all the process into the form of pages regardless of the fact that a process can have some relative parts of functions which needs to be loaded in the same page. 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 decreases the efficiency of the system. 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,
  • 63.
    Sr. No. KeypppPaging Segmentation 1 Memory Size In Paging, a process address space is broken into fixed sized blocks called pages. In Segmentation, a process address space is broken in varying sized blocks called sections. 2 Accountability Operating System divides the memory into pages. Compiler is responsible to calculate the segment size, the virtual address and actual address. 3 Size Page size is determined by available memory. Section size is determined by the user. 4 Speed Paging technique is faster in terms of memory access. Segmentation is slower than paging. 5 Fragmentation Paging can cause internal fragmentation as some pages may go underutilized. Segmentation can cause external fragmentation as some memory block may not be used at all. 6 Logical Address During paging, a logical address is divided into page number and page offset. During segmentation, a logical address is divided into section number and section offset. 7 Table During paging, a logical address is divided into page number and page offset. During segmentation, a logical address is divided into section number and section offset. 8 Data Storage Page table stores the page data. Segmentation table stores the segmentation data. DIFFERENCE BETWEEN PAGING AND SEGMENTATION PAGING SEGMENTATION
  • 64.
    THANKYOU BY MANISHA JHA B-TECHSTUDENT (CSE BRANCH)