Malloc log

Malloc Log is an optional extension of the malloc subsystem, allowing the user to obtain information regarding the active allocations currently held by the calling process. This data can then be used in problem determination and performance analysis.

Data recorded in the malloc log

Malloc Log records the following data for each active allocation:
  • The address returned to the caller.
  • The size of the allocation.
  • The heap which the allocation was serviced from.
  • The stack traceback of the calling function. The depth of the traceback that is recorded is a configurable option.
In addition, the following information can optionally be logged:
  • The process ID of the calling process.
  • The thread ID of the calling thread.
  • The sequence number of the allocation with respect to process startup.
  • The real time in which the allocation was made.

With Malloc Log enabled, each successful allocation requires an additional amount of overhead used to store the metadata. This overhead is around 50-100 bytes for a 32-bit application; twice that for a 64-bit application. The amount of overhead changes depending on the options that are set.

The Malloc Log information can be accessed in the following ways:
  • Using the DBX malloc subcommand.
  • Using the report_allocations malloc debug option.

Enabling malloc log

Malloc Log is not enabled by default. To enable Malloc Log with the default settings, set the MALLOCDEBUG environment variable as follows:
MALLOCDEBUG=log
To enable Malloc Log with user-specified configuration options, set the MALLOCDEBUG environment variable as follows:
MALLOCDEBUG=log:extended,stack_depth:6
Note: The default Malloc Log values are as follows:
extended
Defaults to off. Specifying this option will enable the logging of the optional allocation metadata specified above. This parameter will affect the amount of overhead required for each allocation. This option does not have any effect if MALLOCTYPE is set to watson2.
stack_depth
Used to specify the depth of the function-call stack that is recorded for each allocation. This parameter affects the amount of overhead required for each allocation The default value is 4, the maximum is 64.

Limitations

The performance of all programs can degrade when Malloc Log is enabled, due to the cost of storing data to memory. Memory usage will also increase.

The Malloc Log debugging feature is compatible with the following malloc policies and options: