Page MenuHomeFreeBSD

Add support for blocking waits to refcounts.
ClosedPublic

Authored by jeff on Aug 13 2019, 8:02 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 20 2024, 2:09 AM
Unknown Object (File)
Dec 23 2023, 7:48 AM
Unknown Object (File)
Nov 22 2023, 8:47 PM
Unknown Object (File)
Nov 13 2023, 11:16 AM
Unknown Object (File)
Nov 9 2023, 5:14 AM
Unknown Object (File)
Nov 7 2023, 10:57 AM
Unknown Object (File)
Nov 2 2023, 7:21 AM
Unknown Object (File)
Oct 20 2023, 5:38 AM
Subscribers

Details

Summary

This adds a wait bit to refcount with an atomic sleep. Consumers that use this facility need to be aware that specific count values can not be examined directly.

When a counter is saturated this will block forever.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 25875
Build 24444: arc lint + arc unit

Event Timeline

jeff added reviewers: jhb, markj.

I'm not really crazy about this to be honest. refcount_release() gets inlined hundreds if not thousands of times into various functions. Now all of those callers are polluted with extra dead branch to call wakeup(). The fences in refcount_release() also don't make sense when refcount_wait() is used since a refcount of 0 doesn't mean that the protected object is unreachable, the way you'd normally expect a refcount to work. I would argue that this use-case would be better served by a new KPI or something open-coded.

That said, I don't see any technical issues aside from the nits I pointed out.

sys/sys/refcount.h
45

The use of bit 31 meant that we could detect saturation with a single js instruction after the acquire, but that's no longer true with this change.

88

Extra newline.

91

We should assert some bound on n, probably 2^30?

Address some of Markj's feedback. Move the last ref drop into a dedicated function to lessen text bloat.

sys/sys/refcount.h
121

On underflow, we want to call refcount_release_last() to reset the counter value. But now that won't happen since this is an unsigned comparison.

122

Style: missing parens.

sys/kern/kern_synch.c
55

This sorts before resourcevar.h.

363

Can't the cmpset fail spuriously on LL/SC platforms if the cache line is concurrently modified?

markj added inline comments.
sys/kern/kern_synch.c
363

Never mind, that only applies to fcmpset.

This revision is now accepted and ready to land.Aug 15 2019, 7:34 PM
kib added inline comments.
sys/kern/kern_synch.c
370

There is no _rel at the beginning of the function. You need to point to the refcount_releasen().