|
|
Log in / Subscribe / Register

The seqcount latch lock type

The seqcount latch lock type

Posted Sep 17, 2020 22:23 UTC (Thu) by nix (subscriber, #2304)
Parent article: The seqcount latch lock type

FYI: I've used this technique in userspace to avoid locking. I didn't invent it, of course, I saw it in the core timekeeping code and was taken with it.

It doesn't gain you anything in the uncontended case, but one particularly nice thing from the userspace perspective is that you are guaranteed not to have any trips into the kernel at all, even when contended, so if there are enough colliding writes and concurrent reads that loads of slow-path trips into the kernel on lock contention are killing you, you can try moving from a (futex-backed) pthread mutex to one of these. It's rare, but if you know that reads and writes are often going to be colliding for a brief period (one or two retry loops) this can give a significant performance gain and latency reduction and can even reduce CPU load as well, even though it's a busywait! (A quick run round the retry loop is a *lot* faster than a transition into the kernel on a blocking futex and back out.)


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds