oneapi-src / unified-memory-framework

A library for constructing allocators and memory pools. It also contains broadly useful abstractions and utilities for memory management. UMF allows users to manage multiple memory pools characterized by different attributes, allowing certain allocation types to be isolated from others and allocated using different hardware resources as required.
https://oneapi-src.github.io/unified-memory-framework/
Other
35 stars 26 forks source link

The pool_proxy causes memory leak when used with OS memory provider. #475

Closed vinser52 closed 5 months ago

vinser52 commented 5 months ago

The pool_proxy implementation is straightforward and simply proxies all allocation/deallocation requests to the underlying memory provider. The proxy_free() function just calls the umfMemoryProviderFree() function which requires the size of the allocation as the last argument. Since the proxy_pool implementation has no any state, the size is unknown and the proxy_free() function just passes 0 as the size argument to the umfMemoryProviderFree() function.

Furthermore, OS memory provider implementation ignores this fact. When 0 is passed as the size argument to the os_free it ignores the error returned by the os_munmap function if the size is 0.

How often bug is revealed:

always

Details

ldorau commented 5 months ago

@vinser52 @igchor @bratpiorka

Furthermore, OS memory provider implementation ignores this fact. When 0 is passed as the size argument to the os_free it ignores the error returned by the os_munmap function if the size is 0.

os_free() should not ignore this error, but it cannot be changed now, because of the implementation of disjoint pool (see: #481): https://github.com/oneapi-src/unified-memory-framework/blob/6fc3e56b4870184dec70613359c4db2ef7f1180a/src/pool/pool_disjoint.cpp#L405-L411

and because of the implementation of proxy_free() of course:

static umf_result_t (void *pool, void *ptr) {
    assert(pool);
    struct proxy_memory_pool *hPool = (struct proxy_memory_pool *)pool;
    return umfMemoryProviderFree(hPool->hProvider, ptr, 0);
}
ldorau commented 5 months ago

I propose a fix: #482

ldorau commented 5 months ago

New fix: https://github.com/oneapi-src/unified-memory-framework/pull/487