malloc.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. #ifndef NO_TLS
  171. // HACK: This is a __thread - marked thread-local variable. If we initialize it globally here, VERY weird errors happen.
  172. // The initialization happens in __malloc_init() and pthread_create_helper().
  173. __thread bool s_allocation_enabled;
  174. #endif
  175. static void* malloc_impl(size_t size, CallerWillInitializeMemory caller_will_initialize_memory)
  176. {
  177. #ifndef NO_TLS
  178. VERIFY(s_allocation_enabled);
  179. #endif
  180. if (s_log_malloc)
  181. dbgln("LibC: malloc({})", size);
  182. if (!size) {
  183. // Legally we could just return a null pointer here, but this is more
  184. // compatible with existing software.
  185. size = 1;
  186. }
  187. g_malloc_stats.number_of_malloc_calls++;
  188. size_t good_size;
  189. auto* allocator = allocator_for_size(size, good_size);
  190. PthreadMutexLocker locker(s_malloc_mutex);
  191. if (!allocator) {
  192. size_t real_size = round_up_to_power_of_two(sizeof(BigAllocationBlock) + size, ChunkedBlock::block_size);
  193. #ifdef RECYCLE_BIG_ALLOCATIONS
  194. if (auto* allocator = big_allocator_for_size(real_size)) {
  195. if (!allocator->blocks.is_empty()) {
  196. g_malloc_stats.number_of_big_allocator_hits++;
  197. auto* block = allocator->blocks.take_last();
  198. int rc = madvise(block, real_size, MADV_SET_NONVOLATILE);
  199. bool this_block_was_purged = rc == 1;
  200. if (rc < 0) {
  201. perror("madvise");
  202. VERIFY_NOT_REACHED();
  203. }
  204. if (mprotect(block, real_size, PROT_READ | PROT_WRITE) < 0) {
  205. perror("mprotect");
  206. VERIFY_NOT_REACHED();
  207. }
  208. if (this_block_was_purged) {
  209. g_malloc_stats.number_of_big_allocator_purge_hits++;
  210. new (block) BigAllocationBlock(real_size);
  211. }
  212. ue_notify_malloc(&block->m_slot[0], size);
  213. return &block->m_slot[0];
  214. }
  215. }
  216. #endif
  217. g_malloc_stats.number_of_big_allocs++;
  218. auto* block = (BigAllocationBlock*)os_alloc(real_size, "malloc: BigAllocationBlock");
  219. new (block) BigAllocationBlock(real_size);
  220. ue_notify_malloc(&block->m_slot[0], size);
  221. return &block->m_slot[0];
  222. }
  223. ChunkedBlock* block = nullptr;
  224. for (auto& current : allocator->usable_blocks) {
  225. if (current.free_chunks()) {
  226. block = &current;
  227. break;
  228. }
  229. }
  230. if (!block && s_hot_empty_block_count) {
  231. g_malloc_stats.number_of_hot_empty_block_hits++;
  232. block = s_hot_empty_blocks[--s_hot_empty_block_count];
  233. if (block->m_size != good_size) {
  234. new (block) ChunkedBlock(good_size);
  235. ue_notify_chunk_size_changed(block, good_size);
  236. char buffer[64];
  237. snprintf(buffer, sizeof(buffer), "malloc: ChunkedBlock(%zu)", good_size);
  238. set_mmap_name(block, ChunkedBlock::block_size, buffer);
  239. }
  240. allocator->usable_blocks.append(*block);
  241. }
  242. if (!block && s_cold_empty_block_count) {
  243. g_malloc_stats.number_of_cold_empty_block_hits++;
  244. block = s_cold_empty_blocks[--s_cold_empty_block_count];
  245. int rc = madvise(block, ChunkedBlock::block_size, MADV_SET_NONVOLATILE);
  246. bool this_block_was_purged = rc == 1;
  247. if (rc < 0) {
  248. perror("madvise");
  249. VERIFY_NOT_REACHED();
  250. }
  251. rc = mprotect(block, ChunkedBlock::block_size, PROT_READ | PROT_WRITE);
  252. if (rc < 0) {
  253. perror("mprotect");
  254. VERIFY_NOT_REACHED();
  255. }
  256. if (this_block_was_purged || block->m_size != good_size) {
  257. if (this_block_was_purged)
  258. g_malloc_stats.number_of_cold_empty_block_purge_hits++;
  259. new (block) ChunkedBlock(good_size);
  260. ue_notify_chunk_size_changed(block, good_size);
  261. }
  262. allocator->usable_blocks.append(*block);
  263. }
  264. if (!block) {
  265. g_malloc_stats.number_of_block_allocs++;
  266. char buffer[64];
  267. snprintf(buffer, sizeof(buffer), "malloc: ChunkedBlock(%zu)", good_size);
  268. block = (ChunkedBlock*)os_alloc(ChunkedBlock::block_size, buffer);
  269. new (block) ChunkedBlock(good_size);
  270. allocator->usable_blocks.append(*block);
  271. ++allocator->block_count;
  272. }
  273. --block->m_free_chunks;
  274. void* ptr = block->m_freelist;
  275. if (ptr) {
  276. block->m_freelist = block->m_freelist->next;
  277. } else {
  278. ptr = block->m_slot + block->m_next_lazy_freelist_index * block->m_size;
  279. block->m_next_lazy_freelist_index++;
  280. }
  281. VERIFY(ptr);
  282. if (block->is_full()) {
  283. g_malloc_stats.number_of_blocks_full++;
  284. dbgln_if(MALLOC_DEBUG, "Block {:p} is now full in size class {}", block, good_size);
  285. allocator->usable_blocks.remove(*block);
  286. allocator->full_blocks.append(*block);
  287. }
  288. dbgln_if(MALLOC_DEBUG, "LibC: allocated {:p} (chunk in block {:p}, size {})", ptr, block, block->bytes_per_chunk());
  289. if (s_scrub_malloc && caller_will_initialize_memory == CallerWillInitializeMemory::No)
  290. memset(ptr, MALLOC_SCRUB_BYTE, block->m_size);
  291. ue_notify_malloc(ptr, size);
  292. return ptr;
  293. }
  294. static void free_impl(void* ptr)
  295. {
  296. #ifndef NO_TLS
  297. VERIFY(s_allocation_enabled);
  298. #endif
  299. ScopedValueRollback rollback(errno);
  300. if (!ptr)
  301. return;
  302. g_malloc_stats.number_of_free_calls++;
  303. void* block_base = (void*)((FlatPtr)ptr & ChunkedBlock::ChunkedBlock::block_mask);
  304. size_t magic = *(size_t*)block_base;
  305. PthreadMutexLocker locker(s_malloc_mutex);
  306. if (magic == MAGIC_BIGALLOC_HEADER) {
  307. auto* block = (BigAllocationBlock*)block_base;
  308. #ifdef RECYCLE_BIG_ALLOCATIONS
  309. if (auto* allocator = big_allocator_for_size(block->m_size)) {
  310. if (allocator->blocks.size() < number_of_big_blocks_to_keep_around_per_size_class) {
  311. g_malloc_stats.number_of_big_allocator_keeps++;
  312. allocator->blocks.append(block);
  313. size_t this_block_size = block->m_size;
  314. if (mprotect(block, this_block_size, PROT_NONE) < 0) {
  315. perror("mprotect");
  316. VERIFY_NOT_REACHED();
  317. }
  318. if (madvise(block, this_block_size, MADV_SET_VOLATILE) != 0) {
  319. perror("madvise");
  320. VERIFY_NOT_REACHED();
  321. }
  322. return;
  323. }
  324. }
  325. #endif
  326. g_malloc_stats.number_of_big_allocator_frees++;
  327. os_free(block, block->m_size);
  328. return;
  329. }
  330. assert(magic == MAGIC_PAGE_HEADER);
  331. auto* block = (ChunkedBlock*)block_base;
  332. dbgln_if(MALLOC_DEBUG, "LibC: freeing {:p} in allocator {:p} (size={}, used={})", ptr, block, block->bytes_per_chunk(), block->used_chunks());
  333. if (s_scrub_free)
  334. memset(ptr, FREE_SCRUB_BYTE, block->bytes_per_chunk());
  335. auto* entry = (FreelistEntry*)ptr;
  336. entry->next = block->m_freelist;
  337. block->m_freelist = entry;
  338. if (block->is_full()) {
  339. size_t good_size;
  340. auto* allocator = allocator_for_size(block->m_size, good_size);
  341. dbgln_if(MALLOC_DEBUG, "Block {:p} no longer full in size class {}", block, good_size);
  342. g_malloc_stats.number_of_freed_full_blocks++;
  343. allocator->full_blocks.remove(*block);
  344. allocator->usable_blocks.prepend(*block);
  345. }
  346. ++block->m_free_chunks;
  347. if (!block->used_chunks()) {
  348. size_t good_size;
  349. auto* allocator = allocator_for_size(block->m_size, good_size);
  350. if (s_hot_empty_block_count < number_of_hot_chunked_blocks_to_keep_around) {
  351. dbgln_if(MALLOC_DEBUG, "Keeping hot block {:p} around", block);
  352. g_malloc_stats.number_of_hot_keeps++;
  353. allocator->usable_blocks.remove(*block);
  354. s_hot_empty_blocks[s_hot_empty_block_count++] = block;
  355. return;
  356. }
  357. if (s_cold_empty_block_count < number_of_cold_chunked_blocks_to_keep_around) {
  358. dbgln_if(MALLOC_DEBUG, "Keeping cold block {:p} around", block);
  359. g_malloc_stats.number_of_cold_keeps++;
  360. allocator->usable_blocks.remove(*block);
  361. s_cold_empty_blocks[s_cold_empty_block_count++] = block;
  362. mprotect(block, ChunkedBlock::block_size, PROT_NONE);
  363. madvise(block, ChunkedBlock::block_size, MADV_SET_VOLATILE);
  364. return;
  365. }
  366. dbgln_if(MALLOC_DEBUG, "Releasing block {:p} for size class {}", block, good_size);
  367. g_malloc_stats.number_of_frees++;
  368. allocator->usable_blocks.remove(*block);
  369. --allocator->block_count;
  370. os_free(block, ChunkedBlock::block_size);
  371. }
  372. }
  373. void* malloc(size_t size)
  374. {
  375. MemoryAuditingSuppressor suppressor;
  376. void* ptr = malloc_impl(size, CallerWillInitializeMemory::No);
  377. if (s_profiling)
  378. perf_event(PERF_EVENT_MALLOC, size, reinterpret_cast<FlatPtr>(ptr));
  379. return ptr;
  380. }
  381. // This is a Microsoft extension, and is not found on other Unix-like systems.
  382. // FIXME: Implement aligned_alloc() instead
  383. //
  384. // This is used in libc++ to implement C++17 aligned new/delete.
  385. //
  386. // Both Unix-y alternatives to _aligned_malloc(), the C11 aligned_alloc() and
  387. // posix_memalign() say that the resulting pointer can be deallocated with
  388. // regular free(), which means that the allocator has to keep track of the
  389. // requested alignments. By contrast, _aligned_malloc() is paired with
  390. // _aligned_free(), so it can be easily implemented on top of malloc().
  391. void* _aligned_malloc(size_t size, size_t alignment)
  392. {
  393. if (popcount(alignment) != 1) {
  394. errno = EINVAL;
  395. return nullptr;
  396. }
  397. alignment = max(alignment, sizeof(void*));
  398. if (Checked<size_t>::addition_would_overflow(size, alignment)) {
  399. errno = ENOMEM;
  400. return nullptr;
  401. }
  402. void* ptr = malloc(size + alignment);
  403. if (!ptr) {
  404. errno = ENOMEM;
  405. return nullptr;
  406. }
  407. auto aligned_ptr = (void*)(((FlatPtr)ptr + alignment) & ~(alignment - 1));
  408. ((void**)aligned_ptr)[-1] = ptr;
  409. return aligned_ptr;
  410. }
  411. void free(void* ptr)
  412. {
  413. MemoryAuditingSuppressor suppressor;
  414. if (s_profiling)
  415. perf_event(PERF_EVENT_FREE, reinterpret_cast<FlatPtr>(ptr), 0);
  416. ue_notify_free(ptr);
  417. free_impl(ptr);
  418. }
  419. void _aligned_free(void* ptr)
  420. {
  421. if (ptr)
  422. free(((void**)ptr)[-1]);
  423. }
  424. void* calloc(size_t count, size_t size)
  425. {
  426. MemoryAuditingSuppressor suppressor;
  427. if (Checked<size_t>::multiplication_would_overflow(count, size)) {
  428. errno = ENOMEM;
  429. return nullptr;
  430. }
  431. size_t new_size = count * size;
  432. auto* ptr = malloc_impl(new_size, CallerWillInitializeMemory::Yes);
  433. if (ptr)
  434. memset(ptr, 0, new_size);
  435. return ptr;
  436. }
  437. size_t malloc_size(void* ptr)
  438. {
  439. MemoryAuditingSuppressor suppressor;
  440. if (!ptr)
  441. return 0;
  442. void* page_base = (void*)((FlatPtr)ptr & ChunkedBlock::block_mask);
  443. auto* header = (const CommonHeader*)page_base;
  444. auto size = header->m_size;
  445. if (header->m_magic == MAGIC_BIGALLOC_HEADER)
  446. size -= sizeof(CommonHeader);
  447. else
  448. VERIFY(header->m_magic == MAGIC_PAGE_HEADER);
  449. return size;
  450. }
  451. size_t malloc_good_size(size_t size)
  452. {
  453. size_t good_size;
  454. allocator_for_size(size, good_size);
  455. return good_size;
  456. }
  457. void* realloc(void* ptr, size_t size)
  458. {
  459. MemoryAuditingSuppressor suppressor;
  460. if (!ptr)
  461. return malloc(size);
  462. if (!size) {
  463. free(ptr);
  464. return nullptr;
  465. }
  466. auto existing_allocation_size = malloc_size(ptr);
  467. if (size <= existing_allocation_size) {
  468. ue_notify_realloc(ptr, size);
  469. return ptr;
  470. }
  471. auto* new_ptr = malloc(size);
  472. if (new_ptr) {
  473. memcpy(new_ptr, ptr, min(existing_allocation_size, size));
  474. free(ptr);
  475. }
  476. return new_ptr;
  477. }
  478. void __malloc_init()
  479. {
  480. #ifndef NO_TLS
  481. // HACK: This is a __thread - marked thread-local variable. If we initialize it globally, VERY weird errors happen.
  482. // Therefore, we need to do the initialization here and in pthread_create_helper().
  483. s_allocation_enabled = true;
  484. #endif
  485. s_in_userspace_emulator = (int)syscall(SC_emuctl, 0) != -ENOSYS;
  486. if (s_in_userspace_emulator) {
  487. // Don't bother scrubbing memory if we're running in UE since it
  488. // keeps track of heap memory anyway.
  489. s_scrub_malloc = false;
  490. s_scrub_free = false;
  491. }
  492. if (secure_getenv("LIBC_NOSCRUB_MALLOC"))
  493. s_scrub_malloc = false;
  494. if (secure_getenv("LIBC_NOSCRUB_FREE"))
  495. s_scrub_free = false;
  496. if (secure_getenv("LIBC_LOG_MALLOC"))
  497. s_log_malloc = true;
  498. if (secure_getenv("LIBC_PROFILE_MALLOC"))
  499. s_profiling = true;
  500. for (size_t i = 0; i < num_size_classes; ++i) {
  501. new (&allocators()[i]) Allocator();
  502. allocators()[i].size = size_classes[i];
  503. }
  504. new (&big_allocators()[0])(BigAllocator);
  505. }
  506. void serenity_dump_malloc_stats()
  507. {
  508. dbgln("# malloc() calls: {}", g_malloc_stats.number_of_malloc_calls);
  509. dbgln();
  510. dbgln("big alloc hits: {}", g_malloc_stats.number_of_big_allocator_hits);
  511. dbgln("big alloc hits that were purged: {}", g_malloc_stats.number_of_big_allocator_purge_hits);
  512. dbgln("big allocs: {}", g_malloc_stats.number_of_big_allocs);
  513. dbgln();
  514. dbgln("empty hot block hits: {}", g_malloc_stats.number_of_hot_empty_block_hits);
  515. dbgln("empty cold block hits: {}", g_malloc_stats.number_of_cold_empty_block_hits);
  516. dbgln("empty cold block hits that were purged: {}", g_malloc_stats.number_of_cold_empty_block_purge_hits);
  517. dbgln("block allocs: {}", g_malloc_stats.number_of_block_allocs);
  518. dbgln("filled blocks: {}", g_malloc_stats.number_of_blocks_full);
  519. dbgln();
  520. dbgln("# free() calls: {}", g_malloc_stats.number_of_free_calls);
  521. dbgln();
  522. dbgln("big alloc keeps: {}", g_malloc_stats.number_of_big_allocator_keeps);
  523. dbgln("big alloc frees: {}", g_malloc_stats.number_of_big_allocator_frees);
  524. dbgln();
  525. dbgln("full block frees: {}", g_malloc_stats.number_of_freed_full_blocks);
  526. dbgln("number of hot keeps: {}", g_malloc_stats.number_of_hot_keeps);
  527. dbgln("number of cold keeps: {}", g_malloc_stats.number_of_cold_keeps);
  528. dbgln("number of frees: {}", g_malloc_stats.number_of_frees);
  529. }
  530. }