On 1/22/2021 2:10 PM, Chris M. Thomasson wrote:
> On 1/21/2021 11:43 PM, David Brown wrote:
>> On 22/01/2021 08:22, Bonita Montero wrote:
>>>>> Because there isn't any native type, even those platform-specific
>>>>> like those __512*-datatypes, which need an alignment of kBs.
>>>
>>>> One can over align on purpose to steal bits and do other fancy
>>>> things wrt, say, memory allocators.
>>>
>>> There's no reason to declare data structures to be aligned beyond
>>> any native data type.
>>
>> Of course there is.
[...]
> I have some older memory allocators that could simply round freed memory
> down to a page boundary where a header is, and link it into a lock-free
> list. This allowed the granularity of a memory block to be the size of a
> pointer. Pretty nice, and fast.
Wrt my older memory allocators and special free lists... Well, I could
tell if the memory being freed was allocated from the same thread that
allocated it to begin with. Iirc, it went something like:
round the freed address F down to a page boundary.
Get the per thread page, TLS and such.
Okay, now we compare the freed rounded down address F to the freeing
threads main page address. If they are the same, aka (local memory),
then we could free the memory F directly to our local stack without
using any membars or atomics. Now, if they were different (remote
memory), then I had to use a lock-free stack to pass the memory back to
the remote thread that allocated it to being with.
So a page "header" had two free lists, local and remote. When malloc
failed to grab local memory from the local list, it flushed the remote,
transferred to local, and tried the local free list again. If that
failed it tried to grab another page from the global pool. If that
failed it would allocate new memory from the system. If that failed, it
returned NULL to the calling thread.
A multi-layered approach wrt malloc and free.
This is bringing up many old memories! This thread is cool. Thanks
everybody.
Wrt my old experimental memory allocator, this made all memory
allocations be at least as big as a pointer. So, allocating memory >= to
a pointer size does not incur any extra overhead. However, allocating a
single char, will be rounded up to a pointer size.