SlideShare uma empresa Scribd logo
1 de 19
Memory Allocation for Real Time
Operating System
Eng. Asma’a Lafi
1
Memory allocation
• Reserving memory moment to moment, as
needed, without having to reserve a fixed
amount ahead of time. Modern operating
systems perform dynamic memory allocation
for their own use. They may also perform the
same operation for their applications, or they
may include programming interface functions
(APIs such as malloc) that allow the
applications to allocate and de-allocate
memory as needed.
2
Memory allocation in RTOS
• Real time operating system uses different
memory allocation strategies and algorithm that
are used in order to improve the performance of
the intended system.
• Basically two types of memory allocation are
provided in RTOS stack and heap. The stack
allocation is used during context switching for
Task Control Blocks while heap allocation deals
with memory other than memory used for
program code and it is used for dynamic
allocation of data space for tasks. Allocation of
this memory is called heap allocation.
3
Memory allocation in RTOS (cont’d)
• Real time operating system
supports static and dynamic
memory allocation
Static memory
allocation
Dynamic memory
allocation
Memory is
allocated at
compile or design
time
Memory is
allocated at run
time
Memory allocation
is a deterministic
process that
means memory
allocation already
known
Requires memory
manager to keep
track which
memory are used
and which are not
No memory
allocation or
deallocation
actions are
performed during
execution
Memory allocation
is established and
destroyed during
the execution
4
Classification of Memory Allocation
Techniques.
5
Manual memory Allocation
• In manual memory allocation, the programmer has
direct control on process of memory is allocated
and recycling. Usually this is either by explicit
calls to heap allocation functions or by language
constructs that affect the stack.
• Advantage:
Manual memory allocation is easier for
programmers to understand and use.
• Disadvantage:
Memory allocation bugs are common when manual
memory allocation is used.
6
Automatic Memory Allocation
• Automatic memory allocation, usually do their job by
recycling blocks that are unreachable from program
variables.
• Advantage:
Automatic memory allocation eliminates most memory
allocation bugs.
• Disadvantage:
Sometimes automatic memory managers fail to deallocate
unused memory locations causing memory leaks.
Automatic memory mangers usually consume a great
amount of the CPU time and usually have nondeterministic
behavior.
7
DYNAMIC MEMORY ALLOCATION ALGORITHMS
Sequential Fit
Sequential fit is the most basic algorithm which uses a single linear list
of all free memory blocks called a free list. Free blocks are allocated
from this list in one of four ways :
 First fit: the list is searched from the beginning, returning the first
block large enough to satisfy the request
 Next fit: the list is searched from the place where the last search left
off, returning the next block large enough to satisfy the request
 Best fit: the list is searched exhaustively, returning the smallest block
large enough to satisfy the request.
 Worst fit : the list is searched; returning largest available free block .
8
DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d)
• Sequential Fit
Advantage:
Simple to understand and easy to apply.
Disadvantage:
As memory available for allocation becomes large, the search
time becomes large and in the worst case can be proportional to
the memory size.
As the free list becomes large, the memory used to store the
free list becomes large; hence the memory overhead becomes
large
Sequential Fit is not a good strategy for RTSs because it is
based on a sequential search, whose cost depends on the number
of existing free blocks.
9
DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d)
• Buddy allocator
A buddy allocator uses an array of free lists, one for each
allowable block size.
The buddy allocator rounds up the requested size to an
allowable size and allocates from the corresponding free
list. If the free list is empty, a larger block from another
free list is selected and split.
A block may only be split into a pair of buddies (of the
same size in case of binary buddy system).
A block may be coalesced only with its buddy, and this is
possible only if the buddy has not been split into smaller
blocks.
10
DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d)
• Buddy allocator
Advantage:
The advantage of a buddy system is that the
buddy of a block being freed can be quickly found
by a simple address computation.
Disadvantage:
The disadvantage of a buddy system is that the
restricted set of block sizes leads to high
internal fragmentation, as does the limited ability
to coalesce.
11
DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d)
Indexed Fit
Indexed fits are a class of allocation
mechanisms that use an indexing data
structure, such as a tree or hash table, to
identify suitable free blocks, according to the
allocation policy.
Advantage
This strategy is based on the use of advanced
structures to index the free memory blocks
thus provide better performance.
12
DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d)
Bitmapped Fit
Bitmapped Fits are a class of allocation
mechanisms that use a bitmap to represent
the usage of the heap. Each bit in the map
corresponds to a part of the heap, typically a
word, and is set if that part is in use.
Advantage:
In Bitmapped Fit mechanism, the search time
is proportional to the bitmap size which result
in a small memory overhead.
13
DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d)
Two Level Segregated Fit (TLSF)
 Two level segregated fit solves the problem of the worst case
