Re: Lightweight locking primitive

From: "Hubertus Franke" <frankeh(at)us(dot)ibm(dot)com>
To: Igor Kovalenko <Igor(dot)Kovalenko(at)motorola(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, rusty(at)rustcorp(dot)com(dot)au
Subject: Re: Lightweight locking primitive
Date: 2002-03-12 22:55:46
Message-ID: OF0C576C73.D0980FA9-ON85256B7A.007DE6EF@pok.ibm.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Biggest difference, FUTEX work across address spaces, pthread_mutexes don't
!

Hubertus Franke
Enterprise Linux Group (Mgr), Linux Technology Center (Member Scalability)
, OS-PIC (Chair)
email: frankeh(at)us(dot)ibm(dot)com
(w) 914-945-2003 (fax) 914-945-4425 TL: 862-2003

Igor Kovalenko <Igor(dot)Kovalenko(at)motorola(dot)com> on 03/12/2002 04:48:23 PM

To:
cc: pgsql-hackers(at)postgresql(dot)org, Hubertus Franke/Watson/IBM(at)IBMUS,
rusty(at)rustcorp(dot)com(dot)au
Subject: Re: [HACKERS] Lightweight locking primitive

Matthew Kirkwood wrote:
>
> Hi,
>
> It seems that the Linux kernel will very shortly acquire a lightweight
> userlevel locking primitive (called futexes), thanks primarily to Rusty
> and Hubertus. It looks to be very useful for the sort of locking that
> databases of various types need to do.
>
> They have a bunch of rather nice properties:

I am curious how 'futexes' are different/better than POSIX (pthread
style) mutexes?

>
> a) low overhead in the no-contention case - a single locked
> instruction on i386

should be same for pthread_mutex_lock()

> b) no kernel overhead for non-contended locks - make as
> many as you like, the kernel memory cost is only
> O(number of locks with waiters)

Well it can't have kernel overhead for non-contended locks if a
non-contended lock is one opcode, can it?

> c) are interruptible / restartable across signals

Not sure what 'restartable' means? Do you mean locking primitives would
restarted by kernel when interrupted by signals? Like kernel calls with
SA_RESTART set? How that would be possible if kernel does not even know
about non-contended locks?

> d) the name :-)
>
> They don't do:
>
> a) deadlock detection
> b) cleanup on process exit -- the kernel doesn't know who
> had the lock, so it can't help here
>
> A reader/writer version is available, though it's currently implemented
> with two futexes. Spin-for-a-while-before-sleeping versions are planned.
>

RW locks are defined by POSIX too and can be implemented by mutex +
condvar. I wonder what is wrong with those... At the same time Linux has
POSIX semaphores which can not be shared across processes, making them
quite useless. Fixing that could help postgres quite a bit more I
think...

-- igor

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Trond Eivind =?iso-8859-1?q?Glomsr=F8d?= 2002-03-12 23:30:42 Re: Zlib vulnerability heads-up.
Previous Message Doug McNaught 2002-03-12 22:18:16 Re: Lightweight locking primitive