SlideShare una empresa de 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

Más contenido relacionado

La actualidad más candente

Real Time OS For Embedded Systems
Real Time OS For Embedded SystemsReal Time OS For Embedded Systems
Real Time OS For Embedded SystemsHimanshu Ghetia
 
Introduction to Embedded Architecture
Introduction to Embedded Architecture Introduction to Embedded Architecture
Introduction to Embedded Architecture amrutachintawar239
 
Case Study of Embedded Systems
Case Study of Embedded SystemsCase Study of Embedded Systems
Case Study of Embedded Systemsanand hd
 
Architecture of operating system
Architecture of operating systemArchitecture of operating system
Architecture of operating systemSupriya Kumari
 
Embedded systems - UNIT-1 - Mtech
Embedded systems - UNIT-1 - MtechEmbedded systems - UNIT-1 - Mtech
Embedded systems - UNIT-1 - Mtechsangeetha rakhi
 
Digital signal processor architecture
Digital signal processor architectureDigital signal processor architecture
Digital signal processor architecturekomal mistry
 
Control Unit Design
Control Unit DesignControl Unit Design
Control Unit DesignVinit Raut
 
ARM7-ARCHITECTURE
ARM7-ARCHITECTURE ARM7-ARCHITECTURE
ARM7-ARCHITECTURE Dr.YNM
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controllerTech_MX
 
UNIT-5 IoT Reference Architecture.pdf
UNIT-5 IoT Reference Architecture.pdfUNIT-5 IoT Reference Architecture.pdf
UNIT-5 IoT Reference Architecture.pdfMansiMehta96928
 
Control Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitControl Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitabdosaidgkv
 
Interrupt in real time system
Interrupt in real time system Interrupt in real time system
Interrupt in real time system ali jawad
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazationSiva Sathya
 
Cache memory
Cache memoryCache memory
Cache memoryAnuj Modi
 
Timing and control
Timing and controlTiming and control
Timing and controlchauhankapil
 

La actualidad más candente (20)

Real Time OS For Embedded Systems
Real Time OS For Embedded SystemsReal Time OS For Embedded Systems
Real Time OS For Embedded Systems
 
Introduction to Embedded Architecture
Introduction to Embedded Architecture Introduction to Embedded Architecture
Introduction to Embedded Architecture
 
Case Study of Embedded Systems
Case Study of Embedded SystemsCase Study of Embedded Systems
Case Study of Embedded Systems
 
E.s unit 6
E.s unit 6E.s unit 6
E.s unit 6
 
Architecture of operating system
Architecture of operating systemArchitecture of operating system
Architecture of operating system
 
Run time administration
Run time administrationRun time administration
Run time administration
 
Embedded systems - UNIT-1 - Mtech
Embedded systems - UNIT-1 - MtechEmbedded systems - UNIT-1 - Mtech
Embedded systems - UNIT-1 - Mtech
 
Digital signal processor architecture
Digital signal processor architectureDigital signal processor architecture
Digital signal processor architecture
 
Control Unit Design
Control Unit DesignControl Unit Design
Control Unit Design
 
ARM CORTEX M3 PPT
ARM CORTEX M3 PPTARM CORTEX M3 PPT
ARM CORTEX M3 PPT
 
Interrupts ppt
Interrupts pptInterrupts ppt
Interrupts ppt
 
ARM7-ARCHITECTURE
ARM7-ARCHITECTURE ARM7-ARCHITECTURE
ARM7-ARCHITECTURE
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controller
 
UNIT-5 IoT Reference Architecture.pdf
UNIT-5 IoT Reference Architecture.pdfUNIT-5 IoT Reference Architecture.pdf
UNIT-5 IoT Reference Architecture.pdf
 
Control Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitControl Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unit
 
Interrupt in real time system
Interrupt in real time system Interrupt in real time system
Interrupt in real time system
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
 
Cache memory
Cache memoryCache memory
Cache memory
 
Lambda design rule
Lambda design ruleLambda design rule
Lambda design rule
 
Timing and control
Timing and controlTiming and control
Timing and control
 

Similar a Memory Allocation Algorithms for Real-Time Systems

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
 
Cache memory ppt
Cache memory ppt  Cache memory ppt
Cache memory ppt Arpita Naik
 
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
 

Similar a Memory Allocation Algorithms for Real-Time Systems (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)
 
Cache memory ppt
Cache memory ppt  Cache memory ppt
Cache memory ppt
 
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
 

Último

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 

Último (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 

Memory Allocation Algorithms for Real-Time Systems

  • 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