Memory Management (Memory Pool Allocator)
Collaboration diagram for Memory Management (Memory Pool Allocator):


class  MemPoolIterator
class  mgb_t
class  MemPoolMeter
class  MemPools
class  MemAllocator
class  MemImplementingAllocator
class  MemPoolStats
struct  _MemPoolGlobalStats
class  MemPoolChunked
class  MemChunk
class  MemPoolMalloc


#define toMB(size)   ( ((double) size) / ((double)(1024*1024)) )
#define toKB(size)   ( (size + 1024 - 1) / 1024 )
#define MEM_PAGE_SIZE   4096
#define MEM_MIN_FREE   32
#define MEM_MAX_FREE   65535 /* unsigned short is max number of items per chunk */
#define memPoolCreate   MemPools::GetInstance().create


typedef struct _MemPoolGlobalStats MemPoolGlobalStats


MemPoolIteratormemPoolIterate (void)
MemImplementingAllocatormemPoolIterateNext (MemPoolIterator *iter)
void memPoolIterateDone (MemPoolIterator **iter)
int memPoolGetGlobalStats (MemPoolGlobalStats *stats)
int memPoolsTotalAllocated (void)

Detailed Description

MemPools are a pooled memory allocator running on top of malloc(). It's purpose is to reduce memory fragmentation and provide detailed statistics on memory consumption.
Preferably all memory allocations in Squid should be done using MemPools or one of the types built on top of it (i.e. cbdata).
Usually it is better to use cbdata types as these gives you additional safeguards in references and typechecking. However, for high usage pools where the cbdata functionality of cbdata is not required directly using a MemPool might be the way to go.

Macro Definition Documentation


#define MEM_MAX_FREE   65535 /* unsigned short is max number of items per chunk */

Definition at line 59 of file Pool.h.


#define MEM_MIN_FREE   32

Definition at line 57 of file Pool.h.


#define MEM_PAGE_SIZE   4096

Definition at line 55 of file Pool.h.

◆ memPoolCreate

#define memPoolCreate   MemPools::GetInstance().create

Creates a named MemPool of elements with the given size

Definition at line 325 of file Pool.h.

◆ toKB

#define toKB (   size)    ( (size + 1024 - 1) / 1024 )

Definition at line 52 of file Pool.h.

◆ toMB

#define toMB (   size)    ( ((double) size) / ((double)(1024*1024)) )

Definition at line 50 of file Pool.h.

Typedef Documentation

◆ MemPoolGlobalStats

TODO: Kill this typedef for C++

Definition at line 66 of file Pool.h.

Function Documentation

◆ memPoolGetGlobalStats()

int memPoolGetGlobalStats ( MemPoolGlobalStats stats)

Fills a MemPoolGlobalStats with statistical data about overall usage for all pools.

statsObject to be filled with statistical data.
Number of pools that have at least one object in use. Ie. number of dirty pools.

Definition at line 249 of file

References MemPoolStats::chunks_alloc, MemPoolStats::chunks_free, MemPoolStats::chunks_inuse, MemPoolStats::chunks_partial, MemPools::flushMeters(), MemPools::GetInstance(), MemAllocator::getStats(), MemPoolStats::items_alloc, MemPoolStats::items_idle, MemPoolStats::items_inuse, MemPools::mem_idle_limit, memPoolIterate(), memPoolIterateDone(), memPoolIterateNext(), MemPoolStats::overhead, Pool_id_counter, MemPools::poolCount, pp_stats, Ping::stats, and TheMeter.

Referenced by DumpInfo(), GetInfo(), memClean(), memPoolsTotalAllocated(), and Mem::Report().

◆ memPoolIterate()

MemPoolIterator * memPoolIterate ( void  )

Initialise iteration through all of the pools.

Iterator for use by memPoolIterateNext() and memPoolIterateDone()

Definition at line 39 of file

References MemPools::GetInstance(), Iterator, MemPoolIterator::pool, and MemPools::pools.

Referenced by MemPools::clean(), MemPools::flushMeters(), memPoolGetGlobalStats(), and Mem::Report().

◆ memPoolIterateDone()

void memPoolIterateDone ( MemPoolIterator **  iter)

Should be called after finished with iterating through all pools.

Definition at line 46 of file

References assert, Iterator, and MemPoolIterator::pool.

Referenced by MemPools::clean(), MemPools::flushMeters(), memPoolGetGlobalStats(), and Mem::Report().

◆ memPoolIterateNext()

MemImplementingAllocator * memPoolIterateNext ( MemPoolIterator iter)

Get next pool pointer, until getting NULL pointer.

Definition at line 54 of file

References assert, MemImplementingAllocator::next, and MemPoolIterator::pool.

Referenced by MemPools::clean(), MemPools::flushMeters(), memPoolGetGlobalStats(), and Mem::Report().

◆ memPoolsTotalAllocated()

int memPoolsTotalAllocated ( void  )

Definition at line 298 of file

References memPoolGetGlobalStats(), and Ping::stats.

Referenced by statMemoryAccounted().






Web Site Translations