SlideShare a Scribd company logo
Memory Management
https://www.geeksforgeeks.org/memory-m
anagement-in-operating-system
/
Memory Management
•Memory Management is the process of controlling
and coordinating computer memory, assigning portions
known as blocks to various running programs to
optimize the overall performance of the system
•It is the most important function of an operating
system that manages primary memory.
•It helps processes to move back and forward between
the main memory and execution disk.
• It helps OS to keep track of every memory location,
irrespective of whether it is allocated to some process
or it remains free.
Memory Management techniques in operating systems
Memory Management techniques in operating systems
Why Use Memory Management?
•It allows you to check how much memory needs to
be allocated to processes that decide which processor
should get memory at what time.
•It allocates the space to application routines.
•It also make sure that these applications do not
interfere with each other.
•Helps protect different processes from each other
•It places the programs in memory so that memory is
utilized to its full extent.
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 hardware device called Memory-Management Unit is used
for mapping logical address to its corresponding physical
address.
•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.
Logical and Physical address
Mapping logical address to physical address
•The user program never sees the real physical
addresses.
•The program can be create a pointer to
location 346,store it in memory, manipulate it,
and compare it with other.
•The user program deals with logical addresses.
The memory mapping hardware converts logical
addresses into physical addresses.
Address Binding
•The Address Binding refers to the mapping of
computer instructions and data to physical
memory locations.
•The Association of program instruction and data
to the actual physical memory locations is called
the Address Binding or relocation.
Memory Management techniques in operating systems
Types of Address Binding
Compile-time Address Binding
Load time Address Binding
Execution time Address Binding
Compile-time Address
Binding
If the compiler is responsible of performing
address binding then it is called as compile time
address binding.
This type of address binding will be done before
loading the program into memory.
The compiler required to interact with the
operating system memory manager to perform
compile time address binding.
Load Time Address Binding
This type of address binding will be done
after loading the program into memory.
Load time address binding will be done by
operating memory manager.
Execution Time or
Dynamic Address Binding
The address binding will be postponed even after
loading the program into memory.
The program will keep on changing the locations
in the memory till the time of program execution.
This type of Address binding will be done by the
processor at the time of program execution.
The compiler, the program, and for any module
that needs to be included dynamically, that
provided only as a reference to them, and the rest
of the work will be done at runtime.
The complete program and all process data must
be in physical memory for the process to run.
Example – Dynamic loading occurs in Oops
languages ​
​
such as C++ and Java.
Dynamic loading
In static loading, Initially, the complete program is
loaded into the main memory before execution.
In the case of static loading, the entire program is
compiled and linked, leaving no program or external
module dependencies at compile time.
Static Loading is very useful when the program isn’t
too big or complicated, and when you plan to use the
program multiple times.
Example – Static loading is only done in the case of
structured programming languages ​
​
like C.
Static Loading
Memory Management Techniques
Contiguous memory allocation
 Contiguous memory allocation is basically a method
in which a single contiguous section/part of memory
is allocated to a process or file needing it.
 Because of this all the available memory space
resides at the same place together
 Which means that the freely/unused available
memory partitions are not distributed in a random
fashion here and there across the whole memory
space.
Contiguous memory allocation
Non-Contiguous memory allocation
 Non-Contiguous memory allocation is basically a
method which allocates the memory space present
in different locations to the process as per it’s
requirements.
 This technique of memory allocation helps to
reduce the wastage of memory, which eventually
gives rise to Internal and external fragmentation.
Non-Contiguous memory allocation
Contiguous Memory Management Techniques
Contiguous Technique can be divided into:
 Fixed (or static) partitioning
 Variable (or dynamic) partitioning
Fixed (or static) partitioning
This is the oldest and simplest technique used.
 In this partitioning, number of partitions 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.
Fixed (or static) partitioning contd..
What is Fragmentation?
•Processes are stored and removed from memory, which
creates free memory space, which are too small to use by
other processes.
•After sometimes, that processes not able to allocate to
memory blocks because its small size and memory blocks
always remain unused is called fragmentation.
•When free blocks are quite small, so it is not able to fulfill any
request.
What is Fragmentation? Contd..
Fragmentation is of two types
1. External fragmentation
Total memory space is enough to satisfy a request or
to reside a process in it, but it is not contiguous, so it
cannot be used.
2. Internal fragmentation
Memory block assigned to process is bigger. Some
portion of memory is left unused, as it cannot be used
by another process.
Internal fragmentation
 Internal fragmentation happens
