Top Banner
Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools
53

Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Chapter 8 Real-Time Embedded Multithreading

Memory Management: Byte Pools And Block Pools

Page 2: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

OUTLINE (cont.)

Introduction Summary of Memory Byte Pools Memory Byte Pool Control Block Pitfalls of Memory Byte Pools Summary of Memory Byte Pool Services Memory Byte Pool Example Memory Byte Pool Internals

Page 3: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

OUTLINE

Summary of Memory Block Pools Memory Block Pool Control Block Summary of Memory Block Pool Services Memory Block Pool Example Memory Block Pool Internals

Page 4: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Introduction (cont.)

A memory byte pool is a contiguous block of bytes.

A memory block pool is also a contiguous block of bytes, but it is organized into a collection of fixed-size memory blocks.

Page 5: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Introduction

There is no fragmentation problem, and allocation and releasing memory blocks is fast.

In general, the use of memory block pools is preferred over memory byte pools.

Page 6: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pools (cont.)

ThreadX allocates memory from the memory byte pool in a first-fit manner.

ThreadX converts excess memory from this block into a new free memory, it merges adjacent free memory blocks together. This process is called defragmentation.

Page 7: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pools (cont.)

The number of allocatable bytes in a memory byte pool is slightly less than what was specified during creation

Each free memory block in the pool requires the equivalent of two C pointers of overhead.

Page 8: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pools (cont.)

ThreadX automatically divides it into two blocks , a large free block and a small permanently.

Application thread can suspend while waiting for memory bytes form a pool.

Page 9: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pools

tx_byte_pool_prioritize places the highest priority thread at front of the suspension list, while leaving all other suspended threads in the same FIFO order.

Page 10: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Byte Pool Control Block (cont.)

The characteristics of each memory byte pool are found in its Control Block.

Memory Byte Pool Control Blocks can be located anywhere in memory, but it is most common to make the Control Block a global structure by defining it outside the scope of any function.

Page 11: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Byte Pool Control Block

Page 12: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Pitfalls of Memory Byte Pools (cont.)

A memory byte pool may have 2000 bytes of memory available but not be able to satisfy an allocation request of even 1000 bytes.

There is no guarantee on how many of the free bytes are contiguous.

Page 13: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Pitfalls of Memory Byte Pools

There is no guarantee on how long it might take to find the block.

Many such applications pre-allocate their required memory during initialization or run-time configuration.

Users of byte pool allocated memory must not write outside its boundaries.

Page 14: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Creating a Memory Byte Pool

A memory byte pool is declared with the TX_BYTE_POOL data type and is defined with the tx_byte_pool_create

Page 15: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Page 16: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Allocating from a Memory Byte Pool

The tx_byte_allocate service is the method by witch bytes of memory are allocated from the memory byte pool.

If the allocation succeeds, the pointer memory_ptr contains the starting location of the allocated bytes.

Page 17: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Page 18: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Deleting a Memory Byte Pool

A memory pool can be deleted with the tx_byte_pool_delete service.

All threads that are suspended because they are waiting for memory from this byte pool are resumed and receive a TX_DELETED return status.

Page 19: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Page 20: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Retrieving Memory byte Pool Information

The tx_byte_pool_info_get service retrieves a variety of information about a memory byte pool.

Page 21: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Page 22: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Page 23: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Prioritizing a Memory Byte Pool Suspension List

The tx_byte_pool_prioritize service places the highest-priority thread suspended for ownership of a specific memory byte pool at the front of the suspension list.

All other thread remain in the same FIFO order in which they were suspended.

Page 24: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Page 25: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services (cont.)

Releasing Memory to a Byte Pool

The tx_byte_release service releases a previously allocated memory area block to its associated pool.

If one or more thread are suspended on this pool, each suspended thread receives the memory it requested and is resumed.

Page 26: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Byte Pool Services

Page 27: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Byte Pool Internals (cont.)

When the TX_BYTE_POOL data type is used to declare a byte pool, a Byte Pool Control Block is created, and that Control Block is added to a doubly linked circular list.

The pointer named tx_byte_pool_created_ptr points to the first Control Block in the list.

Page 28: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Byte Pool Internals (cont.)

ThreadX allocates from the pool in a first-fit manner, converts excess memory from this block into a new block, and places it back in the free memory list. This process is called fragmentation.

Page 29: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Byte Pool Internals (cont.)

This process is called fragmentation

ThreadX merges free memory blocks together during a subsequent allocation search for a large enough free memory block

This process is called defragmentation.

Page 30: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Byte Pool Internals (cont.)

Page 31: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Byte Pool Internals (cont.)

Page 32: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Byte Pool Internals

Page 33: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pools (cont.)

Memory block pools consist of fixed-size blocks, using them involves no fragmentation problem.

The allocation service does not have to search through a list of block.

Lack of flexibility is the main drawback of fixed-size memory pools.

Page 34: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pools (cont.)

Memory block pools contain a number of fixed-size blocks.

The block size, in bytes is specified during creation of the pool.

Each memory block in the pool imposes a small amount of overhead – the size of a C pointer

Page 35: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pools (cont.)

The number of memory blocks in a pool depends on the block size and the total number of bytes in the memory area supplied during creation.

The memory area for the block pool is specifies during creation , and can be located anywhere in the target’s address space.

Page 36: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pools (cont.)

tx_block_pool_prioritize places the highest priority thread at the front of the suspension list, while leaving all other suspended threads in the same FIFO order.

Page 37: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Block Pool Control Block (cont.)

The characteristics of each memory block pool are found in its Control Block .

The user of an allocated memory block must not write outside its boundaries.

Page 38: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Block Pool Control Block

Page 39: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Creating a Memory Block Pool

A memory block pool is declared with the TX_BLOCK_POOL data type and is defined with the tx_block_pool_create service.

Page 40: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Page 41: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Page 42: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Allocating a Memory Block Pool

The tx_block_allocate service is the method that allocates a fixed size block of memory form the memory block pool

Page 43: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Page 44: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Deleting a Memory Block Pool

A mymory block pool can be deleted with the tx_block_pool_delete service.

All threads that are suspended because they are waiting for memory from this block pool are resumed and receive a TX_DELETED return status.

Page 45: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Page 46: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Retrieving Memory Block Pool Information

The tx_block_pool_info_get service retrieves a variety of information about a memory block pool.

Page 47: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Page 48: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Prioritizing a Memory Block Pool Suspension List

The tx_block_pool_prioritize service place the highest-priority thread suspended for ownership of a specific memory block pool at the front of the suspension list.

All other threads remain in the same FIFO order in which they were suspended.

Page 49: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Page 50: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services (cont.)

Releasing a Memory Block

The tx_block_release service releases one previously allocated memory block back to its associated block pool.

If one or more threads are suspended on this pool, each suspended thread receives a memory block and is resumed until the pool runs out of blocks or until there are no more suspended threads.

Page 51: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Summary of Memory Block Pool Services

Page 52: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Block Pool Internals (cont.)

Page 53: Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools.

Memory Block Pool Internals