> On Sep 16, 2019, at 7:50 AM, Roman Simakov <[email protected]> wrote:
> 
> Hi,
> 
> I guess it would be interesting alternative for spinlock
> (https://kernelnewbies.org/Linux_5.3)
> 1.6. Power efficient userspace waiting with the umwait x86 instructions
> 
> More description is here:
> https://lwn.net/Articles/790920/
> 

Spinlocks in userspace are a performance disaster - here are some rhoughts from 
Jim Starkey ...

Spin locks were invented at DEC for use in either the RSX-11M+ or VMS kernel 
for a very specific and narrow purpose.  Spin locks were used when the OS was 
initiating a very short device request where the expected completion time was 
less than the overhead to setup for and process a device interrupt.  They were 
used sparingly and effectively.

For virtually any other purpose, spin locks are a huge net loss for a very 
simple reason: Hogging the processor waiting for another thread or process not 
only wastes processor cycles but a quite likely to present the other process 
and thread from running and releasing whatever resource had induced the spin.

The last great performance leap on the Falcon/InnoDB race at MySQL was when 
Google replaced InnoDB's spin locks with Falcon's user mode synchronization 
locks, giving InnoDB a 20% or 30% kick under heavy load.

Long (or indeterminate) locks are best handled with user mode read/write 
synchronization objects.  Very short term locks can be avoided through 
judicious use of non-interlocked data structures managed with compare-and-swap. 
 AmorphousDB, for example, uses non-interlocked hash tables for things like 
transactions and network operation tickets; objects in these hash tables can be 
safely removed by first moving them into an object purgatory that is safely 
emptied by a cycle manager once a second (or whatever).

There is an incredible among of non-sense written about spin locks by folks who 
tend to believe that any technique used by and OS kernel must be very cool and 
very efficient.

The related idea of an instruction that can stall a processor waiting on memory 
write is every bit as flawed as spin locks even if it does reduce the amount of 
power consumed while gumming up the OS scheduler.

-- 
Jim Starkey


Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to