when the memory is split into
mounted-sized blocks. Whenever a
method is requested for the memory,
the mounted-sized block is allotted to
the method.
 In the case where the memory
allotted to the method is somewhat
larger than the memory requested,
then the difference between allotted
and requested memory is called
internal fragmentation.
 We fixed the sizes of the memory
blocks, which has caused this issue. If
we use dynamic partitioning to allot
space to the process, this issue can be
solved.
External
Fragmentation
External fragmentation
External fragmentation occurs when a storage
medium, such as a hard disc or solid-state drive,
has many small blocks of free space scattered
throughout it.
This can happen when a system creates and
deletes files frequently, leaving many small blocks
of free space on the medium.
When a system needs to store a new file, it may be
unable to find a single contiguous block of free
space large enough to store the file and must
instead store the file in multiple smaller blocks.
This can cause external fragmentation and
performance problems when accessing the file.
Variable Partitioning
 Variable Partitioning 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.
Variable Partitioning
Various features associated with variable Partitioning-
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 utilization of RAM.
Number of partitions in RAM is not fixed and depends on the
number of incoming process and Main Memory’s size.
Variable Partitioning
Advantages of Variable Partitioning
1. 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.
2. 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.
3. 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
1. 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.
2. External Fragmentation:
There will be external fragmentation inspite of absence of
internal fragmentation.
Disadvantages of Variable Partitioning
Now P5 of size 3 MB cannot be
accommodated in spite of
required available space because
in contiguous no spanning is
allowed.
Compaction
•It is a method to overcome external fragmentation
•All free blocks are brought together to as one large
block of free space
•It requires dynamic free allocation
•It has cost and selection of optimal compaction
strategy is difficult
•One method for compaction is swapping
Compaction
How fragmentation can cause waste of memory and a
compaction technique can be used to create more
free memory out of fragmented memory
What is Swapping?
 Swapping is a method in which the process
should be swapped temporarily from the main
memory to the backing store.
 It will be later brought back into the memory for
continue execution.
 Backing store is a hard disk or some other
secondary storage device that should be big
enough inorder to accommodate copies of all
memory images for all users.
 It is also capable of offering direct access to these
