On Mon, 16 Feb 2026 07:32:53 -0800
Linus Torvalds [off-list ref] wrote:
On Mon, 16 Feb 2026 at 03:09, David Laight [off-list ref] wrote:
quoted
volatile structure members are almost free
No, gcc does absolutely horrible things with volatiles. It disables a
lot of very basic stuff.
Try doing something as simple as a "var++" on a volatile, and cry.
On x86 I just see a load, inc, store - not that surprising really.
(clang did do 'inc memory'.)
It's not as though 'inc memory' is atomic (without a lock prefix).
Also var++ will be 3 u-ops the same as the read, inc, write so the
underlying execution is much the same (ok you might save on the
address generation and the compiler doesn't have to find a register name,
but I don't remember anything modern being limited by instruction retirement).
You might save a bit of I-cache.
I've an idea that gcc converts var++ to 'var = var + 1' early on
and then might manage to convert it back later.
A good way of running out of registers,
We need to have explicit 'READ_ONCE()' etc atomic accesses, just to
make it very very clear that the compiler will generate shit code.
We do *not* hide them and make them implicit by marking data
structures volatile. I very much want those explicit
READ_ONCE/WRITE_ONCE cases.
I guess you count as the boss :-)
David
Linus