unified-memory-framework icon indicating copy to clipboard operation
unified-memory-framework copied to clipboard

Disjoint pool causes memory leak calling umfMemoryProviderFree() with size equal 0

Open ldorau opened this issue 9 months ago • 4 comments

Disjoint pool causes memory leak calling umfMemoryProviderFree() with size equal 0:

https://github.com/oneapi-src/unified-memory-framework/blob/6fc3e56b4870184dec70613359c4db2ef7f1180a/src/pool/pool_disjoint.cpp#L407

static void memoryProviderFree(umf_memory_provider_handle_t hProvider,
                               void *ptr) {
    auto ret = umfMemoryProviderFree(hProvider, ptr, 0);
    if (ret != UMF_RESULT_SUCCESS) {
        throw MemoryProviderError{ret};
    }
}

what can cause an error (which is ignored now).

Environment Information

  • UMF version (hash commit or a tag): 6fc3e56b4870184dec70613359c4db2ef7f1180a

ldorau avatar May 10 '24 07:05 ldorau

@igchor @vinser52 @bratpiorka

ldorau avatar May 10 '24 07:05 ldorau

More details just FYI. Initially disjoint pool was designed for L0 provider. L0 provider does not need the size when memory is freed (the size parameter is ignored). The similar story is with the OS provider implementation on Windows - the size parameter is ignored when memory is freed.

vinser52 avatar May 10 '24 07:05 vinser52

When we are deallocating Slabs then it's easy, we can just pass the Slab size here: https://github.com/oneapi-src/unified-memory-framework/blob/6fc3e56b4870184dec70613359c4db2ef7f1180a/src/pool/pool_disjoint.cpp#L441

But for allocations that bypass the pooling we do not know the size. Perhaps we could leverage memory tracking there?

igchor avatar May 10 '24 14:05 igchor

But for allocations that bypass the pooling we do not know the size. Perhaps we could leverage memory tracking there?

Exactly, the plan is to use tracking capabilities. @ldorau already prepared such a fix for the pool_proxy: Red #487.

vinser52 avatar May 10 '24 14:05 vinser52

@vinser52 @igchor The fix is ready: #490 - please review :-)

ldorau avatar May 13 '24 10:05 ldorau