memory images.
What is Swapping?
Benefits of Swapping
•It offers a higher degree of multiprogramming.
•Allows dynamic relocation. Processes can be swap in
different locations.
•It helps to get better utilization of memory.
•Minimum wastage of CPU time on completion so it can
easily be applied to a priority-based scheduling method
to improve its performance.
What is Memory allocation?
•Memory allocation is a process by which computer
programs are assigned memory or space.
Here, main memory is divided into two types of
partitions
•Low Memory - Operating system resides in this type
of memory.
•High Memory- User processes are held in high
memory.
Memory allocation technique/
Partition Allocation algorithm
•Memory is divided into different blocks or partitions.
Each process is allocated according to the requirement.
Below are the various partition allocation schemes :
•First Fit: In this type fit, the partition is allocated, which is
the first sufficient block from the beginning of the main
memory.
•Best Fit: It allocates the process to the partition that is
the first smallest partition among the free partitions.
•Worst Fit: It allocates the process to the partition, which
is the largest sufficient freely available partition in the
main memory.
Ex. Assume a process P4 comes with a memory requirement 3 KB.
Locate this process.
Non-Contiguous Memory
Allocation Technique
•In the non-contiguous memory allocation technique,
different parts of the same process are stored in
different places of the main memory.
Types:
•Paging [Fixed partitioning]
•Segmentation[Variable partitioning]
What is 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 equal
size frames.
•One page of the process is to be stored in one of the frames
of the memory.
What is Paging? Contd..
•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.
•The pages are mapped to the frames in Paging, page size
needs to be as same as frame size.
Paging concept
Memory Management techniques in operating systems
Memory Management techniques in operating systems
Address Mapping
Memory Management techniques in operating systems
Translation of logical Address into
physical Address
•As a CPU always generates a logical address and
we need a physical address for accessing the main
memory.
•This mapping is done by the MMU(memory
management Unit) with the help of the page table.
Translation of logical Address
into physical Address contd..
Logical Address: The logical address consists of two
parts page number and page offset.
1. Page Number: It tells the exact page of the process
which the CPU wants to access.
2. Page Offset: It tells the exact word on that page
which the CPU wants to read.
Logical Address = Page Number + Page Offset
Translation of logical Address into
physical Address contd..
Physical Address: The physical address consists of two
parts frame number and page offset.
1. Frame Number: It tells the exact frame where the page is
stored in physical memory.
2. Page Offset: It tells the exact word on that page which the
CPU wants to read. It requires no translation as the page size
is the same as the frame size.
Physical Address = Frame Number + Page Offset
Translation of logical Address into
physical Address contd..
Page table:
•A page table contains the frame number corresponding to
the page number of some specific process.
•The page table maps the page number to its actual location
(frame number) in the memory.
•So, each process will have its own page table. A register
called Page Table Base Register(PTBR) which holds the base
value of the page table.
How is the translation done?
•The CPU generates the logical address which
contains the page number and the page offset.
•The PTBR register contains the address of the page
table.
• Now, the page table helps in determining the frame
number corresponding to the page number.
• Now, with the help of frame number and the page
offset the physical address is determined and the
page is accessed in the main memory.
Memory Management techniques in operating systems
Advantages of Paging
•There is no external fragmentation as it allows us
to store the data in a non-contiguous way.
•Swapping is easy between equal-sized pages and
frames.
Disadvantages of Paging
•As the size of the frame is fixed, so it may suffer from
internal fragmentation. It may happen that the process is too
small and it may not acquire the entire frame size.
•The access time increases because of paging as the main
memory has to be now accessed two times. First, we need to
access the page table which is also stored in the main memory
and second, combine the frame number with the page offset
and then get the physical address of the page which is again
stored in the main memory.
•For every process, we have an independent page table and
maintaining the page table is extra overhead.
What is Segmentation?
Segmentation method works almost similarly to
paging. The only difference between the two is that
segments are of variable-length, whereas, in the
paging method, pages are always of fixed size.
What is Segmentation? Contd..
•In paging, we were blindly diving the process into
pages of fixed sizes but in segmentation, we divide
the process into modules for better visualization of
the process.
•Here each segment or module consists of the same
type of functions.
• For example, the main function is included in one
segment, library function is kept in other segments,
and so on.
•As the size of segments may vary, so memory is
divided into variable size parts.
Translation of logical Address into
physical Address
•As a CPU always generates a logical address and we
need a physical address for accessing the main
memory.
•This mapping is done by the MMU(memory
management Unit) with the help of the segment
table.
•The OS maintains a segment map table for all the
processes.
Translation of logical Address into
physical Address contd..
Logical Address: The logical address consists of two
parts segment number and segment offset.
1. Segment Number: It tells the specific segment of
the process from which the CPU wants to read the
data.
2. Segment Offset: It tells the exact word in that
segment which the CPU wants to read.
Logical Address = Segment Number + Segment Offset
Translation of logical Address
into physical Address contd..
Physical Address:
The physical address is obtained by adding the base
address of the segment to the segment offset.
Segment table:
A segment table stores the base address of each
segment in the main memory. It has two parts
i.e. Base and Limit.
Base indicates the base address or starting address of
the segment in the main memory.
Limit tells the size of that segment.
A register called Segment Table Base Register(STBR)
which holds the base value of the segment table.
Translation of logical Address into
physical Address contd..
How is the translation done?
•The CPU generates the logical address which contains the
segment number and the segment offset.
•STBR register contains the address of the segment table.
Now, the segment table helps in determining the base address
of the segment corresponding to the segment number.
•Now, the segment offset is compared with the limit
corresponding to the Base.
How is the translation done? Contd..
•If the segment offset is greater than the limit then it is an
invalid address.
•This is because the CPU is trying to access a word in the
segment and this value is greater than the size of the segment
itself which is not possible.
• If the segment offset is less than or equal to the limit then
only the request is accepted.
•The physical address is generated by adding the base address
of the segment to the segment offset.
Memory Management techniques in operating systems
Advantages of Segmentation
•The size of the segment table is less compared to the
size of the page table.
•There is no internal fragmentation.
Disadvantages of Segmentation
•When the processes are loaded and removed ( during
swapping ) from the main memory then free memory spaces
are broken into smaller pieces and this causes external
fragmentation.
•Here also the time to access the data increases as due to
segmentation the main memory has to be now accessed two
times. First, we need to access the segment table which is
also stored in the main memory and second, combine the
base address of the segment with the segment offset and
then get the physical address which is again stored in the
main memory.

