You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2023/01/16 06:02:29 UTC

[GitHub] [nuttx] Donny9 opened a new pull request, #8131: mm/mm_heap/tlsf: support global mempool to optimize small block performance

Donny9 opened a new pull request, #8131:
URL: https://github.com/apache/nuttx/pull/8131

   ## Summary
   This PR is based on https://github.com/apache/nuttx/pull/8116.
   
   Support global mempool to optimize small block performance for default mm_heap and tlsf manager, you can enable this function by config CONFIG_MM_HEAP_MEMPOOL_THRESHOLD and CONFIG_MM_HEAP_MEMPOOL_EXPAND.
   
   
   
   * why need to add this mechanism?
       There are many small memory block in NuttX system, eg: struct tcb_s, struct inode, etc, and several disadvantages about them: 
   1.Their frequent allocate and free cause the system memory fragmentation.
   2.Since each memory block has an overhead, the utilization of small memory blocks is relatively low, which will cause memory waste.
   So we can use mempool to alloc smallo block, to improve alloc speed and utilization, to reduce fragmentation.
   
   * how to enable or config this mechanism?
   1. CONFIG_MM_HEAP_MEMPOOL_THRESHOLD is a size of threshold to avoid using multiple mempool in heap, If the size of the memory requested by the user is less than the threshold, the memory will be requested from the multiple mempool by default, default value is disable.
   2. CONFIG_MM_HEAP_MEMPOOL_EXPAND is a expand size for each mempool in multiple mempool, This size describes the size of each expansion of each memory pool with insufficient memory in the multi-level memory pool. default value is 4K.
   3. so, when CONFIG_MM_HEAP_MEMPOOL_THRESHOLD is 256 and CONFIG_MM_HEAP_MEMPOOL_EXPAND is 4K, 
   The system allocates memory lower than 256 from the multi-level memory pool, and allocates memory higher than 256 from the default heap manager(mm_heap/tlsf) and when the multi-level memory pool is insufficient, the size of each expansion is 4K.
   
   * Profile for this mechanism
   We test based on the environment of the Vela watch AP core, and runs three-party applications, monkey for gui, and graphical lunch on the ap. Among them, the three-party applications use memory very frequently and under great pressure.
   
   test items: (record the free command output log)
   1. default (mm_heap default manager), without enabling mempool and tlsf, run the monkey for testing.
   2. default with mempool (CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=256, CONFIG_MM_HEAP_MEMPOOL_EXPAND=1024) 
   3. default with mempool (CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=256, CONFIG_MM_HEAP_MEMPOOL_EXPAND=2048) 
   4. default with mempool (CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=256, CONFIG_MM_HEAP_MEMPOOL_EXPAND=4096) 
   5. default with mempool (CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=256, CONFIG_MM_HEAP_MEMPOOL_EXPAND=8192) 
   6. tlsf manager with mempool(CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=256, CONFIG_MM_HEAP_MEMPOOL_EXPAND=1024)
   7.  tlsf manager with mempool(CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=256, CONFIG_MM_HEAP_MEMPOOL_EXPAND=2048)
   8. tlsf manager with mempool(CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=256, CONFIG_MM_HEAP_MEMPOOL_EXPAND=4096/4096 with addr align8)
   9. tlsf manager with mempool(CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=256, CONFIG_MM_HEAP_MEMPOOL_EXPAND=8192/8192 with addr align8)
   
   test result charts:
   The data for all charts is based on the output of the free command
   * nfree(number of free blocks)
   p1:
   ![image](https://user-images.githubusercontent.com/70748590/212607232-0d45f4ab-e992-4704-b2d5-4e0a486d82f9.png)
   * nused(number of used blocks)
   p2:
   ![image](https://user-images.githubusercontent.com/70748590/212607444-c74f9a1f-6bca-4e75-a059-d31da37aeee4.png)
   p3:
   ![image](https://user-images.githubusercontent.com/70748590/212607452-8e7fbc43-b1f0-47b5-b220-d8e8c8aa4b54.png)
   * largest(the largest size of  free block)
   p4:
   ![image](https://user-images.githubusercontent.com/70748590/212607546-dec01452-7fa1-4422-8143-ec7a84d6bfdd.png)
   * free(the free memory size of system)
   p5:
   ![image](https://user-images.githubusercontent.com/70748590/212607633-42a11c44-cbb0-48b7-8864-eb570c7ba7c0.png)
   * used(the allocaed memory size of system)
   p6:
   ![image](https://user-images.githubusercontent.com/70748590/212607670-ce095de9-1f05-4ce2-9d48-0108c91b76d5.png)
   
   test result:
   1. From the comparison of the above figure, tlsf has relatively high fragmentation in each configuration, which is worse than NuttX's native heap manager.
   2. When the NuttX native heap manager and mempool manage the heap together, the mempool is used for management when the heap is less than 256 bytes, and the performance is the best when the mempool is insufficient and expanded to 4K each time, as shown in the **yellow** line in the figure.
   
   
   ## Impact
   Add global multi mempool to optimize small block performance
   ## Testing
   Vela CI test.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #8131: mm/mm_heap/tlsf: support global mempool to optimize small block performance

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #8131:
URL: https://github.com/apache/nuttx/pull/8131#issuecomment-1384323388

   > @Donny9 if TLSF generate more fragmentation than native NuttX heap manager, why we should use it?
   
   its' fast than nuttx's and has the constant execution time regardless the fragmentation. You can learn more info from:
   http://www.gii.upv.es/tlsf/main/docs
   Of course, the nuttx heap plus mempool could fast as TLSF.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] acassis commented on pull request #8131: mm/mm_heap/tlsf: support global mempool to optimize small block performance

Posted by GitBox <gi...@apache.org>.
acassis commented on PR #8131:
URL: https://github.com/apache/nuttx/pull/8131#issuecomment-1384217969

   @Donny9 if TLSF generate more fragmentation than native NuttX heap manager, why we should use it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] jerpelea merged pull request #8131: mm/mm_heap/tlsf: support global mempool to optimize small block performance

Posted by GitBox <gi...@apache.org>.
jerpelea merged PR #8131:
URL: https://github.com/apache/nuttx/pull/8131


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org