mallocMC icon indicating copy to clipboard operation
mallocMC copied to clipboard

Discrepancy between calls to `setMemPool` and `resetMemPool`

Open chillenzer opened this issue 1 year ago • 2 comments

I've just started to read through the code and one of the first things to note was that l. 145, 146 and 149 seem to be somewhat inconsistent: We get our void* pool in the alloc method from setMemPool and later want to basically free it in the free method via handing it back to resetMemPool. But the pointer gets modified in between by the AlignmentPolicy, so we are basically freeing a different pointer than we allocated which is undefined behaviour.

It is not technically a problem currently because all ReservePoolPolicies I've found in the codebase completely ignore the pointer they are given but that is surely not how the interface was intended.

chillenzer avatar Mar 22 '24 09:03 chillenzer

This is not a problem because the pointer is not used to free memory. We use alpaka buffers which handle the lifetime and locations of the buffer correctly.

psychocoderHPC avatar Mar 22 '24 11:03 psychocoderHPC

As alluded to above, that is a true statement for the reservation policies that are currently shipped with mallocMC. But this will still blow up in any person's face who implements their own reservation policy. I would say that this is still a significant bug in the Allocator class or the reservation policies' interface definition.

So, I would propose that we officially define the reservation policy as the owner of the memory such that no pointer needs to be communicated in the resetMemPool call. (Agreed upon offline already.)

chillenzer avatar Mar 22 '24 12:03 chillenzer