[libc-commits] [libc] [libc] Control freelist malloc buffer size with a config (PR #96248)
via libc-commits
libc-commits at lists.llvm.org
Thu Jun 20 16:02:39 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: None (PiJoules)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/96248.diff
5 Files Affected:
- (modified) libc/config/baremetal/config.json (+5)
- (modified) libc/config/config.json (+6)
- (modified) libc/docs/configure.rst (+2)
- (modified) libc/src/stdlib/CMakeLists.txt (+2)
- (modified) libc/src/stdlib/freelist_malloc.cpp (+1-8)
``````````diff
diff --git a/libc/config/baremetal/config.json b/libc/config/baremetal/config.json
index 53f232e31cc8a..dda4c42425755 100644
--- a/libc/config/baremetal/config.json
+++ b/libc/config/baremetal/config.json
@@ -12,5 +12,10 @@
"LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE": {
"value": false
}
+ },
+ "malloc": {
+ "LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE": {
+ "value": 102400
+ }
}
}
diff --git a/libc/config/config.json b/libc/config/config.json
index 8d6a84e732597..11433c15d762e 100644
--- a/libc/config/config.json
+++ b/libc/config/config.json
@@ -54,5 +54,11 @@
"value": 100,
"doc": "Default number of spins before blocking if a rwlock is in contention (default to 100)."
}
+ },
+ "malloc": {
+ "LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE": {
+ "value": 1073741824,
+ "doc": "Default size for the constinit freelist buffer used for the freelist malloc implementation (default 1o 1GB)."
+ }
}
}
diff --git a/libc/docs/configure.rst b/libc/docs/configure.rst
index bdae6c54052f2..016e2e5aa5876 100644
--- a/libc/docs/configure.rst
+++ b/libc/docs/configure.rst
@@ -28,6 +28,8 @@ to learn about the defaults for your platform and target.
* **"codegen" options**
- ``LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR``: Enable -fstack-protector-strong to defend against stack smashing attack.
- ``LIBC_CONF_KEEP_FRAME_POINTER``: Keep frame pointer in functions for better debugging experience.
+* **"malloc" options**
+ - ``LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE``: Default size for the constinit freelist buffer used for the freelist malloc implementation (default 1o 1GB).
* **"printf" options**
- ``LIBC_CONF_PRINTF_DISABLE_FIXED_POINT``: Disable printing fixed point values in printf and friends.
- ``LIBC_CONF_PRINTF_DISABLE_FLOAT``: Disable printing floating point values in printf and friends.
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index 3b1ca3ab2fe42..51d53e0d02ea2 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -390,6 +390,8 @@ else()
malloc.h
DEPENDS
libc.src.__support.freelist_heap
+ COMPILE_OPTIONS
+ -DLIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}
)
else()
add_entrypoint_external(
diff --git a/libc/src/stdlib/freelist_malloc.cpp b/libc/src/stdlib/freelist_malloc.cpp
index 0be7f3467e32c..fb2a83835832e 100644
--- a/libc/src/stdlib/freelist_malloc.cpp
+++ b/libc/src/stdlib/freelist_malloc.cpp
@@ -17,15 +17,8 @@
namespace LIBC_NAMESPACE {
namespace {
-// Users can define LIBC_FREELIST_MALLOC_SIZE for setting the default buffer
-// size used by freelist malloc.
-#ifdef LIBC_FREELIST_MALLOC_SIZE
+// This is set via the LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE configuration.
constexpr size_t SIZE = LIBC_FREELIST_MALLOC_SIZE;
-#else
-// TODO: We should probably have something akin to what scudo/sanitizer
-// allocators do where each platform defines this.
-constexpr size_t SIZE = 0x40000000ULL; // 1GB
-#endif
LIBC_CONSTINIT FreeListHeapBuffer<SIZE> freelist_heap_buffer;
} // namespace
``````````
</details>
https://github.com/llvm/llvm-project/pull/96248
More information about the libc-commits
mailing list