malloc.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/BuiltinWrappers.h>
  7. #include <AK/Debug.h>
  8. #include <AK/ScopedValueRollback.h>
  9. #include <AK/Vector.h>
  10. #include <LibELF/AuxiliaryVector.h>
  11. #include <assert.h>
  12. #include <errno.h>
  13. #include <mallocdefs.h>
  14. #include <pthread.h>
  15. #include <serenity.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <sys/internals.h>
  20. #include <sys/mman.h>
  21. #include <syscall.h>
  22. class PthreadMutexLocker {
  23. public:
  24. ALWAYS_INLINE explicit PthreadMutexLocker(pthread_mutex_t& mutex)
  25. : m_mutex(mutex)
  26. {
  27. lock();
  28. __heap_is_stable = false;
  29. }
  30. ALWAYS_INLINE ~PthreadMutexLocker()
  31. {
  32. __heap_is_stable = true;
  33. unlock();
  34. }
  35. ALWAYS_INLINE void lock() { pthread_mutex_lock(&m_mutex); }
  36. ALWAYS_INLINE void unlock() { pthread_mutex_unlock(&m_mutex); }
  37. private:
  38. pthread_mutex_t& m_mutex;
  39. };
  40. #define RECYCLE_BIG_ALLOCATIONS
  41. static pthread_mutex_t s_malloc_mutex = PTHREAD_MUTEX_INITIALIZER;
  42. bool __heap_is_stable = true;
  43. constexpr size_t number_of_hot_chunked_blocks_to_keep_around = 16;
  44. constexpr size_t number_of_cold_chunked_blocks_to_keep_around = 16;
  45. constexpr size_t number_of_big_blocks_to_keep_around_per_size_class = 8;
  46. static bool s_log_malloc = false;
  47. static bool s_scrub_malloc = true;
  48. static bool s_scrub_free = true;
  49. static bool s_profiling = false;
  50. static bool s_in_userspace_emulator = false;
  51. ALWAYS_INLINE static void ue_notify_malloc(const void* ptr, size_t size)
  52. {
  53. if (s_in_userspace_emulator)
  54. syscall(SC_emuctl, 1, size, (FlatPtr)ptr);
  55. }
  56. ALWAYS_INLINE static void ue_notify_free(const void* ptr)
  57. {
  58. if (s_in_userspace_emulator)
  59. syscall(SC_emuctl, 2, (FlatPtr)ptr, 0);
  60. }
  61. ALWAYS_INLINE static void ue_notify_realloc(const void* ptr, size_t size)
  62. {
  63. if (s_in_userspace_emulator)
  64. syscall(SC_emuctl, 3, size, (FlatPtr)ptr);
  65. }
  66. ALWAYS_INLINE static void ue_notify_chunk_size_changed(const void* block, size_t chunk_size)
  67. {
  68. if (s_in_userspace_emulator)
  69. syscall(SC_emuctl, 4, chunk_size, (FlatPtr)block);
  70. }
  71. struct MemoryAuditingSuppressor {
  72. ALWAYS_INLINE MemoryAuditingSuppressor()
  73. {
  74. if (s_in_userspace_emulator)
  75. syscall(SC_emuctl, 7);
  76. }
  77. ALWAYS_INLINE ~MemoryAuditingSuppressor()
  78. {
  79. if (s_in_userspace_emulator)
  80. syscall(SC_emuctl, 8);
  81. }
  82. };
  83. struct MallocStats {
  84. size_t number_of_malloc_calls;
  85. size_t number_of_big_allocator_hits;
  86. size_t number_of_big_allocator_purge_hits;
  87. size_t number_of_big_allocs;
  88. size_t number_of_hot_empty_block_hits;
  89. size_t number_of_cold_empty_block_hits;
  90. size_t number_of_cold_empty_block_purge_hits;
  91. size_t number_of_block_allocs;
  92. size_t number_of_blocks_full;
  93. size_t number_of_free_calls;
  94. size_t number_of_big_allocator_keeps;
  95. size_t number_of_big_allocator_frees;
  96. size_t number_of_freed_full_blocks;
  97. size_t number_of_hot_keeps;
  98. size_t number_of_cold_keeps;
  99. size_t number_of_frees;
  100. };
  101. static MallocStats g_malloc_stats = {};
  102. static size_t s_hot_empty_block_count { 0 };
  103. static ChunkedBlock* s_hot_empty_blocks[number_of_hot_chunked_blocks_to_keep_around] { nullptr };
  104. static size_t s_cold_empty_block_count { 0 };
  105. static ChunkedBlock* s_cold_empty_blocks[number_of_cold_chunked_blocks_to_keep_around] { nullptr };
  106. struct Allocator {
  107. size_t size { 0 };
  108. size_t block_count { 0 };
  109. ChunkedBlock::List usable_blocks;
  110. ChunkedBlock::List full_blocks;
  111. };
  112. struct BigAllocator {
  113. Vector<BigAllocationBlock*, number_of_big_blocks_to_keep_around_per_size_class> blocks;
  114. };
  115. // Allocators will be initialized in __malloc_init.
  116. // We can not rely on global constructors to initialize them,
  117. // because they must be initialized before other global constructors
  118. // are run. Similarly, we can not allow global destructors to destruct
  119. // them. We could have used AK::NeverDestoyed to prevent the latter,
  120. // but it would have not helped with the former.
  121. alignas(Allocator) static u8 g_allocators_storage[sizeof(Allocator) * num_size_classes];
  122. alignas(BigAllocator) static u8 g_big_allocators_storage[sizeof(BigAllocator)];
  123. static inline Allocator (&allocators())[num_size_classes]
  124. {
  125. return reinterpret_cast<Allocator(&)[num_size_classes]>(g_allocators_storage);
  126. }
  127. static inline BigAllocator (&big_allocators())[1]
  128. {
  129. return reinterpret_cast<BigAllocator(&)[1]>(g_big_allocators_storage);
  130. }
  131. static Allocator* allocator_for_size(size_t size, size_t& good_size)
  132. {
  133. for (size_t i = 0; size_classes[i]; ++i) {
  134. if (size <= size_classes[i]) {
  135. good_size = size_classes[i];
  136. return &allocators()[i];
  137. }
  138. }
  139. good_size = PAGE_ROUND_UP(size);
  140. return nullptr;
  141. }
  142. #ifdef RECYCLE_BIG_ALLOCATIONS
  143. static BigAllocator* big_allocator_for_size(size_t size)
  144. {
  145. if (size == 65536)
  146. return &big_allocators()[0];
  147. return nullptr;
  148. }
  149. #endif
  150. extern "C" {
  151. static void* os_alloc(size_t size, const char* name)
  152. {
  153. int flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_PURGEABLE;
  154. #if ARCH(X86_64)
  155. flags |= MAP_RANDOMIZED;
  156. #endif
  157. auto* ptr = serenity_mmap(nullptr, size, PROT_READ | PROT_WRITE, flags, 0, 0, ChunkedBlock::block_size, name);
  158. VERIFY(ptr != MAP_FAILED);
  159. return ptr;
  160. }
  161. static void os_free(void* ptr, size_t size)
  162. {
  163. int rc = munmap(ptr, size);
  164. assert(rc == 0);
  165. }
  166. enum class CallerWillInitializeMemory {
  167. No,
  168. Yes,
  169. };
  170. static void* malloc_impl(size_t size, CallerWillInitializeMemory caller_will_initialize_memory)
  171. {
  172. if (s_log_malloc)
  173. dbgln("LibC: malloc({})", size);
  174. if (!size) {
  175. // Legally we could just return a null pointer here, but this is more
  176. // compatible with existing software.
  177. size = 1;
  178. }
  179. g_malloc_stats.number_of_malloc_calls++;
  180. size_t good_size;
  181. auto* allocator = allocator_for_size(size, good_size);
  182. PthreadMutexLocker locker(s_malloc_mutex);
  183. if (!allocator) {
  184. size_t real_size = round_up_to_power_of_two(sizeof(BigAllocationBlock) + size, ChunkedBlock::block_size);
  185. #ifdef RECYCLE_BIG_ALLOCATIONS
  186. if (auto* allocator = big_allocator_for_size(real_size)) {
  187. if (!allocator->blocks.is_empty()) {
  188. g_malloc_stats.number_of_big_allocator_hits++;
  189. auto* block = allocator->blocks.take_last();
  190. int rc = madvise(block, real_size, MADV_SET_NONVOLATILE);
  191. bool this_block_was_purged = rc == 1;
  192. if (rc < 0) {
  193. perror("madvise");
  194. VERIFY_NOT_REACHED();
  195. }
  196. if (mprotect(block, real_size, PROT_READ | PROT_WRITE) < 0) {
  197. perror("mprotect");
  198. VERIFY_NOT_REACHED();
  199. }
  200. if (this_block_was_purged) {
  201. g_malloc_stats.number_of_big_allocator_purge_hits++;
  202. new (block) BigAllocationBlock(real_size);
  203. }
  204. ue_notify_malloc(&block->m_slot[0], size);
  205. return &block->m_slot[0];
  206. }
  207. }
  208. #endif
  209. g_malloc_stats.number_of_big_allocs++;
  210. auto* block = (BigAllocationBlock*)os_alloc(real_size, "malloc: BigAllocationBlock");
  211. new (block) BigAllocationBlock(real_size);
  212. ue_notify_malloc(&block->m_slot[0], size);
  213. return &block->m_slot[0];
  214. }
  215. ChunkedBlock* block = nullptr;
  216. for (auto& current : allocator->usable_blocks) {
  217. if (current.free_chunks()) {
  218. block = &current;
  219. break;
  220. }
  221. }
  222. if (!block && s_hot_empty_block_count) {
  223. g_malloc_stats.number_of_hot_empty_block_hits++;
  224. block = s_hot_empty_blocks[--s_hot_empty_block_count];
  225. if (block->m_size != good_size) {
  226. new (block) ChunkedBlock(good_size);
  227. ue_notify_chunk_size_changed(block, good_size);
  228. char buffer[64];
  229. snprintf(buffer, sizeof(buffer), "malloc: ChunkedBlock(%zu)", good_size);
  230. set_mmap_name(block, ChunkedBlock::block_size, buffer);
  231. }
  232. allocator->usable_blocks.append(*block);
  233. }
  234. if (!block && s_cold_empty_block_count) {
  235. g_malloc_stats.number_of_cold_empty_block_hits++;
  236. block = s_cold_empty_blocks[--s_cold_empty_block_count];
  237. int rc = madvise(block, ChunkedBlock::block_size, MADV_SET_NONVOLATILE);
  238. bool this_block_was_purged = rc == 1;
  239. if (rc < 0) {
  240. perror("madvise");
  241. VERIFY_NOT_REACHED();
  242. }
  243. rc = mprotect(block, ChunkedBlock::block_size, PROT_READ | PROT_WRITE);
  244. if (rc < 0) {
  245. perror("mprotect");
  246. VERIFY_NOT_REACHED();
  247. }
  248. if (this_block_was_purged || block->m_size != good_size) {
  249. if (this_block_was_purged)
  250. g_malloc_stats.number_of_cold_empty_block_purge_hits++;
  251. new (block) ChunkedBlock(good_size);
  252. ue_notify_chunk_size_changed(block, good_size);
  253. }
  254. allocator->usable_blocks.append(*block);
  255. }
  256. if (!block) {
  257. g_malloc_stats.number_of_block_allocs++;
  258. char buffer[64];
  259. snprintf(buffer, sizeof(buffer), "malloc: ChunkedBlock(%zu)", good_size);
  260. block = (ChunkedBlock*)os_alloc(ChunkedBlock::block_size, buffer);
  261. new (block) ChunkedBlock(good_size);
  262. allocator->usable_blocks.append(*block);
  263. ++allocator->block_count;
  264. }
  265. --block->m_free_chunks;
  266. void* ptr = block->m_freelist;
  267. if (ptr) {
  268. block->m_freelist = block->m_freelist->next;
  269. } else {
  270. ptr = block->m_slot + block->m_next_lazy_freelist_index * block->m_size;
  271. block->m_next_lazy_freelist_index++;
  272. }
  273. VERIFY(ptr);
  274. if (block->is_full()) {
  275. g_malloc_stats.number_of_blocks_full++;
  276. dbgln_if(MALLOC_DEBUG, "Block {:p} is now full in size class {}", block, good_size);
  277. allocator->usable_blocks.remove(*block);
  278. allocator->full_blocks.append(*block);
  279. }
  280. dbgln_if(MALLOC_DEBUG, "LibC: allocated {:p} (chunk in block {:p}, size {})", ptr, block, block->bytes_per_chunk());
  281. if (s_scrub_malloc && caller_will_initialize_memory == CallerWillInitializeMemory::No)
  282. memset(ptr, MALLOC_SCRUB_BYTE, block->m_size);
  283. ue_notify_malloc(ptr, size);
  284. return ptr;
  285. }
  286. static void free_impl(void* ptr)
  287. {
  288. ScopedValueRollback rollback(errno);
  289. if (!ptr)
  290. return;
  291. g_malloc_stats.number_of_free_calls++;
  292. void* block_base = (void*)((FlatPtr)ptr & ChunkedBlock::ChunkedBlock::block_mask);
  293. size_t magic = *(size_t*)block_base;
  294. PthreadMutexLocker locker(s_malloc_mutex);
  295. if (magic == MAGIC_BIGALLOC_HEADER) {
  296. auto* block = (BigAllocationBlock*)block_base;
  297. #ifdef RECYCLE_BIG_ALLOCATIONS
  298. if (auto* allocator = big_allocator_for_size(block->m_size)) {
  299. if (allocator->blocks.size() < number_of_big_blocks_to_keep_around_per_size_class) {
  300. g_malloc_stats.number_of_big_allocator_keeps++;
  301. allocator->blocks.append(block);
  302. size_t this_block_size = block->m_size;
  303. if (mprotect(block, this_block_size, PROT_NONE) < 0) {
  304. perror("mprotect");
  305. VERIFY_NOT_REACHED();
  306. }
  307. if (madvise(block, this_block_size, MADV_SET_VOLATILE) != 0) {
  308. perror("madvise");
  309. VERIFY_NOT_REACHED();
  310. }
  311. return;
  312. }
  313. }
  314. #endif
  315. g_malloc_stats.number_of_big_allocator_frees++;
  316. os_free(block, block->m_size);
  317. return;
  318. }
  319. assert(magic == MAGIC_PAGE_HEADER);
  320. auto* block = (ChunkedBlock*)block_base;
  321. dbgln_if(MALLOC_DEBUG, "LibC: freeing {:p} in allocator {:p} (size={}, used={})", ptr, block, block->bytes_per_chunk(), block->used_chunks());
  322. if (s_scrub_free)
  323. memset(ptr, FREE_SCRUB_BYTE, block->bytes_per_chunk());
  324. auto* entry = (FreelistEntry*)ptr;
  325. entry->next = block->m_freelist;
  326. block->m_freelist = entry;
  327. if (block->is_full()) {
  328. size_t good_size;
  329. auto* allocator = allocator_for_size(block->m_size, good_size);
  330. dbgln_if(MALLOC_DEBUG, "Block {:p} no longer full in size class {}", block, good_size);
  331. g_malloc_stats.number_of_freed_full_blocks++;
  332. allocator->full_blocks.remove(*block);
  333. allocator->usable_blocks.prepend(*block);
  334. }
  335. ++block->m_free_chunks;
  336. if (!block->used_chunks()) {
  337. size_t good_size;
  338. auto* allocator = allocator_for_size(block->m_size, good_size);
  339. if (s_hot_empty_block_count < number_of_hot_chunked_blocks_to_keep_around) {
  340. dbgln_if(MALLOC_DEBUG, "Keeping hot block {:p} around", block);
  341. g_malloc_stats.number_of_hot_keeps++;
  342. allocator->usable_blocks.remove(*block);
  343. s_hot_empty_blocks[s_hot_empty_block_count++] = block;
  344. return;
  345. }
  346. if (s_cold_empty_block_count < number_of_cold_chunked_blocks_to_keep_around) {
  347. dbgln_if(MALLOC_DEBUG, "Keeping cold block {:p} around", block);
  348. g_malloc_stats.number_of_cold_keeps++;
  349. allocator->usable_blocks.remove(*block);
  350. s_cold_empty_blocks[s_cold_empty_block_count++] = block;
  351. mprotect(block, ChunkedBlock::block_size, PROT_NONE);
  352. madvise(block, ChunkedBlock::block_size, MADV_SET_VOLATILE);
  353. return;
  354. }
  355. dbgln_if(MALLOC_DEBUG, "Releasing block {:p} for size class {}", block, good_size);
  356. g_malloc_stats.number_of_frees++;
  357. allocator->usable_blocks.remove(*block);
  358. --allocator->block_count;
  359. os_free(block, ChunkedBlock::block_size);
  360. }
  361. }
  362. void* malloc(size_t size)
  363. {
  364. MemoryAuditingSuppressor suppressor;
  365. void* ptr = malloc_impl(size, CallerWillInitializeMemory::No);
  366. if (s_profiling)
  367. perf_event(PERF_EVENT_MALLOC, size, reinterpret_cast<FlatPtr>(ptr));
  368. return ptr;
  369. }
  370. // This is a Microsoft extension, and is not found on other Unix-like systems.
  371. // FIXME: Implement aligned_alloc() instead
  372. //
  373. // This is used in libc++ to implement C++17 aligned new/delete.
  374. //
  375. // Both Unix-y alternatives to _aligned_malloc(), the C11 aligned_alloc() and
  376. // posix_memalign() say that the resulting pointer can be deallocated with
  377. // regular free(), which means that the allocator has to keep track of the
  378. // requested alignments. By contrast, _aligned_malloc() is paired with
  379. // _aligned_free(), so it can be easily implemented on top of malloc().
  380. void* _aligned_malloc(size_t size, size_t alignment)
  381. {
  382. if (popcount(alignment) != 1) {
  383. errno = EINVAL;
  384. return nullptr;
  385. }
  386. alignment = max(alignment, sizeof(void*));
  387. if (Checked<size_t>::addition_would_overflow(size, alignment)) {
  388. errno = ENOMEM;
  389. return nullptr;
  390. }
  391. void* ptr = malloc(size + alignment);
  392. if (!ptr) {
  393. errno = ENOMEM;
  394. return nullptr;
  395. }
  396. auto aligned_ptr = (void*)(((FlatPtr)ptr + alignment) & ~(alignment - 1));
  397. ((void**)aligned_ptr)[-1] = ptr;
  398. return aligned_ptr;
  399. }
  400. void free(void* ptr)
  401. {
  402. MemoryAuditingSuppressor suppressor;
  403. if (s_profiling)
  404. perf_event(PERF_EVENT_FREE, reinterpret_cast<FlatPtr>(ptr), 0);
  405. ue_notify_free(ptr);
  406. free_impl(ptr);
  407. }
  408. void _aligned_free(void* ptr)
  409. {
  410. if (ptr)
  411. free(((void**)ptr)[-1]);
  412. }
  413. void* calloc(size_t count, size_t size)
  414. {
  415. MemoryAuditingSuppressor suppressor;
  416. if (Checked<size_t>::multiplication_would_overflow(count, size)) {
  417. errno = ENOMEM;
  418. return nullptr;
  419. }
  420. size_t new_size = count * size;
  421. auto* ptr = malloc_impl(new_size, CallerWillInitializeMemory::Yes);
  422. if (ptr)
  423. memset(ptr, 0, new_size);
  424. return ptr;
  425. }
  426. size_t malloc_size(void* ptr)
  427. {
  428. MemoryAuditingSuppressor suppressor;
  429. if (!ptr)
  430. return 0;
  431. void* page_base = (void*)((FlatPtr)ptr & ChunkedBlock::block_mask);
  432. auto* header = (const CommonHeader*)page_base;
  433. auto size = header->m_size;
  434. if (header->m_magic == MAGIC_BIGALLOC_HEADER)
  435. size -= sizeof(CommonHeader);
  436. else
  437. VERIFY(header->m_magic == MAGIC_PAGE_HEADER);
  438. return size;
  439. }
  440. size_t malloc_good_size(size_t size)
  441. {
  442. size_t good_size;
  443. allocator_for_size(size, good_size);
  444. return good_size;
  445. }
  446. void* realloc(void* ptr, size_t size)
  447. {
  448. MemoryAuditingSuppressor suppressor;
  449. if (!ptr)
  450. return malloc(size);
  451. if (!size) {
  452. free(ptr);
  453. return nullptr;
  454. }
  455. auto existing_allocation_size = malloc_size(ptr);
  456. if (size <= existing_allocation_size) {
  457. ue_notify_realloc(ptr, size);
  458. return ptr;
  459. }
  460. auto* new_ptr = malloc(size);
  461. if (new_ptr) {
  462. memcpy(new_ptr, ptr, min(existing_allocation_size, size));
  463. free(ptr);
  464. }
  465. return new_ptr;
  466. }
  467. void __malloc_init()
  468. {
  469. s_in_userspace_emulator = (int)syscall(SC_emuctl, 0) != -ENOSYS;
  470. if (s_in_userspace_emulator) {
  471. // Don't bother scrubbing memory if we're running in UE since it
  472. // keeps track of heap memory anyway.
  473. s_scrub_malloc = false;
  474. s_scrub_free = false;
  475. }
  476. if (secure_getenv("LIBC_NOSCRUB_MALLOC"))
  477. s_scrub_malloc = false;
  478. if (secure_getenv("LIBC_NOSCRUB_FREE"))
  479. s_scrub_free = false;
  480. if (secure_getenv("LIBC_LOG_MALLOC"))
  481. s_log_malloc = true;
  482. if (secure_getenv("LIBC_PROFILE_MALLOC"))
  483. s_profiling = true;
  484. for (size_t i = 0; i < num_size_classes; ++i) {
  485. new (&allocators()[i]) Allocator();
  486. allocators()[i].size = size_classes[i];
  487. }
  488. new (&big_allocators()[0])(BigAllocator);
  489. }
  490. void serenity_dump_malloc_stats()
  491. {
  492. dbgln("# malloc() calls: {}", g_malloc_stats.number_of_malloc_calls);
  493. dbgln();
  494. dbgln("big alloc hits: {}", g_malloc_stats.number_of_big_allocator_hits);
  495. dbgln("big alloc hits that were purged: {}", g_malloc_stats.number_of_big_allocator_purge_hits);
  496. dbgln("big allocs: {}", g_malloc_stats.number_of_big_allocs);
  497. dbgln();
  498. dbgln("empty hot block hits: {}", g_malloc_stats.number_of_hot_empty_block_hits);
  499. dbgln("empty cold block hits: {}", g_malloc_stats.number_of_cold_empty_block_hits);
  500. dbgln("empty cold block hits that were purged: {}", g_malloc_stats.number_of_cold_empty_block_purge_hits);
  501. dbgln("block allocs: {}", g_malloc_stats.number_of_block_allocs);
  502. dbgln("filled blocks: {}", g_malloc_stats.number_of_blocks_full);
  503. dbgln();
  504. dbgln("# free() calls: {}", g_malloc_stats.number_of_free_calls);
  505. dbgln();
  506. dbgln("big alloc keeps: {}", g_malloc_stats.number_of_big_allocator_keeps);
  507. dbgln("big alloc frees: {}", g_malloc_stats.number_of_big_allocator_frees);
  508. dbgln();
  509. dbgln("full block frees: {}", g_malloc_stats.number_of_freed_full_blocks);
  510. dbgln("number of hot keeps: {}", g_malloc_stats.number_of_hot_keeps);
  511. dbgln("number of cold keeps: {}", g_malloc_stats.number_of_cold_keeps);
  512. dbgln("number of frees: {}", g_malloc_stats.number_of_frees);
  513. }
  514. }