2. What is Memory Management in RTOS
The memory management function of an RTOS kernel is slightly different
compared to the General Purpose Operating Systems.
The memory allocation time increases depending on the size of the block of
memory.
Needs to be allocated and the state of the allocated memory block (initialized
memory block consumes more allocation time than un initialized memory
block)
3. Since predictable timing and deterministic behavior are the primary focus for
an RTOS.
RTOS achieves this by compromising the effectiveness of memory allocation.
RTOS generally uses 'block' based memory allocation technique, instead of the
usual dynamic memory allocation techniques used by the GPOS.
RTOS kernel uses blocks of fixed size of dynamic memory and the block is
allocated for a task on a need basis.
The blocks are stored in a 'Free buffer Queue’.
4. Most of the RTOS kernels allow tasks to access any of the memory blocks
without any memory protection to achieve predictable timing and avoid the
timing overheads.
RTOS kernels assume that the whole design is proven correct and protection is
unnecessary.
Some commercial RTOS kernels allow memory protection as optional and the
kernel enters a fail-safe mode when an illegal memory access occurs.
The memory management function of an RTOS kernel is slightly different
compared to the General Purpose Operating Systems.
A few RTOS kernels implement VirtualMemory concept for memory allocationIf
the system supports secondary memory storage (like HDD and FLASH
memory).
7. 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
8. 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.
9. 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 .
11. Outcome
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.