4 ms·
Source for those interested: https://github.com/torvalds/linux/blob/master/lib/refcount.c https://github.com/torvalds/linux/blob/master/lib/refcount.c I'm kin
by anameaname 9y ago
Source for those interested: https://github.com/torvalds/linux/blob/master/lib/refcount.c https://github.com/torvalds/linux/blob/master/lib/refcount.c
I'm kind of surprised that the authors went with compare-and-exchange for their ref count, rather than get-and-increment. Even if the counter does overflow, it's usually detectable, and reversible. This is true even in the face of concurrent updates. The benefit is that there is only one atomic operation in the fast path.
- Someone 9y ago”usually detectable” isn’t good enough. You must assume attackers will try to hit your code zillions of times until they hit the ‘unusual’ case.