summaryrefslogtreecommitdiff
path: root/libc/src/stdlib/freelist_malloc.cpp
AgeCommit message (Collapse)Author
2024-12-16[libc] Breakup freelist_malloc into separate files (#119806)Petr Hosek
This better matches the structure we use for the rest of libc.
2024-12-12Revert "[libc] Breakup freelist_malloc into separate files" (#119749)Petr Hosek
Reverts llvm/llvm-project#98784 which broke libc builders.
2024-12-12[libc] Breakup freelist_malloc into separate files (#98784)Petr Hosek
This better matches the structure we use for the rest of libc.
2024-11-21Reapply "[libc] Use best-fit binary trie to make malloc logarithmic (#117065)"Daniel Thornburgh
This reverts commit 93b83642ee34d0092b94776728dad0117c2b72a1. - Correct riscv32 assumption about alignment (bit of a hack). - Fix test case where the largest_small and smallest sizes are the same.
2024-11-21Revert "[libc] Use best-fit binary trie to make malloc logarithmic (#117065)"Daniel Thornburgh
This reverts commit b05600d96f46697e21f6b1b7ad901391326243a8. riscv32 unit test still broken
2024-11-21Reapply "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)Daniel Thornburgh
- Fix assertion expressions. - Fix incorrect small size in freestore_test. - There may only be one small size for high alignment and small pointers (riscv32). - Don't rely on stack alignment in FreeList test.
2024-11-20Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)Daniel Thornburgh
Reverts llvm/llvm-project#106259 Unit tests break on AArch64.
2024-11-20[libc] Use best-fit binary trie to make malloc logarithmic (#106259)Daniel Thornburgh
This reworks the free store implementation in libc's malloc to use a dlmalloc-style binary trie of circularly linked FIFO free lists. This data structure can be maintained in logarithmic time, but it still permits a relatively small implementation compared to other logarithmic-time ordered maps. The implementation doesn't do the various bitwise tricks or optimizations used in actual dlmalloc; it instead optimizes for (relative) readability and minimum code size. Specific optimization can be added as necessary given future profiling.
2024-07-25[libc] Lazily initialize freelist malloc using symbols (#99254)Daniel Thornburgh
This requires the user to set the upper bounds of the heap by defining the symbol `__libc_heap_limit`. The heap begins at `_end` and ends `__libc_heap_limit` bytes afterwards. This prevents a completely unused heap from requiring any space, and it prevents the heap from being zeroed at initialization time as part of BSS. It also allows users to customize the available heap location without recompiling libc. I'd think this should eventually be replaced with an implemenation based on a morecore() library. This would allow the same implementation to use sbrk() on POSIX, `_end` and `__libc_heap_limit` on embedded, and a buffer in tests. It would also provide better "wilderness" behavior that tends to decrease heap fragementation (see Wilson et al.) See #98096
2024-07-12[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)Petr Hosek
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini
declaration" (#98593) Reverts llvm/llvm-project#98075 bots are broken
2024-07-11[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)Petr Hosek
This is a part of #97655.
2024-07-03[libc] Add aligned_alloc (#96586)PiJoules
This adds support for aligned_alloc with the freelist allocator. This works by finding blocks large enough to hold the requested size plus some shift amount that's at most the requested alignment. Blocks that meet this requirement but aren't properly aligned can be split such that the usable_space of a new block is aligned properly. The "padding" block created will be merged with the previous block if one exists.
2024-06-20[libc] Control freelist malloc buffer size with a config (#96248)PiJoules
Rather than propgating a compile define, add an explicit cmake flag for controlling the size. The default for baremetal is 100KB and the default for others is 1GB.
2024-06-20[libc] Move freelist + block to __support (#96231)PiJoules
2024-06-14[libc][stdlib] Make the FreeListHeap constant-initializable (#95453)PiJoules
This refactors some of the FreeListHeap, FreeList, and Block classes to have constexpr ctors so we can constinit a global allocator that does not require running some global function or global ctor to initialize. This is needed to prevent worrying about initialization order and any other module-ctor can invoke malloc without worry.