diff --git a/src/proxy_lib/proxy_lib.c b/src/proxy_lib/proxy_lib.c index ef4d9dc846..8f818de116 100644 --- a/src/proxy_lib/proxy_lib.c +++ b/src/proxy_lib/proxy_lib.c @@ -128,6 +128,13 @@ static umf_memory_pool_handle_t Proxy_pool = NULL; // it protects us from recursion in umfPool*() static __TLS int was_called_from_umfPool = 0; +// This WA for the issue: +// https://github.com/oneapi-src/unified-memory-framework/issues/894 +// It protects us from a recursion in malloc_usable_size() +// when the JEMALLOC proxy_lib_pool is used. +// TODO remove this WA when the issue is fixed. +static __TLS int was_called_from_malloc_usable_size = 0; + /*****************************************************************************/ /*** The constructor and destructor of the proxy library *********************/ /*****************************************************************************/ @@ -454,15 +461,18 @@ size_t malloc_usable_size(void *ptr) { return 0; // unsupported in case of the ba_leak allocator } - if (Proxy_pool && (umfPoolByPtr(ptr) == Proxy_pool)) { + if (!was_called_from_malloc_usable_size && Proxy_pool && + (umfPoolByPtr(ptr) == Proxy_pool)) { + was_called_from_malloc_usable_size = 1; was_called_from_umfPool = 1; size_t size = umfPoolMallocUsableSize(Proxy_pool, ptr); was_called_from_umfPool = 0; + was_called_from_malloc_usable_size = 0; return size; } #ifndef _WIN32 - if (Size_threshold_value) { + if (!was_called_from_malloc_usable_size && Size_threshold_value) { return System_malloc_usable_size(ptr); } #endif /* _WIN32 */