Not logged in
Log in now
Create an account
Subscribe to LWN
LWN.net Weekly Edition for May 23, 2013
An "enum" for Python 3
An unexpected perf feature
LWN.net Weekly Edition for May 16, 2013
A look at the PyPy 2.0 release
Heh. I suggested introducing kref_get_not_zero() (based on atomic_inc_not_zero()) back in January, but got a lot of resistance. Better luck to the next guy.
Posted Jun 9, 2009 20:42 UTC (Tue) by neilbrown (subscriber, #359)
Thanks for that reference.
I cannot comment on the code under the microscope in that thread as I am not familiar with it at all. However your observation that kref_get_not_zero() can be safe when used under a lock that excludes the object from being freed is one that I completely agree with. It is therefore tempting to call the function kref_get_locked() to match the inode_get_locked that already exists.
However it can be valid to use atomic_inc_not_zero() when not holding a lock,
as in the example in a previous thread. In that case it is safe not because a lock is held, but because a secondary reference is held (s_count).
Either way, the complete pattern description for kref would need to spell
out how and when to use kref_get_not_zero() (or whatever it gets called).
I must say that Greg's 'ick' in the reply to your linked post surprised me.
kref_get_not_zero is (in my view) much less 'ick' than kref_set which is part of the current kref API (exercise: find all 3 places that use kref_set and replace them with calls to other parts of the api).
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds