On Mon Feb 6 16:41:16 2023 +0000, Jinoh Kang wrote:
Putting groups into the linked lists earlier removes that option and I
think it becomes harder to act on fully freed groups. Thanks, I get it. However, this implies that the existing implementation isn't exactly free from this problem either: a group that has never been fully allocated cannot be released to subheap even it is now fully free. I think this problem can be overcome by forbidding partially free group from being added to a group list at all. We still allow partially free groups for `affinity_group` since a group knows which `affinity_group` slot it belongs to. This also means that `heap_free_block_lfh` can never encounter a block from a group that belongs to a lookaside SList, which eliminates the RTL SList atomicity problem as well.
Yes, the current implementation also has a slight memory consumption overhead (at most a number of groups roughly equal to twice the size of the affinity array for each enabled category). I think it is acceptable.
I think I actually prefer not to reuse the linked list pointer for something else than the calls to `SList` functions. And using only the `free_bits` member for the group ownership logic, although it requires a bit of semantic overload of the last bit for the flag, allows us to use atomic operations on a single field, and imho is easier to reason about than operations on two separate fields.
For instance, setting `GROUP_FLAG_FREE` can be done atomically with the check that the other bits of `free_bits` are still all unset.