• 中国计算机学会会刊
  • 中国科技核心期刊
  • 中文核心期刊

计算机工程与科学 ›› 2024, Vol. 46 ›› Issue (11): 1916-1923.

• 高性能计算 • 上一篇    下一篇

基于TLSF算法的高效内存分配算法的设计与实现

陈朝辉1,段雄2   

  1. (1.中国科学技术大学先进技术研究院,安徽 合肥 230031;2.安徽华米信息科技有限公司,安徽 合肥 230088)
  • 收稿日期:2023-07-08 修回日期:2023-10-07 接受日期:2024-11-25 出版日期:2024-11-25 发布日期:2024-11-27

Design and implementation of an efficient memory allocation algorithm based on TLSF algorithm

CHEN Zhao-hui1,DUAN Xiong2   

  1. (1.Institute of Advanced Technology Research,University of Science and Technology of China,Hefei 230031;
    2.Anhui Huami Information Technology Co.,Ltd.,Hefei 230088,China)
  • Received:2023-07-08 Revised:2023-10-07 Accepted:2024-11-25 Online:2024-11-25 Published:2024-11-27

摘要: 在嵌入式系统中,由于内存资源的有限性,内存分配器的性能和碎片率成为其重要考量因素。目前主要采用的内存分配算法是TLSF,然而该算法在嵌入式系统中存在一些问题,例如小内存申请导致外部碎片和大内存申请导致内部碎片。为了解决这些问题,对TLSF算法进行了优化:(1)针对小内存申请,引入了静态内存池(POOL)算法,以解决TLSF算法中大量小内存分配带来的外部碎片问题;(2)针对大内存申请,提出了按级划分的DBL内存分配策略,解决了大内存分配中的内部碎片问题。实验结果表明,通过使用优化后的TLSF算法(DBL+POOL)进行内存管理,可以更好地利用内存资源,提高嵌入式系统的性能和可靠性。

关键词: 内存分配器, TLSF算法, 静态内存池算法, 内存碎片, 嵌入式操作系统

Abstract: In embedded systems, due to the limited availability of memory resources, the perform- ance and fragmentation rate of memory allocators become crucial factors to consider. Currently, the primary algorithm employed is TLSF (two-level segregated fit), but this algorithm poses certain issues in embedded systems, such as external fragmentation caused by small memory allocations and internal fragmentation resulting from large memory allocations. To address these issues, optimizations have been made to the TLSF algorithm: (1) For small memory allocations, a static memory pool (POOL) algorithm is introduced to resolve the external fragmentation problem that arises from numerous small memory allocations in the TLSF algorithm; (2) For large memory allocations, a DBL (divided by level) memory allocation strategy based on hierarchical division is proposed to tackle the internal fragmentation issue in large memory allocations. Experiments have shown that by utilizing the optimized TLSF algorithm (DBL+POOL) for memory management, it is possible to better utilize memory resources, thereby enhancing the performance and reliability of embedded systems.

Key words: memory allocator, TLSF algorithm, static memory pool algorithm, memory fragmentation, embedded operating system