On Wed, Sep 10, 2025 at 11:35:56AM +1000, Finn Thain wrote:
Similarly, on m68k, there is no issue with __alignof(long) == 2 because these platforms don't trap on misaligned access. But that seems a bit irrelevant to the real issue, which is not specific architectural quirks, but the algorithms and their ongoing development.
Err, I believe the topic was just alignment and the breaking of commonly held expectations :)
...
IMHO, good C doesn't make alignment assumptions, because that hinders source code portability and reuse, as well as algorithm extensibility. We've seen it before. The issue here [1] is no different from the pointer abuse which we fixed in Cpython [2].
That kind of thinking really dates from before multithreaded and even lockless algorithms became absolutely pervasive, especially in the kernel.
What I meant was, "assumptions hinder portability etc." not "good C hinders portability etc." (my bad).
Of course, but given the lack of a true atomic type in C there's no good alternative way to avoid this landmine.
Also, grep for READ_ONCE/WRITE_ONCE in the kernel tree if you want to see how big the issue is - ad then remember that only captures a fraction of it :)
These days, READ_ONCE() and WRITE_ONCE() are pervasive, and since C lacks any notion of atomics in the type system (the place this primarily comes up), it would go a long ways towards improving portability and eliminating nasty land mines.
Natural alignment would seem to be desirable for new ABIs, until you realize that it implies wasted RAM on embedded systems and reduced data locality (that is, cooler caches if you did this on i386).
For the data structures where it matters we tend to organize things by natural alignment already.
If anyone wanted to gather precise numbers, there's memory allocation profiling + pahole :)