Memory allocation

There might be heap memory allocation issues when you migrate your program to IBM Open XL C/C++ for AIX 17.1.3.

IBM Open XL C/C++ for AIX 17.1.3 pre-defines the __VEC__ macro by default because the compiler supports POWER7 and higher processors. The _ALL_SOURCE macro is defined by the AIX® system headers unless the macro is suppressed by other macros like _XOPEN_SOURCE. When both the __VEC__ and _ALL_SOURCE macros are defined, the malloc and calloc system calls are mapped to vec_malloc and vec_calloc respectively in the AIX system header file /usr/include/stdlib.h.
Note: When both the __VEC__ and _ALL_SOURCE macros are defined, the effect of the _LINUX_SOURCE_COMPAT macro on malloc and calloc system calls is ignored.

The malloc and calloc system calls give 8-byte aligned allocations, while vec_malloc and vec_calloc give 16-byte aligned allocations. After malloc and calloc are mapped to vec_malloc and vec_calloc, heap memory consumption is greatly increased if an application makes a lot of small heap allocations, which causes the application to run out of memory unexpectedly if the application is built with a certain maxdata value.

To fix the problem, try one of the following approaches:
  1. Compile your program without the _ALL_SOURCE macro and call the vec_malloc, vec_calloc, or posix_memalign system call explicitly where 16-byte alignment is required.
  2. Compile your program with the -mno-altivec option.
  3. If the above approaches are not feasible, then for 32-bit applications, link the generated application with a larger -bmaxdata value to accommodate the extra space required due to vec_malloc and vec_calloc. For example, if you had originally specified -bmaxdata:0x80000000, you need to change the setting to a larger value, such as -bmaxdata:0xa0000000/dsa. The actual amount of additional memory depends on how the application allocates heap memory.
  4. For an existing binary, set a new maxdata value using either the LDR_CNTRL environment variable or the ldedit command. For details, see Large program support.