Out of memory and memory limit errors
Out of memory errors
Klocwork 64-bit analysis may encounter out-of-memory errors when insufficient RAM or swap memory is available. The following messages from the Klocwork build log are symptomatic of out-of-memory errors:
kw_pool_dynamic: Cannot allocate memory for segment: xxxxxbytes Failed to allocate more memory!
Workaround: We recommend the following actions to resolve these errors:
- Allocate more memory on the host machine (physical RAM + swap memory).
- Reduce the number of threads used in the Klocwork build, for example, by using the kwbuildproject -j option.
- Limit the amount of memory used by the Klocwork C/C++ Compiler. By default, the Klocwork C/C++ compiler will use up to 16 GB of memory for each thread. However, if out-of-memory errors occur, then a value smaller than 16 should be specified. You can reduce the amount of memory used for each thread by using the --memory-limit compiler option for kwbuildproject, or by using the KW_CLASSIC_ENGINE_MEMORY_LIMIT environment variable.
Calculating a memory limit value
You can use following formula to compute a memory limit value: (total RAM + total swap - reserved amount) / number of jobs)
- the number of jobs is either the value of the -j option (passed to kwbuildproject or kwcheck) or, if the -j option is not used or is 'auto', it is the number of logical CPU cores plus 1.
- the reserved amount is the total amount of memory needed for the rest of the system to function.
Memory limit errors
The Klocwork C/C++ compiler will use a maximum of 16 GB per thread on 64-bit systems. An attempt to exceed this limit will result in the following error message in the Klocwork build log, for example:REPCXX has exceeded the memory threshold of 16000000 Kb, mem_usage=... Kb. Memory threshold can be increased by passing a value (in GB) to REPCXX through the `--memory-limit=` option or through the `KW_CLASSIC_ENGINE_MEMORY_LIMIT` environment variable.
To resolve this error, use the --memory-limit compiler option for kwbuildproject, or the KW_CLASSIC_ENGINE_MEMORY_LIMIT environment variable to increase the memory available to the Klocwork C/C++ compiler.