@@ -152,15 +152,19 @@ mca_btl_openib_component_t mca_btl_openib_component = {
152152/* This is a memory allocator hook. The purpose of this is to make
153153 * every malloc aligned since this speeds up IB HCA work.
154154 * There two basic cases here:
155- * 1. Memory manager for Open MPI is enabled. Then memalign below will be
156- * overridden by __memalign_hook which is set to opal_memory_linux_memalign_hook.
157- * Thus, _malloc_hook is going to use opal_memory_linux_memalign_hook.
155+ *
156+ * 1. Memory manager for Open MPI is enabled. Then memalign below will
157+ * be overridden by __memalign_hook which is set to
158+ * opal_memory_linux_memalign_hook. Thus, _malloc_hook is going to
159+ * use opal_memory_linux_memalign_hook.
160+ *
158161 * 2. No memory manager support. The memalign below is just regular glibc
159162 * memalign which will be called through __malloc_hook instead of malloc.
160163 */
161164static void * btl_openib_malloc_hook (size_t sz , const void * caller )
162165{
163- if (sz < mca_btl_openib_component .memalign_threshold ) {
166+ if (sz < mca_btl_openib_component .memalign_threshold &&
167+ malloc_hook_set ) {
164168 return mca_btl_openib_component .previous_malloc_hook (sz , caller );
165169 } else {
166170 return memalign (mca_btl_openib_component .use_memalign , sz );
@@ -275,6 +279,7 @@ static int btl_openib_component_close(void)
275279 then _close() (which won't set the hook) */
276280 if (malloc_hook_set ) {
277281 __malloc_hook = mca_btl_openib_component .previous_malloc_hook ;
282+ malloc_hook_set = false;
278283 }
279284#endif
280285
@@ -2518,14 +2523,14 @@ btl_openib_component_init(int *num_btl_modules,
25182523
25192524#if BTL_OPENIB_MALLOC_HOOKS_ENABLED
25202525 /* If we got this far, then setup the memory alloc hook (because
2521- we're most likely going to be using this component). The hook is to be set up
2522- as early as possible in this function since we want most of the allocated resources
2523- be aligned.*/
2526+ we're most likely going to be using this component). The hook
2527+ is to be set up as early as possible in this function since we
2528+ want most of the allocated resources be aligned.*/
25242529 if (mca_btl_openib_component .use_memalign > 0 &&
25252530 (opal_mem_hooks_support_level () &
25262531 (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_CHUNK_SUPPORT )) != 0 ) {
25272532 mca_btl_openib_component .previous_malloc_hook = __malloc_hook ;
2528- __malloc_hook = btl_openib_malloc_hook ;
2533+ __malloc_hook = btl_openib_malloc_hook ;
25292534 malloc_hook_set = true;
25302535 }
25312536#endif
@@ -2944,6 +2949,7 @@ btl_openib_component_init(int *num_btl_modules,
29442949 /*Unset malloc hook since the component won't start*/
29452950 if (malloc_hook_set ) {
29462951 __malloc_hook = mca_btl_openib_component .previous_malloc_hook ;
2952+ malloc_hook_set = false;
29472953 }
29482954#endif
29492955 if (NULL != btls ) {
0 commit comments