More Related Content

What's hot (20)

PPTX
Process management os concept
priyadeosarkar91
 
PPTX
Operating system paging and segmentation
hamza haseeb
 
PPTX
Introduction to Operating Systems
Trinity Dwarka
 
PPT
Software System Engineering - Chapter 1
Fadhil Ismail
 
PPTX
File Management in Operating System
Janki Shah
 
PPT
06 External Memory
Jeanie Delos Arcos
 
PPTX
COCOMO MODEL 1 And 2
Awais Siddique
 
PPTX
Concurrency
rizwanaabassi
 
PPTX
chapter 2 memory and process management
Aisyah Rafiuddin
 
PPTX
Storage Structure in OS
UniSoftCorner Pvt Ltd India.
 
PPTX
Process Synchronization in operating system | mutex | semaphore | race condition
Shivam Mitra
 
PPT
Os Threads
Salman Memon
 
PPT
Virtual memory
aaina_katyal
 
PDF
Chapter12
Loyd Morales
 
PDF
Unit 2: Programming Language Tools
Dr Piyush Charan
 
PPTX
contiguous memory allocation.pptx
Rajapriya82
 
PPT
Introduction to Compiler Construction
Sarmad Ali
 
PPTX
VIRTUAL MEMORY
Kamran Ashraf
 
PPTX
System components (os)
snegacmr
 
PPTX
Android Architecture.pptx
priya Nithya
 
Process management os concept
priyadeosarkar91
 
Operating system paging and segmentation
hamza haseeb
 
Introduction to Operating Systems
Trinity Dwarka
 
Software System Engineering - Chapter 1
Fadhil Ismail
 
File Management in Operating System
Janki Shah
 
06 External Memory
Jeanie Delos Arcos
 
COCOMO MODEL 1 And 2
Awais Siddique
 
Concurrency
rizwanaabassi
 
chapter 2 memory and process management
Aisyah Rafiuddin
 
Storage Structure in OS
UniSoftCorner Pvt Ltd India.
 
Process Synchronization in operating system | mutex | semaphore | race condition
Shivam Mitra
 
Os Threads
Salman Memon
 
Virtual memory
aaina_katyal
 
Chapter12
Loyd Morales
 
Unit 2: Programming Language Tools
Dr Piyush Charan
 
contiguous memory allocation.pptx
Rajapriya82
 
Introduction to Compiler Construction
Sarmad Ali
 
VIRTUAL MEMORY
Kamran Ashraf
 
System components (os)
snegacmr
 
Android Architecture.pptx
priya Nithya
 

Similar to Memory Management techniques in operating systems (20)

PPT
memory managment on computer science.ppt
footydigarse
 
PPTX
B.Tech. Computer Science Engineering OS Notes Unit 3
likatif784
 
PDF
CSI-503 - 6. Memory Management
ghayour abbas
 
PPT
Unit 4_ Memory Management Memory ManagementMemory ManagementMemory Management...
harsh1212000552
 
PPTX
Memory Management in Operating Systems ppt.pptx
bhaimodel20
 
PPTX
Memory Management in System Designing.pptx
errvmaurya563
 
DOCX
Opetating System Memory management
Johan Granados Montero
 
PDF
OS_Unit-4 Operating system class notes for the reference of the semister ...
downloadingmoviesato
 
PDF
OS-III UNIT IN CS3402 Operating System about Deadlock
mdgopal2002
 
