SlideShare a Scribd company logo
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

More Related Content

What's hot

Memory organization
Memory organizationMemory organization
Memory organization
Dr. Abhineet Anand
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memory
Deepak John
 
Cache coherence ppt
Cache coherence pptCache coherence ppt
Cache coherence ppt
ArendraSingh2
 
Direct memory access
Direct memory accessDirect memory access
Direct memory access
Roshan kumar sahu
 
Shared-Memory Multiprocessors
Shared-Memory MultiprocessorsShared-Memory Multiprocessors
Shared-Memory Multiprocessors
Salvatore La Bua
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controller
Tech_MX
 
Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and Architecture
Subhasis Dash
 
Distributed Shared Memory
Distributed Shared MemoryDistributed Shared Memory
Distributed Shared Memory
Prakhar Rastogi
 
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded Systems
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I   Core of Embedded SystemsSYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I   Core of Embedded Systems
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded Systems
Arti Parab Academics
 
8086 memory segmentation
8086 memory segmentation8086 memory segmentation
8086 memory segmentation
mahalakshmimalini
 
Real Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systemsReal Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systems
Hariharan Ganesan
 
Unit 5 Advanced Computer Architecture
Unit 5 Advanced Computer ArchitectureUnit 5 Advanced Computer Architecture
Unit 5 Advanced Computer Architecture
Balaji Vignesh
 
Direct Memory Access(DMA)
Direct Memory Access(DMA)Direct Memory Access(DMA)
Direct Memory Access(DMA)
Page Maker
 
cache memory
 cache memory cache memory
cache memory
NAHID HASAN
 
Direct memory access (dma)
Direct memory access (dma)Direct memory access (dma)
Direct memory access (dma)
Zubair Khalid
 
Static and Dynamic Read/Write memories
Static and Dynamic Read/Write memoriesStatic and Dynamic Read/Write memories
Static and Dynamic Read/Write memories
Abhilash Nair
 
Memory Organisation in embedded systems
Memory Organisation in embedded systemsMemory Organisation in embedded systems
Memory Organisation in embedded systems
UthraSowrirajan1
 
Memory system
Memory systemMemory system
Memory system
gourav kottawar
 
Cache coherence
Cache coherenceCache coherence
Cache coherence
Shyam Krishna Khadka
 
Interconnection Network
Interconnection NetworkInterconnection Network
Interconnection Network
Ali A Jalil
 

What's hot (20)

Memory organization
Memory organizationMemory organization
Memory organization
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memory
 
Cache coherence ppt
Cache coherence pptCache coherence ppt
Cache coherence ppt
 
Direct memory access
Direct memory accessDirect memory access
Direct memory access
 
Shared-Memory Multiprocessors
Shared-Memory MultiprocessorsShared-Memory Multiprocessors
Shared-Memory Multiprocessors
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controller
 
Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and Architecture
 
Distributed Shared Memory
Distributed Shared MemoryDistributed Shared Memory
Distributed Shared Memory
 
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded Systems
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I   Core of Embedded SystemsSYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I   Core of Embedded Systems
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded Systems
 
8086 memory segmentation
8086 memory segmentation8086 memory segmentation
8086 memory segmentation
 
Real Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systemsReal Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systems
 
Unit 5 Advanced Computer Architecture
Unit 5 Advanced Computer ArchitectureUnit 5 Advanced Computer Architecture
Unit 5 Advanced Computer Architecture
 
Direct Memory Access(DMA)
Direct Memory Access(DMA)Direct Memory Access(DMA)
Direct Memory Access(DMA)
 
cache memory
 cache memory cache memory
cache memory
 
Direct memory access (dma)
Direct memory access (dma)Direct memory access (dma)
Direct memory access (dma)
 
Static and Dynamic Read/Write memories
Static and Dynamic Read/Write memoriesStatic and Dynamic Read/Write memories
Static and Dynamic Read/Write memories
 
Memory Organisation in embedded systems
Memory Organisation in embedded systemsMemory Organisation in embedded systems
Memory Organisation in embedded systems
 
Memory system
Memory systemMemory system
Memory system
 
Cache coherence
Cache coherenceCache coherence
Cache coherence
 
Interconnection Network
Interconnection NetworkInterconnection Network
Interconnection Network
 

Similar to Memory allocation for real time operating system

MM RTOS.pptx
MM RTOS.pptxMM RTOS.pptx
MM RTOS.pptx
JAYTANWANI1
 
Cache Memory.pptx
Cache Memory.pptxCache Memory.pptx
Cache Memory.pptx
ssusere16bd9
 
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
Wednesday Solutions
 
Memory Managementgggffffffffffgggggggggg
Memory ManagementgggffffffffffggggggggggMemory Managementgggffffffffffgggggggggg
Memory Managementgggffffffffffgggggggggg
BHUPESHRAHANGDALE200
 
Opetating System Memory management
Opetating System Memory managementOpetating System Memory management
Opetating System Memory management
Johan Granados Montero
 
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 OS
Kumar Pritam
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
Rajapriya82
 
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
May Lau
 
Dos unit3
Dos unit3Dos unit3
Dos unit3
JebasheelaSJ
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
SandhyaTatekalva
 
Cache simulator
Cache simulatorCache simulator
Cache simulator
Suraj Saini
 
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 allocation
Vaibhav 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 system
mydheeswarandseec
 
Memory Management
Memory ManagementMemory Management
Memory Management
Shipra Swati
 
Chapter 9 OS
Chapter 9 OSChapter 9 OS
Chapter 9 OS
C.U
 
unit5_os (1).pptx
unit5_os (1).pptxunit5_os (1).pptx
unit5_os (1).pptx
PriyankaJadhav218236
 
Memory Hierarchy
Memory HierarchyMemory Hierarchy
Memory Hierarchy
SURBHI SAROHA
 

Similar to 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)
 
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
 

Recently uploaded

BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
Celine George
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
nitinpv4ai
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 

Recently uploaded (20)

BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 

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