Open cmichi opened 5 years ago
FWIW, there are more options for sentiel value:
GlobalAlloc
implementation, since returning NULL pointer from there denotes OOM condition and thus will lead to abort and panic which is not desirable since 0-allocation is pretty legit. Besides that, sometimes we return pointers to the allocated data from the Substrate Runtime Interfae host, so we need to ensure that these values are not used for things like from_raw_parts
or similar.@cmichi , dead link: https://github.com/paritytech/substrate/blob/master/core/executor/src/allocator.rs#L87
Is this issue still actual?
(this does not look like a bug
, more of a flaw
)
@abebeos This issue is four years old. I would be surprised if it's still relevant.
I am no longer involved with Substrate, best to check who modified relevant code for this issue last and ask that person about it.
This issue is four years old. I would be surprised if it's still relevant.
Yes, I always enter projects via the "oldies". At least the minimum I do is triggering a cleanup.
I am no longer involved with Substrate, best to check who modified relevant code for this issue last and ask that person about it.
k
@gilescope , @bkchr , @kianenigma
@abebeos so what is your question here? If this is still relevant?
@abebeos so what is your question here? If this is still relevant?
Yes, few comments up I reported a dead link and asked: https://github.com/paritytech/substrate/issues/3561#issuecomment-1440318041
Link should point here
(thinking about it, this zero-alloc looks like a standard problem. A standard solution should exist)
Escalated from the discussion here.
Right now the allocator always uses at least 8 bytes when allocating (see here), even when
alloc(0)
is called. Instead the case of zero-sized allocations should be handled specially, without actually allocating space (which is done at the moment).One idea to explore is to return a "sentinel pointer"; something like
sentinel_ptr = align_to_8_bytes(max_heap_size + 1)
would be guaranteed to not be a valid pointer and could be used.dealloc
needs to be aware of this "sentinel pointer" and handle it specially (by not actually freeing).If you want to work on this, it's best to talk to @pepyakin for more details.