PPTX
Memory Managementgggffffffffffgggggggggg
BHUPESHRAHANGDALE200
 
PPT
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
PPT
OS-unit-3 part -1mxmxmxmmxmxmmxmxmxmxmxmmxmxmmx.ppt
SNIGDHAAPPANABHOTLA
 
DOCX
Operating system
Hussain Ahmady
 
PDF
muja osjkkhkhkkhkkkfdxfdfddkhvjlbjljlhgg
mujahidHajishifa
 
PPTX
HW29kkkkkkkkkkkkkkkkkkkmmmmkkmmkkk454.pptx
SumukhUmesh2
 
DOCX
Memory management
lodhran-hayat
 
PPTX
Operating system memory management
rprajat007
 
PPTX
memorymanagement-2112140500ygyftftt34.pptx
bishalnandi2
 
PPTX
Module 4 - Operating Systems presentation four
adityaduggi0
 
PPTX
Memory management
PATELARCH
 
memory managment on computer science.ppt
footydigarse
 
B.Tech. Computer Science Engineering OS Notes Unit 3
likatif784
 
CSI-503 - 6. Memory Management
ghayour abbas
 
Unit 4_ Memory Management Memory ManagementMemory ManagementMemory Management...
harsh1212000552
 
Memory Management in Operating Systems ppt.pptx
bhaimodel20
 
Memory Management in System Designing.pptx
errvmaurya563
 
Opetating System Memory management
Johan Granados Montero
 
OS_Unit-4 Operating system class notes for the reference of the semister ...
downloadingmoviesato
 
OS-III UNIT IN CS3402 Operating System about Deadlock
mdgopal2002
 
Memory Managementgggffffffffffgggggggggg
BHUPESHRAHANGDALE200
 
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
OS-unit-3 part -1mxmxmxmmxmxmmxmxmxmxmxmmxmxmmx.ppt
SNIGDHAAPPANABHOTLA
 
Operating system
Hussain Ahmady
 
muja osjkkhkhkkhkkkfdxfdfddkhvjlbjljlhgg
mujahidHajishifa
 
HW29kkkkkkkkkkkkkkkkkkkmmmmkkmmkkk454.pptx
SumukhUmesh2
 
Memory management
lodhran-hayat
 
Operating system memory management
rprajat007
 
memorymanagement-2112140500ygyftftt34.pptx
bishalnandi2
 
Module 4 - Operating Systems presentation four
adityaduggi0
 
Memory management
PATELARCH
 
Ad

More from backiyalakshmi14 (9)

PPTX
Introduction to database management system
backiyalakshmi14
 
PPTX
Normalization in Relational database management systems
backiyalakshmi14
 
PPTX
Jquery in web development, including Jquery in HTML
backiyalakshmi14
 
PPTX
sequential circuits, flip flops and Latches
backiyalakshmi14
 
PPTX
Flipflop & Latches, RS Flipflop, NOR and NAND Gate Circuits
backiyalakshmi14
 
PPTX
Half adders and full adders in digital principles
backiyalakshmi14
 
PPTX
Basic gates in electronics and digital Principles
backiyalakshmi14
 
PPTX
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
PPTX
HUMAN VALUES DEVELOPMENT for skill development
backiyalakshmi14
 
Introduction to database management system
backiyalakshmi14
 
Normalization in Relational database management systems
backiyalakshmi14
 
Jquery in web development, including Jquery in HTML
backiyalakshmi14
 
sequential circuits, flip flops and Latches
backiyalakshmi14
 
Flipflop & Latches, RS Flipflop, NOR and NAND Gate Circuits
backiyalakshmi14
 
Half adders and full adders in digital principles
backiyalakshmi14
 
Basic gates in electronics and digital Principles
backiyalakshmi14
 
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
HUMAN VALUES DEVELOPMENT for skill development
backiyalakshmi14
 
Ad

Recently uploaded (20)

PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Dimensions of Societal Planning in Commonism
StefanMz
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
community health nursing question paper 2.pdf
Prince kumar
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 

