NEVER_INLINE void* MemoryManager::smartCallocBig(size_t totalbytes) { assert(totalbytes > 0); auto const n = static_cast<BigNode*>( safe_calloc(totalbytes + sizeof(BigNode), 1) ); return smartEnlist(n); }
NEVER_INLINE void* MemoryManager::smartMallocBig(size_t nbytes) { assert(nbytes > 0); auto const n = static_cast<SweepNode*>( Util::safe_malloc(nbytes + sizeof(SweepNode) - sizeof(SmallNode)) ); return smartEnlist(n); }
NEVER_INLINE void* MemoryManager::smartMallocSizeBigHelper(void*& ptr, size_t& szOut, size_t bytes) { m_stats.usage += bytes; allocm(&ptr, &szOut, debugAddExtra(bytes + sizeof(SweepNode)), 0); szOut = debugRemoveExtra(szOut - sizeof(SweepNode)); return debugPostAllocate( smartEnlist(static_cast<SweepNode*>(ptr)), bytes, szOut ); }
NEVER_INLINE void* MemoryManager::smartMallocSizeBigHelper(void*& ptr, size_t& szOut, size_t bytes) { ptr = mallocx(debugAddExtra(bytes + sizeof(BigNode)), 0); szOut = debugRemoveExtra(sallocx(ptr, 0) - sizeof(BigNode)); // NB: We don't report the SweepNode size in the stats. auto const delta = callerSavesActualSize ? szOut : bytes; m_stats.usage += int64_t(delta); // Adjust jemalloc otherwise we'll double count the direct allocation. JEMALLOC_STATS_ADJUST(&m_stats, delta); return debugPostAllocate( smartEnlist(static_cast<BigNode*>(ptr)), bytes, szOut ); }
template<bool callerSavesActualSize> NEVER_INLINE MemBlock MemoryManager::smartMallocSizeBig(size_t bytes) { #ifdef USE_JEMALLOC auto const n = static_cast<BigNode*>( mallocx(debugAddExtra(bytes + sizeof(BigNode)), 0) ); auto szOut = debugRemoveExtra(sallocx(n, 0) - sizeof(BigNode)); // NB: We don't report the SweepNode size in the stats. auto const delta = callerSavesActualSize ? szOut : bytes; m_stats.usage += int64_t(delta); // Adjust jemalloc otherwise we'll double count the direct allocation. JEMALLOC_STATS_ADJUST(&m_stats, delta); #else m_stats.usage += bytes; auto const n = static_cast<BigNode*>( safe_malloc(debugAddExtra(bytes + sizeof(BigNode))) ); auto szOut = bytes; #endif auto ptrOut = debugPostAllocate(smartEnlist(n), bytes, szOut); FTRACE(3, "smartMallocSizeBig: {} ({} requested, {} usable)\n", ptrOut, bytes, szOut); return {ptrOut, szOut}; }