lkml.org 
[lkml]   [2013]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v2 7/4] ipc: fine grained locking for semtimedop
From
On Wed, Mar 6, 2013 at 5:15 PM, Rik van Riel <riel@redhat.com> wrote:
>
> If the call is a semop manipulating just one semaphore in
> an array with multiple semaphores, the read/write lock for
> the semaphore array is taken in shared (read) mode, and the
> individual semaphore's lock is taken.

You know, we do something like this already elsewhere, and I think we
do it slightly better. See the mm_take_all_locks() logic in mm/mmap.c.

The optimal strategy if you have many items, and the *common* case is
that you need just one lock, is actually to only take that single lock
for the common case. No top-level lock at all.

Then, for the complex (but unlikely) case, you take a *separate*
top-level lock, and then you take the lower-level locks one by one,
while testing first if you already hold them (using a separate data
structure that is protected by the top-level lock).

This way, the common case only needs that single lock that protects
just that particular data structure.

That said, judging by your numbers, your read-write lock seems to work
fine too, even though I'd worry about cacheline ping-pong (but not
contention) on the readers. So it doesn't seem optimal, but it sure as
hell seems better than what we do now ;)

Linus


\
 
 \ /
  Last update: 2013-03-07 00:21    [W:0.119 / U:0.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site