bound maintaining the efficiency of the allocation and
deallocation operations allows the reasonable use of dynamic
memory allocation in real-time applications.
 provides explicit allocation and deallocation of memory. There
exists an increasing number of emerging applications using high
amounts of memory, such as multimedia systems, video
streaming.
 In order to meet these constraints and requirements, two level
segregated fit has been designed with guidelines like immediate
merging, splitting threshold for optimizes the memory usage
which tends to produce the lowest fragmentation on real
workloads.
14
DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d)
• Two Level Segregated Fit (TLSF)
 To implement a good-fit strategy two level segregated fit
algorithm uses a segregated fit mechanism. The basic
segregated fit mechanism uses an array of free lists, with each
array holding free blocks within a size class.
 In order to speed up the access to the free blocks and also to
manage a large set of segregated lists (to reduce
fragmentation) the array of lists has been organized as a two-
level array.
 The first-level array divides free blocks in classes that are a
power of two apart and the second-level sub-divides each first-
level class linearly, where the number of divisions can be
determined by the user. Each array of lists has an associated
bitmap used to mark which lists are empty and which ones
contain free blocks.
15
DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d)
Smart Memory Allocator
Smart Dynamic Memory Allocator is a new allocation
style which allows designing a custom dynamic
memory allocation mechanism with reduced memory
fragmentation and response time.
In this algorithm memory blocks is divided into to
types: Long lived block and Short lived block.
Directions of growing of heap is different for both
types of memory blocks. The short lived allocated
from bottom to top while the long lived block
allocated from top to bottom.
16
DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d)
Smart Memory Allocator
 A new smart dynamic memory allocator particularly for embedded
systems have limited memory and processing power.
 The smart allocator predict the short-lived objects and allocates those
objects on one side of the heap memory and remaining objects on other
side of the heap memory for effective use of memory footprint.
 The allocator reduces the memory fragmentation by using directional
adaptive allocation based on the predicted object lifetimes the lifetime
can be predicted using a mixture of block size and the number of
allocation events.
 The allocator is implemented with improved multilevel segregated
mechanism by means of lookup tables and hierarchical bitmaps that
guarantee very good response time and dependable timing performance.
17
Comparison between Different
Memory Allocation Algorithms
parameters
fragmentation Memory
footprint usage
Response time
Sequential fit Large Maximum Slow
Buddy System large Maximum Fast
Indexed fit large Maximum Fast
Bitmapped fit Large maximum Fast
TLSF Small Minimum Faster
Smart Memory
Allocator
reduce Minimum The fastest
18
CONCLUSION
• Dynamic memory allocation is used in many
real-time systems. In such systems there are
a lot of objects, which are referenced by
different threads.
• There are different memory allocation
algorithms are available.
• The major challenges of memory allocator are
minimizing fragmentation, providing a good
response time, and maintaining a good locality
among the memory blocks.
19

Mais conteúdo relacionado

Mais procurados

network ram parallel computing
network ram parallel computingnetwork ram parallel computing
network ram parallel computingNiranjana Ambadi
 
Real Time OS For Embedded Systems
Real Time OS For Embedded SystemsReal Time OS For Embedded Systems
Real Time OS For Embedded SystemsHimanshu Ghetia
 
Embedded system design process
Embedded system design processEmbedded system design process
Embedded system design processRayees CK
 
Chapter 12 - Mass Storage Systems
Chapter 12 - Mass Storage SystemsChapter 12 - Mass Storage Systems
Chapter 12 - Mass Storage SystemsWayne Jones Jnr
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory managementrprajat007
 
Embedded Systems (18EC62) – Embedded System Components (Module 3)
Embedded Systems (18EC62) – Embedded System Components (Module 3)Embedded Systems (18EC62) – Embedded System Components (Module 3)
Embedded Systems (18EC62) – Embedded System Components (Module 3)Shrishail Bhat
 
Cache memory ppt
Cache memory ppt  Cache memory ppt
Cache memory ppt Arpita Naik
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memoryDeepak John
 
RTOS for Embedded System Design
RTOS for Embedded System DesignRTOS for Embedded System Design
RTOS for Embedded System Designanand hd
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process CommunicationAdeel Rasheed
 
Memory management
Memory managementMemory management
Memory managementcpjcollege
 
RISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set ComputingRISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set ComputingTushar Swami
 

Mais procurados (20)

network ram parallel computing
network ram parallel computingnetwork ram parallel computing
network ram parallel computing
 
Real Time OS For Embedded Systems
Real Time OS For Embedded SystemsReal Time OS For Embedded Systems
Real Time OS For Embedded Systems
 
Embedded system design process
Embedded system design processEmbedded system design process
Embedded system design process
 
Memory virtualization
Memory virtualizationMemory virtualization
Memory virtualization
 
Chapter 12 - Mass Storage Systems
Chapter 12 - Mass Storage SystemsChapter 12 - Mass Storage Systems
Chapter 12 - Mass Storage Systems
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Embedded Systems (18EC62) – Embedded System Components (Module 3)
Embedded Systems (18EC62) – Embedded System Components (Module 3)Embedded Systems (18EC62) – Embedded System Components (Module 3)
Embedded Systems (18EC62) – Embedded System Components (Module 3)
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Cache memory ppt
Cache memory ppt  Cache memory ppt
Cache memory ppt
 
Branch prediction
Branch predictionBranch prediction
Branch prediction
 
Interrupts
InterruptsInterrupts
Interrupts
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memory
 
RTOS for Embedded System Design
RTOS for Embedded System DesignRTOS for Embedded System Design
RTOS for Embedded System Design
 
Interrupts ppt
Interrupts pptInterrupts ppt
Interrupts ppt
 
Vxworks
VxworksVxworks
Vxworks
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
 
Memory management
Memory managementMemory management
Memory management
 
RISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set ComputingRISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set Computing
 

Semelhante a Memory allocation for real time operating system

Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorWednesday Solutions
 
Memory Managementgggffffffffffgggggggggg
Memory ManagementgggffffffffffggggggggggMemory Managementgggffffffffffgggggggggg
Memory ManagementgggffffffffffggggggggggBHUPESHRAHANGDALE200
 
CSI-503 - 6. Memory Management
CSI-503 - 6. Memory Management CSI-503 - 6. Memory Management
CSI-503 - 6. Memory Management ghayour abbas
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSKumar Pritam
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptxRajapriya82
 
A kind of Algorithm that Extend MLC SSD Life Expectancy by 3 Folds
A kind of Algorithm that Extend MLC SSD Life Expectancy by 3 FoldsA kind of Algorithm that Extend MLC SSD Life Expectancy by 3 Folds
A kind of Algorithm that Extend MLC SSD Life Expectancy by 3 FoldsMay Lau
 
Linux Memory Management with CMA (Contiguous Memory Allocator)
Linux Memory Management with CMA (Contiguous Memory Allocator)Linux Memory Management with CMA (Contiguous Memory Allocator)
Linux Memory Management with CMA (Contiguous Memory Allocator)Pankaj Suryawanshi
 
Operating system 34 contiguous allocation
Operating system 34 contiguous allocationOperating system 34 contiguous allocation
Operating system 34 contiguous allocationVaibhav Khanna
 
Memory Management in real time operating system
Memory Management in real time operating systemMemory Management in real time operating system
Memory Management in real time operating systemmydheeswarandseec
 
Chapter 9 OS
Chapter 9 OSChapter 9 OS
Chapter 9 OSC.U
 

Semelhante a Memory allocation for real time operating system (20)

MM RTOS.pptx
MM RTOS.pptxMM RTOS.pptx
MM RTOS.pptx
 
Cache Memory.pptx
Cache Memory.pptxCache Memory.pptx
Cache Memory.pptx
 
Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage Collector
 
Memory Managementgggffffffffffgggggggggg
Memory ManagementgggffffffffffggggggggggMemory Managementgggffffffffffgggggggggg
Memory Managementgggffffffffffgggggggggg
 
Opetating System Memory management
Opetating System Memory managementOpetating System Memory management
Opetating System Memory management
 
CSI-503 - 6. Memory Management
CSI-503 - 6. Memory Management CSI-503 - 6. Memory Management
CSI-503 - 6. Memory Management
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
 
