rpmalloc
rpmalloc copied to clipboard
develop branch crash while modify SPAN_SIZE
- Firstly, I made the following modifications(diff-with-develop-commit-feb43ae.patch):
diff --git a/rpmalloc/rpmalloc.c b/rpmalloc/rpmalloc.c
index 261bb83..4eb33db 100644
--- a/rpmalloc/rpmalloc.c
+++ b/rpmalloc/rpmalloc.c
@@ -151,7 +151,7 @@ madvise(caddr_t, size_t, int);
#endif
#ifndef ENABLE_STATISTICS
//! Enable statistics
-#define ENABLE_STATISTICS 0
+#define ENABLE_STATISTICS 1
#endif
////////////
@@ -2270,20 +2270,26 @@ rpmalloc_thread_collect(void) {
void
rpmalloc_dump_statistics(void* file) {
#if ENABLE_STATISTICS
- fprintf(file, "Mapped pages: %llu\n",
- (unsigned long long)atomic_load_explicit(&global_statistics.page_mapped, memory_order_relaxed));
- fprintf(file, "Mapped pages (peak): %llu\n",
- (unsigned long long)atomic_load_explicit(&global_statistics.page_mapped_peak, memory_order_relaxed));
- fprintf(file, "Active pages: %llu\n",
- (unsigned long long)atomic_load_explicit(&global_statistics.page_active, memory_order_relaxed));
- fprintf(file, "Active pages (peak): %llu\n",
- (unsigned long long)atomic_load_explicit(&global_statistics.page_active_peak, memory_order_relaxed));
- fprintf(file, "Pages committed: %llu\n",
- (unsigned long long)atomic_load_explicit(&global_statistics.page_commit, memory_order_relaxed));
- fprintf(file, "Pages decommitted: %llu\n",
- (unsigned long long)atomic_load_explicit(&global_statistics.page_decommit, memory_order_relaxed));
- fprintf(file, "Heaps created: %llu\n",
- (unsigned long long)atomic_load_explicit(&global_statistics.heap_count, memory_order_relaxed));
+ size_t page_mapped_peak = atomic_load_explicit(&global_statistics.page_mapped_peak, memory_order_relaxed);
+ size_t page_active_peak = atomic_load_explicit(&global_statistics.page_active_peak, memory_order_relaxed);
+ size_t page_mapped = atomic_load_explicit(&global_statistics.page_mapped, memory_order_relaxed);
+ size_t page_active = atomic_load_explicit(&global_statistics.page_active, memory_order_relaxed);
+ size_t page_commit = atomic_load_explicit(&global_statistics.page_commit, memory_order_relaxed);
+ size_t page_decommit = atomic_load_explicit(&global_statistics.page_decommit, memory_order_relaxed);
+ size_t heap_count = atomic_load_explicit(&global_statistics.heap_count, memory_order_relaxed);
+ fprintf(file, "Curr Memory:\n");
+ fprintf(file, "%-15s %16s %16s %16s %16s\n",
+ "MappedPages", "ActivePages", "CommitPages", "DecmitPages", "CreatedHeaps");
+ fprintf(file, "%-15zu %16zu %16zu %16zu %16zu\n",
+ page_mapped, page_active, page_commit, page_decommit, heap_count);
+ fprintf(file, "Peak Memory:\n");
+ fprintf(file, "%-15s %16s %16s %16s %16s\n",
+ "MappedPages","ActivePages", "Mapped(MiB)", "Active(MiB)", "PageSize(KiB)");
+ fprintf(file, "%-15zu %16zu %16zu %16zu %16zu\n",
+ page_mapped_peak, page_active_peak,
+ (global_config.page_size * page_mapped_peak) / (1024 * 1024) + 1,
+ (global_config.page_size * page_active_peak) / (1024 * 1024) + 1,
+ global_config.page_size);
#else
(void)sizeof(file);
#endif
diff --git a/test/main.c b/test/main.c
index 49ab1d2..e9007f2 100644
--- a/test/main.c
+++ b/test/main.c
@@ -969,7 +969,7 @@ test_crossthread(void) {
rpfree(arg[ithread].pointers);
printf("Memory cross thread free tests passed\n");
-
+ rpmalloc_dump_statistics(stdout);
rpmalloc_finalize();
return 0;
@@ -1184,14 +1184,14 @@ test_run(int argc, char** argv) {
(void)sizeof(argc);
(void)sizeof(argv);
test_initialize();
+ if (test_crossthread())
+ return -1;
if (test_alloc())
return -1;
if (test_realloc())
return -1;
if (test_superalign())
return -1;
- if (test_crossthread())
- return -1;
if (test_threaded())
return -1;
if (test_malloc(1))
After the execution of test_crossthread is completed, the output is printed as follows:
MappedPages ActivePages CommitPages DecmitPages CreatedHeaps
8650769 1249558 36410704 35161146 17
Peak Memory:
MappedPages ActivePages Mapped(MiB) Active(MiB) PageSize(KiB)
8650769 1697382 33793 6631 4096
The Mapped(MiB) size is so exaggerated!!
- Based on the above reasons, it is almost impossible for me to use rpmalloc to manage custom memory pools.
Therefore, I attempted to reduce
SPAN_SIZE,but there is a high probability of croedump occurring.
Anyway, one-sentence summary:
Can I adjust it freely SPAN_SIZE, SMALL_PAGE_SIZE_SHIFT,MEDIUM_PAGE_SIZE_SHIFT, LARGE_PAGE_SIZE_SHIFT?
My goal is just to bring Mapped(MiB) closer to Active(MiB) . What should I do?
I encountered a similar problem, which became severe when there were many threads. You can also check out my issue.