LWMalloc is a lightweight dynamic memory allocator for embedded systems

LWMalloc is an ultra-lightweight dynamic memory allocator designed for embedded systems that is said to outperform ptmalloc used in Glibc, achieving up to 53% faster execution time and 23% lower memory usage.

Malloc can cause memory fragmentation on embedded systems, potentially leading to crashes after the firmware runs long enough. Garbage collection is one technique for lowering fragmentation, but it’s not always practical on resource-constrained devices, and some simply avoid using malloc in their firmware, preferring static memory allocation or memory pools to improve reliability. Custom dynamic memory allocators are another option, and that’s what LWMalloc provides.

LWMalloc dynamic memory allocator for embedded systems

LWMalloc is described in a paper entitled “LWMalloc: A Lightweight Dynamic Memory Allocator for Resource-Constrained Environments” as follows:

LWMalloc incorporates a lightweight data structure, a deferred coalescing (DC) policy, and dedicated small chunk pools to optimize memory allocation. The lightweight data structure minimizes metadata overhead, ensuring a compact and efficient implementation. The DC policy reduces execution overhead by postponing redundant operations until allocation, maintaining both efficiency and low-response times. Dedicated small chunk pools enable O(1) allocation for small memory requests, which are common in dynamic allocation patterns, by segregating them into fixed-size pools.

The researchers at Seoul National University of Science and Technology (SEOULTECH) who developed LWMalloc dynamic memory allocator tested it again ptmalloc and reported the following results and highlights:

  • 53% faster execution time
  • 23% lower memory usage
  • LWMalloc is comprised of 530 lines of code and a 20KB footprint, which compares to the 4838 lines of code and 116 KB footprint for ptmalloc

The associated press release also mentions jemalloc, tcmalloc, and mimalloc as alternatives to ptmalloc for improved memory management, but they “suffer from heavy memory consumption, vast library sizes, complexity, and eventual performance degradation” according to the Korean researchers. Access to the full research paper requires a paid IEEE subscription, but I noticed the C code and test program can also be found on GitHub. It’s using standard malloc, calloc, realloc, and free calls, so if you were to integrate it into your project, there would be no need to change the application code, and the library can be injected at runtime to replace malloc/calloc/realloc/free via LD_PRELOAD.

While LWMalloc can benefit any embedded or IoT system with strict memory and performance constraints, SEOULTECH highlights consumer electronics (smart TVs, set-top boxes, home appliances), mobile and wearable devices, automotive systems with real-time constraints, and edge AI computing applications.

Thanks to TLS for the tip.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress. We also use affiliate links in articles to earn commissions if you make a purchase after clicking on those links.

Radxa Orion O6 Armv9 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
2 Comments
oldest
newest
Boardcon MINI1126B-P AI vision system-on-module wit Rockchip RV1126B-P SoC