A kind of Algorithm that Extend MLC SSD Life Expectancy by 3 Folds
A kind of Algorithm that Extend MLC SSD Life Expectancy by 3 FoldsA kind of Algorithm that Extend MLC SSD Life Expectancy by 3 Folds
A kind of Algorithm that Extend MLC SSD Life Expectancy by 3 Folds
 
Dos unit3
Dos unit3Dos unit3
Dos unit3
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
 
Cache simulator
Cache simulatorCache simulator
Cache simulator
 
Linux Memory Management with CMA (Contiguous Memory Allocator)
Linux Memory Management with CMA (Contiguous Memory Allocator)Linux Memory Management with CMA (Contiguous Memory Allocator)
Linux Memory Management with CMA (Contiguous Memory Allocator)
 
Operating system 34 contiguous allocation
Operating system 34 contiguous allocationOperating system 34 contiguous allocation
Operating system 34 contiguous allocation
 
Memory Management in real time operating system
Memory Management in real time operating systemMemory Management in real time operating system
Memory Management in real time operating system
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Chapter 9 OS
Chapter 9 OSChapter 9 OS
Chapter 9 OS
 
unit5_os (1).pptx
unit5_os (1).pptxunit5_os (1).pptx
unit5_os (1).pptx
 
Memory Hierarchy
Memory HierarchyMemory Hierarchy
Memory Hierarchy
 
UNIT-2 OS.pptx
UNIT-2 OS.pptxUNIT-2 OS.pptx
UNIT-2 OS.pptx
 