Memory Management techniques in operating systems

  • 2. Memory Management •Memory Management is the process of controlling and coordinating computer memory, assigning portions known as blocks to various running programs to optimize the overall performance of the system •It is the most important function of an operating system that manages primary memory. •It helps processes to move back and forward between the main memory and execution disk. • It helps OS to keep track of every memory location, irrespective of whether it is allocated to some process or it remains free.
  • 5. Why Use Memory Management? •It allows you to check how much memory needs to be allocated to processes that decide which processor should get memory at what time. •It allocates the space to application routines. •It also make sure that these applications do not interfere with each other. •Helps protect different processes from each other •It places the programs in memory so that memory is utilized to its full extent.
  • 6. 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 hardware device called Memory-Management Unit is used for mapping logical address to its corresponding physical address.
  • 7. •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. Logical and Physical address
  • 8. Mapping logical address to physical address
  • 9. •The user program never sees the real physical addresses. •The program can be create a pointer to location 346,store it in memory, manipulate it, and compare it with other. •The user program deals with logical addresses. The memory mapping hardware converts logical addresses into physical addresses.
  • 10. Address Binding •The Address Binding refers to the mapping of computer instructions and data to physical memory locations. •The Association of program instruction and data to the actual physical memory locations is called the Address Binding or relocation.
  • 12. Types of Address Binding Compile-time Address Binding Load time Address Binding Execution time Address Binding
  • 13. Compile-time Address Binding If the compiler is responsible of performing address binding then it is called as compile time address binding. This type of address binding will be done before loading the program into memory. The compiler required to interact with the operating system memory manager to perform compile time address binding.
  • 14. Load Time Address Binding This type of address binding will be done after loading the program into memory. Load time address binding will be done by operating memory manager.
  • 15. Execution Time or Dynamic Address Binding The address binding will be postponed even after loading the program into memory. The program will keep on changing the locations in the memory till the time of program execution. This type of Address binding will be done by the processor at the time of program execution.
  • 16. The compiler, the program, and for any module that needs to be included dynamically, that provided only as a reference to them, and the rest of the work will be done at runtime. The complete program and all process data must be in physical memory for the process to run. Example – Dynamic loading occurs in Oops languages ​ ​ such as C++ and Java. Dynamic loading
  • 17. In static loading, Initially, the complete program is loaded into the main memory before execution. In the case of static loading, the entire program is compiled and linked, leaving no program or external module dependencies at compile time. Static Loading is very useful when the program isn’t too big or complicated, and when you plan to use the program multiple times. Example – Static loading is only done in the case of structured programming languages ​ ​ like C. Static Loading
  • 19. Contiguous memory allocation  Contiguous memory allocation is basically a method in which a single contiguous section/part of memory is allocated to a process or file needing it.  Because of this all the available memory space resides at the same place together  Which means that the freely/unused available memory partitions are not distributed in a random fashion here and there across the whole memory space.
  • 21. Non-Contiguous memory allocation  Non-Contiguous memory allocation is basically a method which allocates the memory space present in different locations to the process as per it’s requirements.  This technique of memory allocation helps to reduce the wastage of memory, which eventually gives rise to Internal and external fragmentation.
  • 23. Contiguous Memory Management Techniques Contiguous Technique can be divided into:  Fixed (or static) partitioning  Variable (or dynamic) partitioning
  • 24. Fixed (or static) partitioning This is the oldest and simplest technique used.  In this partitioning, number of partitions 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.
  • 25. Fixed (or static) partitioning contd..
  • 26. What is Fragmentation? •Processes are stored and removed from memory, which creates free memory space, which are too small to use by other processes. •After sometimes, that processes not able to allocate to memory blocks because its small size and memory blocks always remain unused is called fragmentation. •When free blocks are quite small, so it is not able to fulfill any request.
  • 27. What is Fragmentation? Contd.. Fragmentation is of two types 1. External fragmentation Total memory space is enough to satisfy a request or to reside a process in it, but it is not contiguous, so it cannot be used. 2. Internal fragmentation Memory block assigned to process is bigger. Some portion of memory is left unused, as it cannot be used by another process.
  • 28. Internal fragmentation  Internal fragmentation happens when the memory is split into mounted-sized blocks. Whenever a method is requested for the memory, the mounted-sized block is allotted to the method.  In the case where the memory allotted to the method is somewhat larger than the memory requested, then the difference between allotted and requested memory is called internal fragmentation.  We fixed the sizes of the memory blocks, which has caused this issue. If we use dynamic partitioning to allot space to the process, this issue can be solved.
  • 30. External fragmentation External fragmentation occurs when a storage medium, such as a hard disc or solid-state drive, has many small blocks of free space scattered throughout it. This can happen when a system creates and deletes files frequently, leaving many small blocks of free space on the medium. When a system needs to store a new file, it may be unable to find a single contiguous block of free space large enough to store the file and must instead store the file in multiple smaller blocks. This can cause external fragmentation and performance problems when accessing the file.
  • 31. Variable Partitioning  Variable Partitioning 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.
  • 32. Variable Partitioning Various features associated with variable Partitioning- 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 utilization of RAM. Number of partitions in RAM is not fixed and depends on the number of incoming process and Main Memory’s size.
  • 34. Advantages of Variable Partitioning 1. 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. 2. 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. 3. 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.
  • 35. Disadvantages of Variable Partitioning 1. 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. 2. External Fragmentation: There will be external fragmentation inspite of absence of internal fragmentation.
  • 36. Disadvantages of Variable Partitioning Now P5 of size 3 MB cannot be accommodated in spite of required available space because in contiguous no spanning is allowed.
  • 37. Compaction •It is a method to overcome external fragmentation •All free blocks are brought together to as one large block of free space •It requires dynamic free allocation •It has cost and selection of optimal compaction strategy is difficult •One method for compaction is swapping
  • 39. How fragmentation can cause waste of memory and a compaction technique can be used to create more free memory out of fragmented memory
  • 40. What is Swapping?  Swapping is a method in which the process should be swapped temporarily from the main memory to the backing store.  It will be later brought back into the memory for continue execution.  Backing store is a hard disk or some other secondary storage device that should be big enough inorder to accommodate copies of all memory images for all users.  It is also capable of offering direct access to these memory images.
  • 42. Benefits of Swapping •It offers a higher degree of multiprogramming. •Allows dynamic relocation. Processes can be swap in different locations. •It helps to get better utilization of memory. •Minimum wastage of CPU time on completion so it can easily be applied to a priority-based scheduling method to improve its performance.
  • 43. What is Memory allocation? •Memory allocation is a process by which computer programs are assigned memory or space. Here, main memory is divided into two types of partitions •Low Memory - Operating system resides in this type of memory. •High Memory- User processes are held in high memory.
  • 44. Memory allocation technique/ Partition Allocation algorithm •Memory is divided into different blocks or partitions. Each process is allocated according to the requirement. Below are the various partition allocation schemes : •First Fit: In this type fit, the partition is allocated, which is the first sufficient block from the beginning of the main memory. •Best Fit: It allocates the process to the partition that is the first smallest partition among the free partitions. •Worst Fit: It allocates the process to the partition, which is the largest sufficient freely available partition in the main memory.
  • 45. Ex. Assume a process P4 comes with a memory requirement 3 KB. Locate this process.
  • 46. Non-Contiguous Memory Allocation Technique •In the non-contiguous memory allocation technique, different parts of the same process are stored in different places of the main memory. Types: •Paging [Fixed partitioning] •Segmentation[Variable partitioning]
  • 47. What is 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 equal size frames. •One page of the process is to be stored in one of the frames of the memory.
  • 48. What is Paging? Contd.. •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. •The pages are mapped to the frames in Paging, page size needs to be as same as frame size.
  • 54. Translation of logical Address into physical Address •As a CPU always generates a logical address and we need a physical address for accessing the main memory. •This mapping is done by the MMU(memory management Unit) with the help of the page table.
  • 55. Translation of logical Address into physical Address contd.. Logical Address: The logical address consists of two parts page number and page offset. 1. Page Number: It tells the exact page of the process which the CPU wants to access. 2. Page Offset: It tells the exact word on that page which the CPU wants to read. Logical Address = Page Number + Page Offset
  • 56. Translation of logical Address into physical Address contd.. Physical Address: The physical address consists of two parts frame number and page offset. 1. Frame Number: It tells the exact frame where the page is stored in physical memory. 2. Page Offset: It tells the exact word on that page which the CPU wants to read. It requires no translation as the page size is the same as the frame size. Physical Address = Frame Number + Page Offset
  • 57. Translation of logical Address into physical Address contd.. Page table: •A page table contains the frame number corresponding to the page number of some specific process. •The page table maps the page number to its actual location (frame number) in the memory. •So, each process will have its own page table. A register called Page Table Base Register(PTBR) which holds the base value of the page table.
  • 58. How is the translation done? •The CPU generates the logical address which contains the page number and the page offset. •The PTBR register contains the address of the page table. • Now, the page table helps in determining the frame number corresponding to the page number. • Now, with the help of frame number and the page offset the physical address is determined and the page is accessed in the main memory.
  • 60. Advantages of Paging •There is no external fragmentation as it allows us to store the data in a non-contiguous way. •Swapping is easy between equal-sized pages and frames.
  • 61. Disadvantages of Paging •As the size of the frame is fixed, so it may suffer from internal fragmentation. It may happen that the process is too small and it may not acquire the entire frame size. •The access time increases because of paging as the main memory has to be now accessed two times. First, we need to access the page table which is also stored in the main memory and second, combine the frame number with the page offset and then get the physical address of the page which is again stored in the main memory. •For every process, we have an independent page table and maintaining the page table is extra overhead.
  • 62. What is Segmentation? Segmentation method works almost similarly to paging. The only difference between the two is that segments are of variable-length, whereas, in the paging method, pages are always of fixed size.
  • 63. What is Segmentation? Contd.. •In paging, we were blindly diving the process into pages of fixed sizes but in segmentation, we divide the process into modules for better visualization of the process. •Here each segment or module consists of the same type of functions. • For example, the main function is included in one segment, library function is kept in other segments, and so on. •As the size of segments may vary, so memory is divided into variable size parts.
  • 64. Translation of logical Address into physical Address •As a CPU always generates a logical address and we need a physical address for accessing the main memory. •This mapping is done by the MMU(memory management Unit) with the help of the segment table. •The OS maintains a segment map table for all the processes.
  • 65. Translation of logical Address into physical Address contd.. Logical Address: The logical address consists of two parts segment number and segment offset. 1. Segment Number: It tells the specific segment of the process from which the CPU wants to read the data. 2. Segment Offset: It tells the exact word in that segment which the CPU wants to read. Logical Address = Segment Number + Segment Offset
  • 66. Translation of logical Address into physical Address contd.. Physical Address: The physical address is obtained by adding the base address of the segment to the segment offset.
  • 67. Segment table: A segment table stores the base address of each segment in the main memory. It has two parts i.e. Base and Limit. Base indicates the base address or starting address of the segment in the main memory. Limit tells the size of that segment. A register called Segment Table Base Register(STBR) which holds the base value of the segment table. Translation of logical Address into physical Address contd..
  • 68. How is the translation done? •The CPU generates the logical address which contains the segment number and the segment offset. •STBR register contains the address of the segment table. Now, the segment table helps in determining the base address of the segment corresponding to the segment number. •Now, the segment offset is compared with the limit corresponding to the Base.
  • 69. How is the translation done? Contd.. •If the segment offset is greater than the limit then it is an invalid address. •This is because the CPU is trying to access a word in the segment and this value is greater than the size of the segment itself which is not possible. • If the segment offset is less than or equal to the limit then only the request is accepted. •The physical address is generated by adding the base address of the segment to the segment offset.
  • 71. Advantages of Segmentation •The size of the segment table is less compared to the size of the page table. •There is no internal fragmentation.
  • 72. Disadvantages of Segmentation •When the processes are loaded and removed ( during swapping ) from the main memory then free memory spaces are broken into smaller pieces and this causes external fragmentation. •Here also the time to access the data increases as due to segmentation the main memory has to be now accessed two times. First, we need to access the segment table which is also stored in the main memory and second, combine the base address of the segment with the segment offset and then get the physical address which is again stored in the main memory.