Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Chapter 8 Real-Time Embedded Multithreading Memory Management: Byte Pools And Block Pools."— Presentation transcript:

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

2 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

3 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

4 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.

5 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.

6 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.

7 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.

8 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.

9 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.

10 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.

11 Memory Byte Pool Control Block

12 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.

13 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.

14 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

15 Summary of Memory Byte Pool Services (cont.)

16 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.

17 Summary of Memory Byte Pool Services (cont.)

18 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.

19 Summary of Memory Byte Pool Services (cont.)

20 Retrieving Memory byte Pool Information The tx_byte_pool_info_get service retrieves a variety of information about a memory byte pool.

21 Summary of Memory Byte Pool Services (cont.)

22

23 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.

24 Summary of Memory Byte Pool Services (cont.)

25 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.

26 Summary of Memory Byte Pool Services

27 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.

28 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.

29 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.

30 Memory Byte Pool Internals (cont.)

31

32 Memory Byte Pool Internals

33 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.

34 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

35 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.

36 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.

37 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.

38 Memory Block Pool Control Block

39 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.

40 Summary of Memory Block Pool Services (cont.)

41

42 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

43 Summary of Memory Block Pool Services (cont.)

44 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.

45 Summary of Memory Block Pool Services (cont.)

46 Retrieving Memory Block Pool Information The tx_block_pool_info_get service retrieves a variety of information about a memory block pool.

47 Summary of Memory Block Pool Services (cont.)

48 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.

49 Summary of Memory Block Pool Services (cont.)

50 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.

51 Summary of Memory Block Pool Services

52 Memory Block Pool Internals (cont.)

53 Memory Block Pool Internals


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

Similar presentations


Ads by Google