Último

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Último (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Memory allocation for real time operating system

  • 1. Memory Allocation for Real Time Operating System Eng. Asma’a Lafi 1
  • 2. Memory allocation • Reserving memory moment to moment, as needed, without having to reserve a fixed amount ahead of time. Modern operating systems perform dynamic memory allocation for their own use. They may also perform the same operation for their applications, or they may include programming interface functions (APIs such as malloc) that allow the applications to allocate and de-allocate memory as needed. 2
  • 3. Memory allocation in RTOS • Real time operating system uses different memory allocation strategies and algorithm that are used in order to improve the performance of the intended system. • Basically two types of memory allocation are provided in RTOS stack and heap. The stack allocation is used during context switching for Task Control Blocks while heap allocation deals with memory other than memory used for program code and it is used for dynamic allocation of data space for tasks. Allocation of this memory is called heap allocation. 3
  • 4. Memory allocation in RTOS (cont’d) • Real time operating system supports static and dynamic memory allocation Static memory allocation Dynamic memory allocation Memory is allocated at compile or design time Memory is allocated at run time Memory allocation is a deterministic process that means memory allocation already known Requires memory manager to keep track which memory are used and which are not No memory allocation or deallocation actions are performed during execution Memory allocation is established and destroyed during the execution 4
  • 5. Classification of Memory Allocation Techniques. 5
  • 6. Manual memory Allocation • In manual memory allocation, the programmer has direct control on process of memory is allocated and recycling. Usually this is either by explicit calls to heap allocation functions or by language constructs that affect the stack. • Advantage: Manual memory allocation is easier for programmers to understand and use. • Disadvantage: Memory allocation bugs are common when manual memory allocation is used. 6
  • 7. Automatic Memory Allocation • Automatic memory allocation, usually do their job by recycling blocks that are unreachable from program variables. • Advantage: Automatic memory allocation eliminates most memory allocation bugs. • Disadvantage: Sometimes automatic memory managers fail to deallocate unused memory locations causing memory leaks. Automatic memory mangers usually consume a great amount of the CPU time and usually have nondeterministic behavior. 7
  • 8. DYNAMIC MEMORY ALLOCATION ALGORITHMS Sequential Fit Sequential fit is the most basic algorithm which uses a single linear list of all free memory blocks called a free list. Free blocks are allocated from this list in one of four ways :  First fit: the list is searched from the beginning, returning the first block large enough to satisfy the request  Next fit: the list is searched from the place where the last search left off, returning the next block large enough to satisfy the request  Best fit: the list is searched exhaustively, returning the smallest block large enough to satisfy the request.  Worst fit : the list is searched; returning largest available free block . 8
  • 9. DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d) • Sequential Fit Advantage: Simple to understand and easy to apply. Disadvantage: As memory available for allocation becomes large, the search time becomes large and in the worst case can be proportional to the memory size. As the free list becomes large, the memory used to store the free list becomes large; hence the memory overhead becomes large Sequential Fit is not a good strategy for RTSs because it is based on a sequential search, whose cost depends on the number of existing free blocks. 9
  • 10. DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d) • Buddy allocator A buddy allocator uses an array of free lists, one for each allowable block size. The buddy allocator rounds up the requested size to an allowable size and allocates from the corresponding free list. If the free list is empty, a larger block from another free list is selected and split. A block may only be split into a pair of buddies (of the same size in case of binary buddy system). A block may be coalesced only with its buddy, and this is possible only if the buddy has not been split into smaller blocks. 10
  • 11. DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d) • Buddy allocator Advantage: The advantage of a buddy system is that the buddy of a block being freed can be quickly found by a simple address computation. Disadvantage: The disadvantage of a buddy system is that the restricted set of block sizes leads to high internal fragmentation, as does the limited ability to coalesce. 11
  • 12. DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d) Indexed Fit Indexed fits are a class of allocation mechanisms that use an indexing data structure, such as a tree or hash table, to identify suitable free blocks, according to the allocation policy. Advantage This strategy is based on the use of advanced structures to index the free memory blocks thus provide better performance. 12
  • 13. DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d) Bitmapped Fit Bitmapped Fits are a class of allocation mechanisms that use a bitmap to represent the usage of the heap. Each bit in the map corresponds to a part of the heap, typically a word, and is set if that part is in use. Advantage: In Bitmapped Fit mechanism, the search time is proportional to the bitmap size which result in a small memory overhead. 13
  • 14. DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d) Two Level Segregated Fit (TLSF)  Two level segregated fit solves the problem of the worst case bound maintaining the efficiency of the allocation and deallocation operations allows the reasonable use of dynamic memory allocation in real-time applications.  provides explicit allocation and deallocation of memory. There exists an increasing number of emerging applications using high amounts of memory, such as multimedia systems, video streaming.  In order to meet these constraints and requirements, two level segregated fit has been designed with guidelines like immediate merging, splitting threshold for optimizes the memory usage which tends to produce the lowest fragmentation on real workloads. 14
  • 15. DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d) • Two Level Segregated Fit (TLSF)  To implement a good-fit strategy two level segregated fit algorithm uses a segregated fit mechanism. The basic segregated fit mechanism uses an array of free lists, with each array holding free blocks within a size class.  In order to speed up the access to the free blocks and also to manage a large set of segregated lists (to reduce fragmentation) the array of lists has been organized as a two- level array.  The first-level array divides free blocks in classes that are a power of two apart and the second-level sub-divides each first- level class linearly, where the number of divisions can be determined by the user. Each array of lists has an associated bitmap used to mark which lists are empty and which ones contain free blocks. 15
  • 16. DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d) Smart Memory Allocator Smart Dynamic Memory Allocator is a new allocation style which allows designing a custom dynamic memory allocation mechanism with reduced memory fragmentation and response time. In this algorithm memory blocks is divided into to types: Long lived block and Short lived block. Directions of growing of heap is different for both types of memory blocks. The short lived allocated from bottom to top while the long lived block allocated from top to bottom. 16
  • 17. DYNAMIC MEMORY ALLOCATION ALGORITHMS (cont’d) Smart Memory Allocator  A new smart dynamic memory allocator particularly for embedded systems have limited memory and processing power.  The smart allocator predict the short-lived objects and allocates those objects on one side of the heap memory and remaining objects on other side of the heap memory for effective use of memory footprint.  The allocator reduces the memory fragmentation by using directional adaptive allocation based on the predicted object lifetimes the lifetime can be predicted using a mixture of block size and the number of allocation events.  The allocator is implemented with improved multilevel segregated mechanism by means of lookup tables and hierarchical bitmaps that guarantee very good response time and dependable timing performance. 17
  • 18. Comparison between Different Memory Allocation Algorithms parameters fragmentation Memory footprint usage Response time Sequential fit Large Maximum Slow Buddy System large Maximum Fast Indexed fit large Maximum Fast Bitmapped fit Large maximum Fast TLSF Small Minimum Faster Smart Memory Allocator reduce Minimum The fastest 18
  • 19. CONCLUSION • Dynamic memory allocation is used in many real-time systems. In such systems there are a lot of objects, which are referenced by different threads. • There are different memory allocation algorithms are available. • The major challenges of memory allocator are minimizing fragmentation, providing a good response time, and maintaining a good locality among the memory blocks. 19