Quick Pool Memory Manager

The Quick Pool memory manager breaks memory up into a series of pools. It is intended to improve heap performance for applications that issue large numbers of small allocation requests. When the Quick Pool memory manager is enabled, allocation requests that fall within a given range of block sizes are assigned a cell within a pool. These requests can be handled more quickly than requests outside of this range. Allocation requests outside this range are handled in the same manner as the default memory manager.

A pool consists of a block of memory (called an extent) that is subdivided into a predetermined number of smaller blocks (called cells) of uniform size. Each cell can be allocated as a block of memory. Each pool is identified using a pool number. The first pool is pool 1, the second pool is pool 2, the third pool is pool 3, and so on. The first pool is the smallest and each succeeding pool is equal to or larger in size than the preceding pool.

The number of pools and cell sizes for each of the pools is determined at the time the Quick Pool memory manager is initialized.

Allocation

A cell is allocated from one of the pools when an allocation request falls within the range of cell sizes defined by the pools. Each allocation request is serviced from the smallest possible pool to conserve space.

When the first request comes in for a pool, an extent is allocated for the pool and the request is satisfied from that extent. Later requests for that pool are also satisfied by the extent until the extent is exhausted. When an extent is exhausted, a new extent is allocated for the pool.

Deallocation

Memory blocks (cells) deallocated with the free operation are added to a free queue associated with the pool that contains the cell. Each pool has a free queue that contains cells that have been freed and have not yet been reallocated. Additional allocation requests from that pool use cells from the free queue.

Reallocation

If the size of the reallocated block falls within the same pool as the original block, the original block is returned without any data movement. Otherwise, a new block of the requested size is allocated, the data is moved from the original block to the new block, the original block is returned to the free queue with the free operation, and the new block is returned to the caller.

Enabling the Quick Pool Memory Manager

The Quick Pool memory manager is not enabled by default. It is enabled and configured either by calling the _C_Quickpool_Init() and _C_Quickpool_Debug() functions or by setting the following environment variables:
QIBM_MALLOC_TYPE=QUICKPOOL
QIBM_MALLOC_QUICKPOOL_OPTIONS=options

To enable the Quick Pool memory manager with the default settings, the QIBM_MALLOC_QUICKPOOL_OPTIONS environment variable does not need to be specified, only QIBM_MALLOC_TYPE=QUICKPOOL needs to be specified. To enable the Quick Pool memory manager with user-specified configuration options, set QIBM_MALLOC_QUICKPOOL_OPTIONS=options, where options is a blank delimited list of one or more configuration options.

If the QIBM_MALLOC_TYPE=QUICKPOOL environment variable is specified and the_C_Quickpool_Init() function is called, the environment variable settings take precedence over the _C_Quickpool_Init() function and the _C_Quickpool_Init() function returns a -1 value indicating that an alternate heap manager has already been enabled.

If the QIBM_MALLOC_TYPE=QUICKPOOL environment variable is specified and the _C_Quickpool_Debug() function is called to change the Quick Pool memory manager characteristics, the settings specified on the parameter to the _C_Quickpool_Debug() function override the environment variable settings.

Configuration Options

The following configuration options are available:

POOLS:(C1 E1)(C2 E2)...(Cn En)

This option can be used to specify the number of pools to be used, along with the cell size and extent cell count for each pool. The subscript value n indicates the number of pools. The minimum valid value of n is 1. The maximum valid value of n is 64.

The value C1 indicates the cell size for pool 1, C2 indicates the cell size for pool 2, Cn indicates the cell size for pool n, and so on. This value must be a multiple of 16 bytes. If a value is specified that is not a multiple of 16 bytes, the cell size is rounded up to the next larger multiple of 16 bytes. The minimum valid value is 16 and the maximum valid value is 4096.

The value E1 indicates the extent cell count for pool 1, E2 indicates the extent cell count for pool 2, En indicates the extent cell count for pool n, and so on. The value specifies the number of cells in a single extent. The value can be any non-negative number, but the total size of the extent might be limited due to architecture constraints. A value of zero indicates that the implementation can choose a large value.

The default value for this option is "POOLS:(16 4096) (32 4096) (64 1024) (128 1024) (256 512) (512 512) (1024 256) (2048 256) (4096 256)". The defaults represent 9 pools with cells of sizes 16, 32, 64, 128, 256, 512, 1024, 2048, and 4096 bytes. The number of cells in each extent is 4096, 4096, 1024, 1024, 512, 512, 256, 256, and 256.

MALLOC_INIT:N

This option can be used to specify that each byte of allocated memory is initialized to the given value. The value N represents an integer in the range of 0 to 255.

This option is not enabled by default.

FREE_INIT:N

This option can be used to specify that each byte of freed memory is initialized to the given value. The value N represents an integer in the range of 0 to 255.

This option is not enabled by default.

COLLECT_STATS

This option can be used to specify that the Quick Pool memory manager collect statistics and report those statistics upon termination of the application. The Quick Pool memory manager collects statistics by calling atexit(_C_Quickpool_Report) when this option is specified. Details about the information contained within that report are documented in the description for _C_Quickpool_Report().

This option is not enabled by default.

Any number of options can be specified and they can be specified in any order. Blanks are the only valid delimiters for separating configuration options. Each configuration option should only be specified once. If a configuration option is specified more than once, only the final instance applies. If a configuration option is specified with an invalid value, the configuration option is ignored.

Examples
ADDENVVAR ENVVAR(QIBM_MALLOC_QUICKPOOL_OPTIONS) LEVEL(*JOB) REPLACE(*YES) 
VALUE('POOLS:(16 4096) (32 4096) (64 1024) (128 1024) (256 512) (512 512) (1024 256) 
(2048 256) (4096 256)')

ADDENVVAR ENVVAR(QIBM_MALLOC_QUICKPOOL_OPTIONS) LEVEL(*JOB) REPLACE(*YES)
VALUE('POOLS:(16 1000) MALLOC_INIT:255 FREE_INIT:0 COLLECT_STATS')

The first example represents the default configuration values. The second example illustrates all options being specified.

Related Functions

The _C_Quickpool_Init() function allows enablement of the Quick Pool memory manager. The _C_Quickpool_Init() function also specifies the number of pools to be used, the cell size, and the extent cell count for each pool.

The _C_Quickpool_Debug() function allows enablement of the other configuration options.

The _C_Quickpool_Report() function is used to report memory statistics.
Note:
  1. The default configuration for the Quick Pool memory manager provides a performance improvement for many applications that issue large numbers of small allocation requests. However, it might be possible to achieve additional gains by modifying the default configuration. Before modifying the default configuration, become familiar with the memory requirements and usage of the application. The Quick Pool memory manager can be enabled with the COLLECT_STATS option to fine-tune the Quick Pool memory manager configuration.
  2. Because of variations in memory requirements and usage, some applications might not benefit from the memory allocation scheme used by the Quick Pool memory manager. Therefore, it is not advisable to enable the Quick Pool memory manager for system-wide use. For optimal performance, enable and configure the Quick Pool memory manager on a per-application basis.
  3. It is allowable to create more than one pool with the same size cells. This can be useful for multi-threaded applications which perform many similar sized allocations. When there is no contention, the first pool of the requested size is used. When contention occurs on the first pool, the Quick Pool memory manager allocates cells from any other equal sized pools to minimize contention.

Related Information