|
|
Subscribe / Log in / New account

ABA problems and pool allocation

ABA problems and pool allocation

Posted Oct 12, 2025 15:48 UTC (Sun) by alison (subscriber, #63752)
In reply to: Provenance is a hard problem, so I'm probably missing something here by daroc
Parent article: Progress on defeating lifetime-end pointer zapping

>Thread 1 reads a pointer to A from the top of the linked list, and is then immediately preempted. Thread 2 pops from the list, frees A, allocates B in the same location, and pushes B.

That's a classic ABA problem. The example always given is that of a motorist waiting at a red light, who during the delay begins to read LWN on their phone. A moment later, the motorist wonders, "Oops, did I miss the green light?" The light is red, so they conclude that the answer is no.

Reading the discussion made me wonder if the generally admirable practice of providing buffers from a preallocated pool rather than creating them anew at runtime would increase the likelihood of an ABA problem. The answer must be yes.


to post comments

ABA problems and pool allocation

Posted Oct 13, 2025 10:35 UTC (Mon) by chris_se (subscriber, #99706) [Link]

> Reading the discussion made me wonder if the generally admirable practice of providing buffers from a preallocated pool rather than creating them anew at runtime would increase the likelihood of an ABA problem. The answer must be yes.

Well, it probably depends on specifics whether that's true or not. Internally many memory allocators also like to use pools of memory for objects with the same size, so this will strongly depend on the details of your memory allocator and/or the details on your own pool-based algorithm.

Funnily enough, since this specific ABA problem is not a "traditional" ABA problem, but is "just" about provenance, taking them from a preallocated pool of pre-created objects (not just pre-allocated memory) would solve the undefined behavior issue, because the object never gets destroyed in the sense the compiler developers are thinking about. This is different from other ABA problems where you are in fact required to use RCU, hazard pointers, double-word CAS, or similar methods to actually solve the problem. In contrast, this stack example only suffers from the ABA issue regarding the provenance of the pointer, but the assembly code generated by current compilers will work at the moment, which is not the case for the other types of ABA problems.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds