Re: [PATCH v2 8/9] atomic,x86: Alternative atomic_*_overflow() scheme

From: Herbert Xu
Date: Thu Dec 16 2021 - 22:38:22 EST


Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> That said - it may not matter - I'm not sure a plain "dec" is even a
> valid operation on a ref in the first place. How could you ever
> validly decrement a ref without checking for it being the last entry?

There are actual spots in the network stack where we know we're
holding multiple reference counts to a given object and in those
cases an unconditional "dec" could make sense. For example, we may
have an object that we obtained from a hash lookup, giving us a
reference count, which we then try to remove from a linked list,
also containing a referencnce count to it. While still holding
the referencnce count from the hash lookup, the linked list
referencnce count could be dropped with a plain "dec".

Of course we might be better off redesigning things to eliminate
reference counts completely but such code does still exist.

Cheers,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt